OTA.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="box">
  3. <view
  4. class="OTA-info"
  5. v-if="devsClientId.length > 0 && otaList.length > 0"
  6. >
  7. <view class="meauList">
  8. <view class="title">OTA信息</view>
  9. <view class="menu-item">
  10. <view class="meanLeft"> 设备序列号 </view>
  11. <view class="meanRight">
  12. <picker
  13. @change="bindPickerChange"
  14. :value="index"
  15. :range="devsClientId"
  16. >
  17. <view class="uni-input">{{
  18. devsClientId[index]
  19. }}</view>
  20. </picker>
  21. <image
  22. src="../../static/rightArrow.png"
  23. alt=""
  24. @click="showPicker"
  25. ></image>
  26. </view>
  27. </view>
  28. <view class="menu-item" bind:tap="gotoPath">
  29. <view class="meanLeft">
  30. <text>设备名称</text>
  31. </view>
  32. <view class="meanRight">
  33. {{ devs[index].devName }}
  34. </view>
  35. </view>
  36. <view class="menu-item" bind:tap="logout">
  37. <view class="meanLeft">
  38. <text>雷达型号</text>
  39. </view>
  40. <view class="meanRight">
  41. {{ devs[index].devType }}
  42. </view>
  43. </view>
  44. <view class="menu-item" bind:tap="logout">
  45. <view class="meanLeft">
  46. <text>当前版本</text>
  47. </view>
  48. <view class="meanRight">
  49. {{ devs[index].hardware }}
  50. </view>
  51. </view>
  52. </view>
  53. <view class="meauList">
  54. <view class="title">OTA版本</view>
  55. <view class="menu-item">
  56. <view class="meanLeft">OTA版本</view>
  57. <view class="meanRight">
  58. <picker
  59. @change="bindPickerChangeTwo"
  60. :value="otaIndex"
  61. :range="otaListName"
  62. >
  63. <view class="uni-input">{{ otaListName[0] }}</view>
  64. </picker>
  65. <image
  66. src="../../static/rightArrow.png"
  67. alt=""
  68. @click="showPicker"
  69. ></image>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <view
  75. class="updateOta"
  76. @click="freshOTA()"
  77. v-if="devsClientId.length > 0 && otaList.length > 0"
  78. >更新OTA</view
  79. >
  80. </view>
  81. </template>
  82. <script>
  83. export default {
  84. data() {
  85. return {
  86. ota: "",
  87. devs: [],
  88. devsClientId: [],
  89. index: 0,
  90. selectClientId: "",
  91. // ota部分
  92. otaList: [],
  93. otaListName: [],
  94. otaIndex: 0,
  95. };
  96. },
  97. methods: {
  98. queryList() {
  99. this.$http
  100. .post("wap/device/deviceList", {
  101. userId: uni.getStorageSync("userId"),
  102. keyword: "",
  103. status: "",
  104. })
  105. .then((res) => {
  106. if (res.data.code == 200) {
  107. let devs = res.data.data;
  108. for (let i = 0; i < devs.length; i++) {
  109. if (
  110. devs[i].installPosition == "Toilet" &&
  111. devs[i].stayTimes?.length > 0
  112. ) {
  113. devs[i].wcTimes = devs[i].stayTimes.length;
  114. } else {
  115. devs[i].wcTimes = 0;
  116. }
  117. const signalTime = devs[i].signal_time;
  118. const currentTime = Date.now();
  119. }
  120. this.devs = devs;
  121. this.devsClientId = this.devs.map(
  122. (ele) => ele.clientId
  123. );
  124. } else {
  125. uni.showModal({
  126. content: res.data.message,
  127. showCancel: false,
  128. });
  129. }
  130. });
  131. },
  132. freshOTA() {
  133. if (this.devs[this.index].online == 0) {
  134. uni.showModal({
  135. content: "设备离线,无法升级",
  136. complete: (res) => {
  137. if (res.confirm) {
  138. } else {
  139. }
  140. },
  141. });
  142. return;
  143. }
  144. let clientIds = [];
  145. clientIds.push(this.devs[this.index].clientId);
  146. let ossUrl = this.otaList[this.otaIndex].ossUrl;
  147. this.$http
  148. .post(
  149. "pub/OTA/update",
  150. { clientIds: clientIds, ossUrl: ossUrl },
  151. {
  152. header: {
  153. "Content-Type": "application/json;charset=UTF-8",
  154. },
  155. }
  156. )
  157. .then((res) => {
  158. if (res.data.code == 200) {
  159. uni.showToast({
  160. title: "OTA升级成功",
  161. icon: "success",
  162. duration: 1500,
  163. });
  164. } else {
  165. uni.showToast({
  166. title: res.data.message,
  167. icon: "none",
  168. duration: 1500,
  169. });
  170. }
  171. });
  172. },
  173. bindPickerChange(e) {
  174. this.index = e.detail.value;
  175. },
  176. // OTA部分
  177. bindPickerChangeTwo(e) {
  178. this.otaIndex = e.detail.value;
  179. },
  180. queryOtaList() {
  181. this.$http.get("pub/OTA/query", {}).then((res) => {
  182. this.otaList = res.data.data;
  183. this.otaListName = this.otaList.map((ele) => ele.fileName);
  184. });
  185. },
  186. },
  187. onLoad() {},
  188. onShow() {
  189. this.queryList();
  190. this.queryOtaList();
  191. },
  192. };
  193. </script>
  194. <style lang="less" scoped>
  195. .box {
  196. padding: 10rpx 18rpx;
  197. width: 100vw;
  198. height: 100vh;
  199. background: linear-gradient(180deg, #faede2 0%, #f4f4f4 100%);
  200. box-sizing: border-box;
  201. .meauList {
  202. .title {
  203. padding-top: 20rpx;
  204. margin-left: 25rpx;
  205. font-weight: 500;
  206. color: #784c41;
  207. font-size: 32rpx;
  208. }
  209. width: 710rpx;
  210. margin: 18rpx auto 0 auto;
  211. background: #fff;
  212. border-radius: 37rpx;
  213. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.03);
  214. padding: 0;
  215. box-sizing: border-box;
  216. .menu-item {
  217. display: flex;
  218. align-items: center;
  219. justify-content: space-between;
  220. margin: 0 32rpx;
  221. padding: 32rpx 0;
  222. border-bottom: 1rpx solid #f0f0f0;
  223. &:last-child {
  224. border-bottom: none;
  225. }
  226. .meanLeft {
  227. display: flex;
  228. align-items: center;
  229. justify-content: center;
  230. image {
  231. width: 38rpx;
  232. height: 38rpx;
  233. }
  234. text {
  235. margin-left: 10rpx;
  236. color: #111111;
  237. font-size: 32rpx;
  238. }
  239. }
  240. .meanRight {
  241. display: flex;
  242. align-items: center;
  243. }
  244. .meanRight image {
  245. margin-left: 4rpx;
  246. width: 16rpx;
  247. height: 26rpx;
  248. }
  249. }
  250. }
  251. .updateOta {
  252. width: 710rpx;
  253. margin: 48rpx auto 0 auto;
  254. height: 88rpx;
  255. background: #fff;
  256. color: #b48a7c;
  257. font-size: 32rpx;
  258. border-radius: 30rpx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.03);
  263. }
  264. }
  265. </style>