index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view :class="['page']">
  3. <view class="device-header">
  4. <view class="device-header_name">
  5. <text>洗车机编号:{{ state.device.deviceName }}</text>
  6. </view>
  7. <view class="device-header_fun">
  8. <uv-tags plain size="mini" type="info" :text="f" v-for="(f,i) in state.device.functions.split('\\|')" :key="i"></uv-tags>
  9. </view>
  10. <view class="device-header_fun">
  11. <uv-tags plain size="mini" type="primary" :text="state.device.state"></uv-tags>
  12. </view>
  13. </view>
  14. <view class="device-body">
  15. <view class="device-body_ops" @click="debounceStartStopDevice">
  16. <text v-if="state.device.state==='idle'">启动设备</text>
  17. <text v-else>停止设备</text>
  18. </view>
  19. <!-- <view class="device-body_ops-time">{{ state.time }}</view>-->
  20. </view>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
  25. import {reactive, ref} from "vue";
  26. import {debounce} from "@/utils/common";
  27. import {get, post} from "@/utils/https";
  28. const initState = () => ({
  29. device: {
  30. functions:[],
  31. deviceName:'',
  32. state:''
  33. },
  34. time: "00:00:00",
  35. start: new Date()
  36. })
  37. const state = reactive(initState())
  38. onHide(() => {
  39. Object.assign(state, initState());
  40. })
  41. onLoad((options:any) => {
  42. console.log("device onLoad>>>>", options)
  43. let id = options?.shortId;
  44. if (!id) {
  45. let query = decodeURIComponent(options.q);
  46. let scanTime = options.scancode_time;
  47. console.log(query,scanTime)
  48. if(query){
  49. id = query.split("#")[1]
  50. }else{
  51. return;
  52. }
  53. }
  54. state.device = getApp<any>().globalData.last.device;
  55. loadDeviceDetail(id);
  56. });
  57. const loadDeviceDetail = (id: number) => {
  58. get(`/wash-device/queryDevice/${id}`).then((res: any) => {
  59. state.device = res;
  60. }).catch(e => {
  61. console.error(e)
  62. })
  63. // countTime();
  64. }
  65. const handleNavigateBack = () => {
  66. uni.navigateBack();
  67. }
  68. const debounceStartStopDevice = debounce(()=>{
  69. handleClickDevice();
  70. },600)
  71. const handleClickDevice = () => {
  72. if(state.device?.state==='idle'){
  73. uni.showLoading({
  74. title: "启动中",
  75. mask: true,
  76. });
  77. post(`/wash-device/startDevice/${state.device.shortId}`).then((res:any)=>{
  78. uni.hideLoading();
  79. uni.showToast({
  80. title:'设备启动成功'
  81. })
  82. })
  83. }else{
  84. uni.showLoading({
  85. title: "停止中",
  86. mask: true,
  87. });
  88. post(`/wash-device/stopDevice/${state.device.shortId}`).then((res:any)=>{
  89. uni.hideLoading()
  90. })
  91. }
  92. }
  93. const countTime = () => {
  94. setInterval(() => {
  95. let delta = new Date().getTime() - state.start.getTime();
  96. delta = delta / 1000;
  97. let hour = (delta / 3600).toFixed(0);
  98. let min = ((delta % 3600) / 60).toFixed(0);
  99. let second = ((delta % 3600) % 60).toFixed(0);
  100. state.time = [
  101. Number(hour) > 9 ? hour : `0${hour}`,
  102. Number(min) > 9 ? min : `0${min}`,
  103. Number(second) > 9 ? second : `0${second}`
  104. ].join(":")
  105. }, 1000)
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .page {
  110. height: 100vh;
  111. width: 100%;
  112. background-color: #f6f7fa;
  113. }
  114. .device-header {
  115. padding: 20rpx;
  116. display: flex;
  117. flex-direction: column;
  118. justify-content: center;
  119. align-items: center;
  120. &_name {
  121. font-weight: 500;
  122. margin: 15rpx 0;
  123. }
  124. &_fun {
  125. font-size: 13px;
  126. color: #7a7a7a;
  127. margin: 10rpx 0;
  128. }
  129. }
  130. .device-body {
  131. flex-grow: 1;
  132. margin-top: 60rpx;
  133. display: flex;
  134. flex-direction: column;
  135. justify-content: center;
  136. align-items: center;
  137. align-content: center;
  138. &_ops {
  139. display: flex;
  140. justify-content: center;
  141. align-items: center;
  142. align-content: center;
  143. width: 300rpx;
  144. height: 300rpx;
  145. border-radius: 50%;
  146. background-color: $uni-color-primary;
  147. color: white;
  148. font-size: 28px;
  149. font-weight: 500;
  150. }
  151. }
  152. </style>