index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. time: "00:00:00",
  31. start: new Date()
  32. })
  33. const state = reactive(initState())
  34. onHide(() => {
  35. Object.assign(state, initState());
  36. })
  37. onLoad((options:any) => {
  38. console.log("device onLoad>>>>", options)
  39. let id = options?.shortId;
  40. if (!id) {
  41. let query = decodeURIComponent(options);
  42. let scanTime = options.scancode_time;
  43. if(query){
  44. id = query?.shortId||query?.id||query
  45. }else{
  46. return;
  47. }
  48. }
  49. state.device = getApp<any>().globalData.last.device;
  50. console.log(state.device)
  51. loadDeviceDetail(id);
  52. });
  53. const loadDeviceDetail = (id: number) => {
  54. get(`/wash-device/queryDevice/${id}`).then((res: any) => {
  55. state.device = res;
  56. }).catch(e => {
  57. console.error(e)
  58. })
  59. countTime();
  60. }
  61. const handleNavigateBack = () => {
  62. uni.navigateBack();
  63. }
  64. const debounceStartStopDevice = debounce(()=>{
  65. handleClickDevice();
  66. },600)
  67. const handleClickDevice = () => {
  68. if(state.device?.state==='idle'){
  69. uni.showLoading({
  70. title: "启动中",
  71. mask: true,
  72. });
  73. post(`/wash-device/startDevice/${state.device.shortId}`).then((res:any)=>{
  74. uni.hideLoading()
  75. })
  76. }else{
  77. uni.showLoading({
  78. title: "停止中",
  79. mask: true,
  80. });
  81. post(`/wash-device/stopDevice/${state.device.shortId}`).then((res:any)=>{
  82. uni.hideLoading()
  83. })
  84. }
  85. }
  86. const countTime = () => {
  87. setInterval(() => {
  88. let delta = new Date().getTime() - state.start.getTime();
  89. delta = delta / 1000;
  90. let hour = (delta / 3600).toFixed(0);
  91. let min = ((delta % 3600) / 60).toFixed(0);
  92. let second = ((delta % 3600) % 60).toFixed(0);
  93. state.time = [
  94. Number(hour) > 9 ? hour : `0${hour}`,
  95. Number(min) > 9 ? min : `0${min}`,
  96. Number(second) > 9 ? second : `0${second}`
  97. ].join(":")
  98. }, 1000)
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .page {
  103. height: 100vh;
  104. width: 100%;
  105. background-color: #f6f7fa;
  106. }
  107. .device-header {
  108. padding: 20rpx;
  109. display: flex;
  110. flex-direction: column;
  111. justify-content: center;
  112. align-items: center;
  113. &_name {
  114. font-weight: 500;
  115. margin: 15rpx 0;
  116. }
  117. &_fun {
  118. font-size: 13px;
  119. color: #7a7a7a;
  120. margin: 10rpx 0;
  121. }
  122. }
  123. .device-body {
  124. flex-grow: 1;
  125. margin-top: 60rpx;
  126. display: flex;
  127. flex-direction: column;
  128. justify-content: center;
  129. align-items: center;
  130. align-content: center;
  131. &_ops {
  132. display: flex;
  133. justify-content: center;
  134. align-items: center;
  135. align-content: center;
  136. width: 240rpx;
  137. height: 240rpx;
  138. border-radius: 50%;
  139. background-color: $uni-color-primary;
  140. color: white;
  141. font-size: 28px;
  142. font-weight: 500;
  143. }
  144. }
  145. </style>