index.vue 8.6 KB

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