putStorage.vue 7.3 KB

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