index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="scanCode">
  3. <capsule :showBorder="true">
  4. <template v-slot:top>
  5. <view class="shop-top">
  6. <view class="back-icon" @click="backClick">
  7. <tui-icon name="arrowleft" :size="42" color="#FFFFFF"></tui-icon>
  8. </view>
  9. <view class="shop-name">{{ shopInfo.shopName }}</view>
  10. </view>
  11. </template>
  12. </capsule>
  13. <view class="scanning">
  14. <view class="scan-box">
  15. <view class="border-box"></view>
  16. <view class="border-box2"></view>
  17. <view class="border-box3"></view>
  18. <view class="border-box4"></view>
  19. <camera class="scan-camera" @scancode="onScancode" mode="scanCode" device-position="back" flash="auto">
  20. <cover-view class="scan-animation" :animation="animation"></cover-view>
  21. </camera>
  22. </view>
  23. <view class="scab-txt">将二维码/条码放到取景框中,即可自动扫描</view>
  24. </view>
  25. <view class="btn-list">
  26. <view class="btn" @click="goCoupons">
  27. <image src="@/static/image/code/keyboard.png" />
  28. <text>输码验劵</text>
  29. </view>
  30. <view class="btn" @click="openAlbum">
  31. <image src="@/static/image/code/photo.png" />
  32. <text>打开相册</text>
  33. </view>
  34. </view>
  35. <modal :showModal="modal" :promptList="promptList" @closeModal="closeModal" :showBtn="false"></modal>
  36. </view>
  37. </template>
  38. <script>
  39. var animation = uni.createAnimation({
  40. timingFunction: "linear",
  41. delay: 0
  42. });
  43. export default {
  44. created() {
  45. // 获取本地存储的店铺数据
  46. this.shopInfo = uni.getStorageSync('shopInfo');
  47. setTimeout(() => {
  48. this.getOrderIdFromUrl('https://test.tuanfengkeji.cn/TFShop_Uni_H5/#/pages/jump/jump?orderId=4979&type=verification&code=4979~JFHXQSZD4F')
  49. }, 8000)
  50. },
  51. onShow() {
  52. this.lineAnimation()
  53. },
  54. data() {
  55. return {
  56. // 扫描线动画
  57. animation: {},
  58. shopInfo: {},
  59. // 控制框显示
  60. modal: false,
  61. // 弹框显示的内容
  62. promptList: [],
  63. }
  64. },
  65. methods: {
  66. lineAnimation() {
  67. this.animation = animation;
  68. let that = this;
  69. let scode = true;
  70. this.timer = setInterval(
  71. function () {
  72. if (scode) {
  73. animation.translateY(260).step({
  74. duration: 1500,
  75. });
  76. scode = !scode;
  77. } else {
  78. animation.translateY(-10).step({
  79. duration: 1500,
  80. });
  81. scode = !scode;
  82. }
  83. that.animation = animation.export();
  84. }.bind(this),
  85. 1500
  86. );
  87. },
  88. // 关闭弹框
  89. // 关闭弹框
  90. closeModal() {
  91. this.modal = false
  92. },
  93. // 相机初始化完成回调函数
  94. onCameraInitDone() {
  95. // setInterval(() => {
  96. // this.$refs.camera.scanCode();
  97. // }, 1000);
  98. },
  99. /**扫码成功*/
  100. onScancode(e) {
  101. // uni.showModal({
  102. // title: '提示',
  103. // content: e,
  104. // });
  105. console.log(e.detail.result);
  106. this.getOrderIdFromUrl(e.detail.result)
  107. },
  108. // 获取订单
  109. getOrderIdFromUrl(url) {
  110. try {
  111. let march = url.match(/orderId=(\d+)/)
  112. // 传递值过去
  113. uni.navigateTo({
  114. url: '/pages_module/orderVerifica/index?orderId=' + march[1]
  115. })
  116. } catch (error) {
  117. this.modal = true
  118. this.promptList = ['此二维码/条码无效', '请扫描正常的二维码/条码']
  119. }
  120. },
  121. // 打开相册
  122. openAlbum() {
  123. uni.chooseImage({
  124. count: 1, // 最多可以选择的图片张数
  125. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  126. sourceType: ['album'], // 选择图片的来源,相册
  127. success: function (res) {
  128. // console.log(res,res.tempFiles[0].path);
  129. uni.scanCode({
  130. path: res.tempFiles[0].path,
  131. success: function (res) {
  132. console.log('二维码内容为:' + res.result)
  133. },
  134. fail: function (res) {
  135. console.log('识别二维码失败')
  136. }
  137. })
  138. }
  139. })
  140. },
  141. // 去到输入验劵
  142. goCoupons() {
  143. uni.navigateTo({
  144. url: '/pages_module/scanCoupons/index'
  145. })
  146. },
  147. backClick() {
  148. // uni.navigateBack()
  149. uni.switchTab({
  150. url: '/pages/tabbar/index/index'
  151. });
  152. }
  153. },
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. %btn {
  158. width: 55rpx;
  159. height: 13rpx;
  160. background-color: #fff;
  161. position: relative;
  162. }
  163. %btnAfter {
  164. content: '';
  165. position: absolute;
  166. width: 13rpx;
  167. height: 55rpx;
  168. background-color: #fff;
  169. }
  170. .scanCode {
  171. width: 100vw;
  172. height: 100vh;
  173. background: url("https://jufeng-shop-1317254189.cos.ap-guangzhou.myqcloud.com/1717469011005-bg.png") center;
  174. background-size: 100% 100%;
  175. position: relative;
  176. .shop-top {
  177. width: 100%;
  178. height: 100%;
  179. position: relative;
  180. z-index: 999;
  181. @include flex(center);
  182. .back-icon {
  183. position: absolute;
  184. left: 0;
  185. top: 50%;
  186. transform: translateY(-50%);
  187. }
  188. .shop-name {
  189. color: #FFFFFF;
  190. }
  191. }
  192. .scanning {
  193. width: 100%;
  194. position: absolute;
  195. top: 50%;
  196. left: 50%;
  197. transform: translate(-50%, -50%);
  198. @include flex(center, column, 30rpx);
  199. .scan-box {
  200. width: 452rpx;
  201. height: 452rpx;
  202. position: relative;
  203. .border-box {
  204. @extend %btn;
  205. position: absolute;
  206. left: -5rpx;
  207. top: -5rpx;
  208. &::after {
  209. @extend %btnAfter;
  210. left: -2rpx;
  211. top: 0;
  212. }
  213. }
  214. .border-box2 {
  215. @extend %btn;
  216. position: absolute;
  217. right: -5rpx;
  218. top: -5rpx;
  219. &::after {
  220. @extend %btnAfter;
  221. right: -2rpx;
  222. top: 0;
  223. }
  224. }
  225. .border-box3 {
  226. @extend %btn;
  227. position: absolute;
  228. right: -5rpx;
  229. bottom: -5rpx;
  230. &::after {
  231. @extend %btnAfter;
  232. right: -2rpx;
  233. bottom: 0;
  234. }
  235. }
  236. .border-box4 {
  237. @extend %btn;
  238. position: absolute;
  239. left: -5rpx;
  240. bottom: -5rpx;
  241. &::after {
  242. @extend %btnAfter;
  243. left: -2rpx;
  244. bottom: 0;
  245. }
  246. }
  247. .scan-camera {
  248. width: 100%;
  249. height: 100%;
  250. }
  251. .scan-animation {
  252. position: absolute;
  253. top: 5%;
  254. left: 0;
  255. width: 100%;
  256. height: 3rpx;
  257. background-color: $primary-color;
  258. border-radius: 50%;
  259. }
  260. }
  261. .scab-txt {
  262. font-size: 28rpx;
  263. color: #FFFFFF;
  264. }
  265. }
  266. .btn-list {
  267. position: absolute;
  268. left: 50%;
  269. bottom: 104rpx;
  270. transform: translateX(-50%);
  271. @include flex(center, null, 60rpx);
  272. .btn {
  273. width: 276rpx;
  274. height: 108rpx;
  275. background: rgba(255, 255, 255, 0.4);
  276. @include flex(center, null, 22rpx);
  277. border-radius: 24rpx;
  278. image {
  279. width: 44rpx;
  280. height: 36rpx;
  281. display: block;
  282. }
  283. text {
  284. font-size: 36rpx;
  285. color: #E6E4E5;
  286. }
  287. }
  288. }
  289. }
  290. </style>