putStorage.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class="container">
  3. <scroll-view scroll-y="true" class="scroll-list"
  4. >
  5. <uni-list>
  6. <uni-list-item border v-for="(item, index) in listArr">
  7. <template v-slot:header>
  8. <view class="slot-box">
  9. <image class="slot-image" src="/static/girder.png" mode="widthFix" style="width: 50px; height: 50px;"></image>
  10. </view>
  11. </template>
  12. <template v-slot:body>
  13. <view class="ml-6" style="font-size: 14px;">
  14. <view class="name">
  15. {{item}}
  16. </view>
  17. <view>
  18. {{item}}
  19. </view>
  20. <view>
  21. {{item}}
  22. </view>
  23. </view>
  24. </template>
  25. <template v-slot:footer>
  26. <uni-icons type="close" color="#999" size="20" style="position: absolute; right: 20px;" @click="clearItem(item,index)"></uni-icons>
  27. </template>
  28. </uni-list-item>
  29. </uni-list>
  30. </scroll-view>
  31. <view class="button-container" v-if="type==1">
  32. <button class="btn" type="default" @click='startScan' v-if="isShowStartBtn" :loading="scanLoad">开始扫描</button>
  33. <button class="btn" type="default" @click='stopScan' v-if="!isShowStartBtn">停止扫描</button>
  34. <button class="btn" type="default" @click="toStorageClick">一键入库</button>
  35. </view>
  36. <view class="button-container" v-if="type==2">
  37. <button class="btn" type="default" @click='startScan' v-if="isShowStartBtn" :loading="scanLoad">开始扫描</button>
  38. <button class="btn" type="default" @click='stopScan' v-if="!isShowStartBtn">停止扫描</button>
  39. <button class="btn" type="default" @click="toReport">一键生成报告</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script setup>
  44. import {
  45. onMounted,
  46. ref,
  47. watch
  48. } from "vue";
  49. import {onLoad, onReady, onUnload} from '@dcloudio/uni-app'
  50. import {getArrValue} from "js-fast-way";
  51. // 获取 module
  52. const rfidModule = uni.requireNativePlugin("DeviceModule_RFID");
  53. //渲染完成
  54. onReady(() => {
  55. // #ifdef APP-PLUS
  56. rfidModuleInit()
  57. // #endif
  58. })
  59. onLoad((options)=>{
  60. type.value=options.type
  61. if(options.type==1){
  62. title.value='样品入库'
  63. }else{
  64. title.value='样品检测'
  65. }
  66. uni.setNavigationBarTitle({
  67. title:title.value
  68. })
  69. })
  70. const title=ref('')
  71. const type=ref('1')
  72. // //按键操作
  73. const isRfidInit = ref(true)
  74. const rfidModuleInit = () => {
  75. isRfidInit.value = true
  76. uni.showLoading({
  77. title: 'RFID模块加载中...',
  78. mask: true,
  79. });
  80. /**
  81. 手机按键监听事件,可在此编写一些逻辑,如使用按键触发扫描,更多详细信息请查阅uni官方文档
  82. 需要注意:退出界面必须移除监听,否则再进入页面重复注册监听会出现多次触发、回调失效的问题
  83. */
  84. plus.key.addEventListener('keydown', keyListener);
  85. //初始化
  86. setTimeout(() => {
  87. // 使用模块前必须先初始化RDIF模块
  88. let { code } = rfidModule.init();
  89. if (code === 0) {
  90. uni.hideLoading();
  91. } else if (code === -1) {
  92. uni.hideLoading();
  93. uni.showToast({
  94. title: 'RFID模块加载失败',
  95. icon: 'error',
  96. duration: 3000
  97. })
  98. } else {
  99. uni.hideLoading();
  100. }
  101. isRfidInit.value = false
  102. }, 400);
  103. }
  104. //按键操作
  105. const keyListener = ({keyCode}) => {
  106. if (keyCode === 293 || keyCode === 312) {
  107. if (isScan.value) {
  108. stopScan()
  109. } else {
  110. startScan()
  111. }
  112. }
  113. }
  114. //开始扫描
  115. const isScan = ref(false)
  116. const startScan = () => {
  117. isShowStartBtn.value=false
  118. if (isRfidInit.value) return
  119. isScan.value = true
  120. rfidModule.startScan((res) => {
  121. if (res.code === 0) {
  122. uni.showToast({
  123. icon: "success",
  124. title: '开启扫描成功'
  125. })
  126. } else if (res.code === 1) {
  127. startScanData(res.data)
  128. }
  129. })
  130. }
  131. //扫描结果处理
  132. const scanDatas = ref([])
  133. const startScanData = async (data) => {
  134. const arr = getArrValue(data)
  135. let epcs = scanDatas.value
  136. for (let i = 0; i < arr.length; i++) {
  137. const epc = arr[i].epc
  138. if (epcs.indexOf(epc) === -1) {
  139. epcs.push(epc)
  140. }
  141. }
  142. scanDatas.value = epcs
  143. console.log(scanDatas.value,'scanDatas.value');
  144. listArr.value=scanDatas.value
  145. }
  146. //停止扫描
  147. const stopScan = () => {
  148. const { code } = rfidModule.stopScan()
  149. if (code === 0) {
  150. isScan.value = false
  151. uni.showToast({
  152. icon: "success",
  153. title: '关闭扫描成功'
  154. })
  155. isShowStartBtn.value=true
  156. } else {
  157. uni.showToast({
  158. icon: "error",
  159. title: res.message
  160. })
  161. }
  162. }
  163. //页面卸载
  164. onUnload(()=>{
  165. // #ifdef APP-PLUS
  166. plus.key.removeEventListener('keydown', keyListener)
  167. // 使用完毕必须释放RDIF模块
  168. rfidModule.free();
  169. // #endif
  170. })
  171. const listArr=ref([
  172. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  173. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  174. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  175. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  176. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  177. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  178. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  179. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  180. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  181. {name:' 水泥(42.5级散装)',num:'SN20015678',postion:'路基、路面、桥梁、隧道'},
  182. ])
  183. //开始扫描
  184. const isShowStartBtn=ref(true)
  185. const scanLoad=ref(false)
  186. const toStorageClick=()=>{
  187. if(!isShowStartBtn.value){
  188. uni.showToast({
  189. title: '请先停止扫描',
  190. icon: 'none',
  191. duration: 3000
  192. })
  193. }
  194. }
  195. const clearItem=(item,index)=>{
  196. }
  197. //一键入库
  198. const storageLoad=ref(false)
  199. //一键生成报告
  200. const toReport=()=>{
  201. if(!isShowStartBtn.value){
  202. uni.showToast({
  203. title: '请先停止扫描',
  204. icon: 'none',
  205. duration: 3000
  206. })
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .name{
  212. font-weight: bold;
  213. }
  214. .container {
  215. display: flex;
  216. flex-direction: column;
  217. height: 100vh; /* 使容器高度为视口高度 */
  218. }
  219. .scroll-list {
  220. flex: 1; /* 占据剩余空间 */
  221. overflow-y: auto; /* 纵向滚动 */
  222. }
  223. .button-container {
  224. display: flex;
  225. justify-content: space-around; /* 两个按钮均匀分布 */
  226. padding: 10px;
  227. background-color: #fff; /* 背景色 */
  228. box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1); /* 阴影效果 */
  229. position: fixed; /* 固定在底部 */
  230. bottom: 0; /* 靠近底部 */
  231. left: 0; /* 左对齐 */
  232. right: 0; /* 右对齐 */
  233. }
  234. .btn {
  235. flex: 1; /* 每个按钮占据相同的空间 */
  236. margin: 0 5px; /* 按钮之间的间距 */
  237. border: none;
  238. border-radius: 5px;
  239. cursor: pointer;
  240. color: black;
  241. }
  242. </style>