index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!-- 扫一扫 -->
  2. <template>
  3. <view class="scan-view">
  4. <view class="status_bar">
  5. <!-- 这里是状态栏 -->
  6. </view>
  7. <!-- <u-navbar :title="userInfo.channelname " :background="'#000'" :title-color="'#fff'" :border-bottom="false"></u-navbar> -->
  8. <!-- 自定义导航栏 -->
  9. <view class="nav-bar">
  10. <view class="left" @click="onClickBack">
  11. <text class="fwhfont icon-icon-chevron-left" style="font-size: 50rpx;"></text>
  12. </view>
  13. <view class="title">
  14. <text class="title-text">{{ userInfo.channelname }}</text>
  15. </view>
  16. </view>
  17. <u-toast ref="uToast" />
  18. <view class="scan-border">
  19. <view
  20. style="width: 500rpx;height: 600rpx;border: 1rpx solid #ccc;margin-bottom: 120rpx;position: relative;">
  21. <view class="Bordertop">
  22. <view style="width: 44rpx;height: 10rpx;background-color: #FBCC04;"></view>
  23. <view style="width: 44rpx;height: 10rpx;background-color: #FBCC04;"></view>
  24. </view>
  25. <view class="Borderright">
  26. <view style="width: 10rpx;height: 44rpx;background-color: #FBCC04;"></view>
  27. <view style="width:10rpx;height: 44rpx;background-color: #FBCC04;position: absolute;bottom: 0rpx;">
  28. </view>
  29. </view>
  30. <view class="Borderbottom">
  31. <view style="width: 44rpx;height: 10rpx;background-color: #FBCC04;"></view>
  32. <view style="width: 44rpx;height: 10rpx;background-color: #FBCC04;"></view>
  33. </view>
  34. <view class="Borderleft">
  35. <view style="width: 10rpx;height: 44rpx;background-color: #FBCC04;"></view>
  36. <view
  37. style="width: 10rpx;height: 44rpx;background-color: #FBCC04;position: absolute;bottom: 0rpx;">
  38. </view>
  39. </view>
  40. <!-- bindscancode="onScancode" @initdone="onCameraInitDone" -->
  41. <camera class="scan-camera" @scancode="onScancode" @error="onError" mode="scanCode"
  42. device-position="back" flash="auto">
  43. <cover-view class="scan-animation" :animation="animation"></cover-view>
  44. </camera>
  45. </view>
  46. <view class="scanText">将二维码/条码放到取景框内,即可自动扫描</view>
  47. <view class="footerButton">
  48. <view class="btns">
  49. <text class="fwhfont icon-jianpan" style="padding-right: 20rpx;"></text>
  50. <text>输码</text>
  51. </view>
  52. <view class="btns">
  53. <text class="fwhfont icon-icon-list" style="padding-right: 20rpx;"></text>
  54. <text>记录</text>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. var animation = uni.createAnimation({
  62. timingFunction: "linear",
  63. delay: 0
  64. });
  65. export default {
  66. data() {
  67. return {
  68. animation: {},
  69. };
  70. },
  71. onShow() {
  72. this.lineAnimation()
  73. },
  74. methods: {
  75. /**扫码线条动画*/
  76. lineAnimation() {
  77. this.animation = animation;
  78. let that = this;
  79. let scode = true;
  80. this.timer = setInterval(
  81. function () {
  82. if (scode) {
  83. animation.translateY(260).step({
  84. duration: 1500,
  85. });
  86. scode = !scode;
  87. } else {
  88. animation.translateY(-10).step({
  89. duration: 1500,
  90. });
  91. scode = !scode;
  92. }
  93. that.animation = animation.export();
  94. }.bind(this),
  95. 1500
  96. );
  97. },
  98. // 相机初始化完成回调函数
  99. onCameraInitDone() {
  100. // setInterval(() => {
  101. // this.$refs.camera.scanCode();
  102. // }, 1000);
  103. },
  104. onError() {
  105. this.$toast('扫码错误')
  106. },
  107. onClickBack() {
  108. uni.navigateBack();
  109. },
  110. /**扫码成功*/
  111. onScancode(e) {
  112. uni.showModal({
  113. title: '提示',
  114. content: '这是一个模态弹窗',
  115. });
  116. console.log(e);
  117. },
  118. },
  119. onUnload() {
  120. },
  121. };
  122. </script>
  123. <style lang="scss" scoped>
  124. page {
  125. background-color: black;
  126. }
  127. .status_bar {
  128. height: var(--status-bar-height);
  129. width: 100%;
  130. }
  131. .scan-view {
  132. width: 100%;
  133. height: 100%;
  134. display: flex;
  135. flex-direction: column;
  136. position: fixed;
  137. align-items: center;
  138. justify-content: space-around;
  139. background-color: #000;
  140. }
  141. .Bordertop {
  142. display: flex;
  143. justify-content: space-between;
  144. position: absolute;
  145. z-index: 99;
  146. width: 100%;
  147. top: -2rpx;
  148. }
  149. .Borderleft {
  150. left: -2rpx;
  151. z-index: 99;
  152. position: absolute;
  153. height: 100%;
  154. }
  155. .Borderright {
  156. z-index: 99;
  157. position: absolute;
  158. right: -2rpx;
  159. height: 100%;
  160. }
  161. .Borderbottom {
  162. display: flex;
  163. z-index: 99;
  164. justify-content: space-between;
  165. position: absolute;
  166. width: 100%;
  167. bottom: -6rpx;
  168. }
  169. .scan-border {
  170. width: 100%;
  171. height: 75%;
  172. /* border: 6rpx solid #08FDFE; */
  173. display: flex;
  174. flex-direction: column;
  175. align-items: center;
  176. .scan-camera {
  177. width: 100%;
  178. height: 100%;
  179. border-radius: 6rpx;
  180. }
  181. }
  182. .scan-animation {
  183. position: absolute;
  184. top: 4%;
  185. left: 2%;
  186. width: 480rpx;
  187. height: 2rpx;
  188. background-color: #FBCC04;
  189. border-radius: 50%;
  190. }
  191. .footerButton {
  192. width: 100%;
  193. margin-top: 100rpx;
  194. display: flex;
  195. justify-content: space-around;
  196. align-items: center;
  197. .btns {
  198. color: #ebebeb;
  199. display: flex;
  200. justify-content: space-around;
  201. align-items: center;
  202. margin: 10rpx;
  203. padding: 20rpx;
  204. background-color: #333333;
  205. border-radius: 20rpx;
  206. }
  207. }
  208. .scanText {
  209. position: absolute;
  210. bottom: 32%;
  211. // left: 15%;
  212. color: #ebebeb;
  213. }
  214. /* 导航栏样式 */
  215. .nav-bar {
  216. display: flex;
  217. justify-content: space-between;
  218. align-items: center;
  219. position: fixed;
  220. top: 3%;
  221. left: 0;
  222. width: 100%;
  223. height: 110rpx;
  224. padding: 0 10px;
  225. box-sizing: border-box;
  226. z-index: 999;
  227. margin-top: 22rpx;
  228. }
  229. /* 左侧按钮样式 */
  230. .left {
  231. display: flex;
  232. justify-content: center;
  233. align-items: center;
  234. color: #000;
  235. background: #fff;
  236. border-radius: 60rpx;
  237. }
  238. /* 标题样式 */
  239. .title {
  240. flex: 1;
  241. display: flex;
  242. align-items: center;
  243. margin-left: 26rpx;
  244. }
  245. /* 标题文字样式 */
  246. .title-text {
  247. max-width: 200px;
  248. overflow: hidden;
  249. text-overflow: ellipsis;
  250. white-space: nowrap;
  251. color: #FFFFFF;
  252. font-size: 36rpx;
  253. }
  254. </style>