deviceList.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div class="ota-edit-module-container">
  3. <el-dialog :title="'设备详情'" :before-close="closeDialog" v-model="isShowDialog" width="769px">
  4. <div class="search">
  5. <el-form inline ref="queryRef">
  6. <el-form-item label="设备名称:" prop="name">
  7. <el-input v-model="tableData.param.deviceName" placeholder="请输入设备名称" clearable style="width: 240px" @submit.prevent />
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" class="ml10" @click="getDetail">
  11. <el-icon>
  12. <ele-Search />
  13. </el-icon>
  14. 查询
  15. </el-button>
  16. </el-form-item>
  17. </el-form>
  18. </div>
  19. <el-table :data="tableData.data" style="width: 100%" row-key="id" v-loading="tableData.loading">
  20. <el-table-column prop="id" label="ID" show-overflow-tooltip></el-table-column>
  21. <el-table-column prop="deviceName" label="设备名称" show-overflow-tooltip></el-table-column>
  22. <el-table-column prop="deviceKey" label="设备标识"></el-table-column>
  23. <el-table-column prop="status" label="状态" show-overflow-tooltip>
  24. <template #default="scope">
  25. <el-tag size="small" v-if="scope.row.status == 0">待推送</el-tag>
  26. <el-tag size="small" v-if="scope.row.status == 1">已推送</el-tag>
  27. <el-tag size="small" v-if="scope.row.status == 2">升级中</el-tag>
  28. <el-tag size="small" v-if="scope.row.status == 3">升级成功</el-tag>
  29. <el-tag size="small" v-if="scope.row.status == 4">升级失败</el-tag>
  30. <el-tag size="small" v-if="scope.row.status == 5">已取消</el-tag>
  31. </template>
  32. </el-table-column>
  33. <el-table-column prop="step" label="升级进度" show-overflow-tooltip>
  34. <template #default="scope">
  35. <el-tag size="small" type="success" v-if="scope.row.step > 0">{{ scope.row.step }}%</el-tag>
  36. <el-tag size="small" v-else>{{ scope.row.step }}</el-tag>
  37. </template>
  38. </el-table-column>
  39. <el-table-column prop="fail" label="失败原因" width="100" align="center">
  40. <template #default="scope">
  41. <el-tag size="small" type="danger" v-if="scope.row.fail == -1">升级失败</el-tag>
  42. <el-tag size="small" type="danger" v-if="scope.row.fail == -2">下载失败</el-tag>
  43. <el-tag size="small" type="danger" v-if="scope.row.fail == -3">校验失败</el-tag>
  44. <el-tag size="small" type="danger" v-if="scope.row.fail == -4">烧写失败</el-tag>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="desc" label="备注信息" show-overflow-tooltip></el-table-column>
  48. <el-table-column prop="createdAt" label="时间" min-width="100" align="center"></el-table-column>
  49. <el-table-column label="操作" width="200" align="center">
  50. <template #default="scope">
  51. <el-button size="small" text type="primary" @click="distribute(scope.row)">手动下发</el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="getDetail" />
  56. </el-dialog>
  57. </div>
  58. </template>
  59. <script lang="ts">
  60. import api from '/@/api/ota';
  61. import {defineComponent, reactive, toRefs} from 'vue';
  62. import {ElMessage} from "element-plus";
  63. interface TableDataRow {
  64. id: number;
  65. name: string;
  66. types: string;
  67. productName: number;
  68. moduleName: string;
  69. checkres: string;
  70. createdAt: string;
  71. }
  72. interface TableDataState {
  73. ids: number[];
  74. tableData: {
  75. data: Array<TableDataRow>;
  76. total: number;
  77. loading: boolean;
  78. param: {
  79. pageNum: number;
  80. pageSize: number;
  81. deviceName: string;
  82. devOtaStrategy: number;
  83. };
  84. };
  85. isShowDialog: boolean;
  86. timeoutTimer: any;
  87. }
  88. export default defineComponent({
  89. setup() {
  90. const state = reactive<TableDataState>({
  91. ids: [],
  92. tableData: {
  93. data: [],
  94. total: 0,
  95. loading: false,
  96. param: {
  97. pageNum: 1,
  98. pageSize: 20,
  99. deviceName: '',
  100. devOtaStrategy: 0,
  101. },
  102. },
  103. isShowDialog: false,
  104. timeoutTimer: null,
  105. });
  106. // 打开弹窗
  107. const openDialog = (row: any) => {
  108. state.tableData.loading = true;
  109. state.tableData.param.devOtaStrategy = Number(row.id);
  110. api.device.getList(state.tableData.param).then((res: any) => {
  111. state.tableData.data = res.Data;
  112. state.tableData.total = res.Total;
  113. }).finally(() => (state.tableData.loading = false));
  114. state.isShowDialog = true;
  115. };
  116. // 关闭弹窗
  117. const closeDialog = () => {
  118. clearTimeout(state.timeoutTimer);
  119. state.isShowDialog = false;
  120. };
  121. // 取消
  122. const onCancel = () => {
  123. closeDialog();
  124. };
  125. const getDetail = () => {
  126. state.tableData.loading = true;
  127. api.device.getList(state.tableData.param).then((res: any) => {
  128. state.tableData.data = res.Data;
  129. state.tableData.total = res.Total;
  130. }).finally(() => (state.tableData.loading = false));
  131. };
  132. // 手动下发
  133. const distribute = (row: any) => {
  134. const deviceKey = row.deviceKey;
  135. const strategyId = row.strategyId;
  136. api.batch.distribute({deviceKey: deviceKey, strategyId: strategyId}).then(() => {
  137. ElMessage.success('操作成功');
  138. });
  139. // 定时请求列表数据
  140. timer();
  141. }
  142. // 定时请求列表
  143. const timer = () => {
  144. // 因列表更新数据不是实时更新,需设置定时后在请求列表
  145. state.timeoutTimer = setTimeout(() => {
  146. getDetail();
  147. }, 3000);
  148. }
  149. return {
  150. getDetail,
  151. openDialog,
  152. closeDialog,
  153. onCancel,
  154. distribute,
  155. ...toRefs(state),
  156. };
  157. },
  158. });
  159. </script>
  160. <style lang="scss" scoped>
  161. .width100 {
  162. width: 100%;
  163. }
  164. </style>