index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="window-box">
  3. <ly-back :showBack="false"/>
  4. <view class="search w100 h100 flex-center-center main flex-dir-column">
  5. <view class="" @click="getListHandle">测验机器</view>
  6. <br>
  7. <br>
  8. <br>
  9. <view class="flex-between-center w50">
  10. <view class="w50 flex-center-center">
  11. <view :class="[machine.scan?'btn-primary':'btn-info']" class="btn">
  12. 扫码器
  13. <uv-icon v-if="machine.scan" color="#FFF" name="checkbox-mark" size="28"/>
  14. </view>
  15. </view>
  16. <view class="w50 flex-center-center">
  17. <view :class="[machine.bmi?'btn-primary':'btn-info']" class="btn">
  18. 体重秤
  19. <uv-icon v-if="machine.bmi" color="#FFF" name="checkbox-mark" size="28"/>
  20. </view>
  21. </view>
  22. </view>
  23. <br>
  24. <br>
  25. <view class="flex-start-center">
  26. 卡号:
  27. <view class="col-checked">{{ pD.value1 || '--' }}</view>
  28. </view>
  29. <br>
  30. <view class="flex-start-center">
  31. 身高:
  32. <view class="col-checked">{{ pD.value3 || '0' }}</view>
  33. cm
  34. </view>
  35. <view class="flex-start-center">
  36. 体重:
  37. <view class="col-checked">{{ pD.value2 || '0' }}</view>
  38. kg
  39. </view>
  40. <!-- <view class="" :class="{'col-green':}"></view>-->
  41. <!-- <view class="w60 h60 bg2 flex-center-center flex-wrap flex-dir-column">-->
  42. <!-- <view>请将卡片放入感应区</view>-->
  43. <!-- <view >-->
  44. <!-- <uv-image :src="pD.imgUrl+ '/index-card.png'" width="500px" height="306px"></uv-image>-->
  45. <!-- </view>-->
  46. <!-- </view>-->
  47. <!-- <view class="btn btn-primary" @click="search">扫码</view>-->
  48. <!-- <view class="btn btn-primary" @click="next">下一页</view>-->
  49. <!-- <view class="btn btn-primary" @click="toSelect">手动选择</view>-->
  50. </view>
  51. </view>
  52. </template>
  53. <script setup>
  54. import {getCurrentInstance, inject, onActivated, onBeforeUnmount, onMounted, reactive} from "vue";
  55. import {onShow, onHide} from "@dcloudio/uni-app";
  56. import {navTo, showToast} from "@/utils/app";
  57. import {cradToStudentInfo} from "@/api/student";
  58. import storage from "@/utils/storage";
  59. import {getAllMethods, logs, sleep} from "@/utils/util";
  60. import * as ASCIIUtils from "@/uni_modules/wrs-js-modbusCRCHex/js_sdk/wrs-ASCIIUtils";
  61. import * as HexUtils from "@/uni_modules/wrs-js-modbusCRCHex/js_sdk/wrs-HexUtils";
  62. import {orderToData} from "@/utils/ble/hex";
  63. const $machine = inject('$machine')
  64. const pD = reactive({
  65. title: '学生未激活',
  66. select: 0,
  67. selectMax: 1,
  68. imgUrl: '/static',
  69. value1: '',
  70. value2: '',
  71. })
  72. const machine = reactive({
  73. scan: false,
  74. bmi: false,
  75. })
  76. const queryForm = reactive({
  77. student_id: 0,
  78. })
  79. const search = async () => {
  80. const {code, msg, data} = await cradToStudentInfo({
  81. mac: 'BBBBBBBBBBBB'
  82. })
  83. if (code === 1) {
  84. queryForm.student_id = data.student.id
  85. storage.setKey(`student-${data.student.id}`)
  86. navTo('pages/task/info', {
  87. id: queryForm.student_id,
  88. })
  89. } else {
  90. showToast(msg)
  91. }
  92. // navTo('pages/task/info')
  93. }
  94. const next = () => {
  95. navTo('pages/task/info', {
  96. id: queryForm.student_id,
  97. })
  98. }
  99. const toSelect = () => {
  100. navTo('pages/classes/select')
  101. }
  102. const getListHandle = () => {
  103. // console.log('getListHandle')
  104. $machine.getUsbList(true)
  105. }
  106. const scanWatch = (res) => {
  107. console.log('scanWatch123', res)
  108. pD.value1 = res.value
  109. }
  110. const bmiWatch = (res) => {
  111. console.log('bmiWatch123', res)
  112. pD.value2 = res.kg
  113. pD.value3 = res.cm
  114. }
  115. const notifyMachineUsb = ({id, up}) => {
  116. machine[id] = up
  117. }
  118. const setWatch = (open = false) => {
  119. if (open) {
  120. $machine.scan().setWatch(scanWatch)
  121. $machine.bmi().setWatch(bmiWatch)
  122. } else {
  123. $machine.scan().setWatch(null)
  124. $machine.bmi().setWatch(null)
  125. }
  126. }
  127. // 挂载完成之后
  128. onMounted(async (r) => {
  129. // console.log('index onMounted')
  130. uni.$on('machineUsb', notifyMachineUsb)
  131. // getListHandle()
  132. })
  133. onShow(async () => {
  134. setWatch(true)
  135. })
  136. onHide(async () => {
  137. setWatch()
  138. })
  139. // 页面卸载前
  140. onBeforeUnmount(() => {
  141. setWatch()
  142. uni.$off('machineUsb', notifyMachineUsb)
  143. })
  144. defineExpose({})
  145. // 激活页面时
  146. onActivated(async () => {
  147. })
  148. </script>
  149. <style lang="scss" scoped>
  150. .main {
  151. background-image: url('static/image/index-bg.png');
  152. width: 100%;
  153. height: 100%;
  154. background-position: center center;
  155. background-size: 100%;
  156. background-repeat: no-repeat;
  157. }
  158. .bg2 {
  159. background-image: url('static/image/index-bg2.png');
  160. width: 80%;
  161. height: 80%;
  162. background-position: center center;
  163. background-size: 100%;
  164. background-repeat: no-repeat;
  165. }
  166. .info-item {
  167. display: flex;
  168. align-items: center;
  169. margin-bottom: 30rpx;
  170. &-label {
  171. margin-right: 50rpx;
  172. }
  173. }
  174. </style>