deviceList.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="ota-edit-module-container">
  3. <el-dialog :title="'设备详情'" :before-close="closeDialog" v-model="isShowDialog" width="1000px">
  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" width="100" show-overflow-tooltip align="center"></el-table-column>
  21. <el-table-column prop="deviceName" label="设备名称" show-overflow-tooltip></el-table-column>
  22. <el-table-column prop="deviceKey" label="设备标识" show-overflow-tooltip></el-table-column>
  23. <el-table-column prop="status" label="状态" show-overflow-tooltip align="center">
  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 align="center">
  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="时间" width="160" align="center"></el-table-column>
  49. <el-table-column label="操作" width="80" align="center">
  50. <template #default="scope">
  51. <el-button size="small" text type="primary" v-if="![2, 3].includes(scope.row.status)" @click="distribute(scope.row)">手动下发</el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <pagination
  56. v-show="tableData.total > 0"
  57. :total="tableData.total"
  58. v-model:page="tableData.param.pageNum"
  59. v-model:limit="tableData.param.pageSize"
  60. @pagination="getDetail"
  61. />
  62. </el-dialog>
  63. </div>
  64. </template>
  65. <script lang="ts">
  66. import api from '/@/api/ota'
  67. import { defineComponent, reactive, toRefs } from 'vue'
  68. import { ElMessage } from 'element-plus'
  69. interface TableDataRow {
  70. id: number
  71. name: string
  72. types: string
  73. productName: number
  74. moduleName: string
  75. checkres: string
  76. createdAt: string
  77. }
  78. interface TableDataState {
  79. ids: number[]
  80. tableData: {
  81. data: Array<TableDataRow>
  82. total: number
  83. loading: boolean
  84. param: {
  85. pageNum: number
  86. pageSize: number
  87. deviceName: string
  88. devOtaStrategy: number
  89. }
  90. }
  91. isShowDialog: boolean
  92. timeoutTimer: any
  93. }
  94. export default defineComponent({
  95. setup() {
  96. const state = reactive<TableDataState>({
  97. ids: [],
  98. tableData: {
  99. data: [],
  100. total: 0,
  101. loading: false,
  102. param: {
  103. pageNum: 1,
  104. pageSize: 20,
  105. deviceName: '',
  106. devOtaStrategy: 0,
  107. },
  108. },
  109. isShowDialog: false,
  110. timeoutTimer: null,
  111. })
  112. // 打开弹窗
  113. const openDialog = (row: any) => {
  114. state.tableData.loading = true
  115. state.tableData.param.devOtaStrategy = Number(row.id)
  116. api.device
  117. .getList(state.tableData.param)
  118. .then((res: any) => {
  119. state.tableData.data = res.Data
  120. state.tableData.total = res.Total
  121. })
  122. .finally(() => (state.tableData.loading = false))
  123. state.isShowDialog = true
  124. }
  125. // 关闭弹窗
  126. const closeDialog = () => {
  127. clearTimeout(state.timeoutTimer)
  128. state.isShowDialog = false
  129. }
  130. // 取消
  131. const onCancel = () => {
  132. closeDialog()
  133. }
  134. const getDetail = () => {
  135. state.tableData.loading = true
  136. api.device
  137. .getList(state.tableData.param)
  138. .then((res: any) => {
  139. state.tableData.data = res.Data
  140. state.tableData.total = res.Total
  141. })
  142. .finally(() => (state.tableData.loading = false))
  143. }
  144. // 手动下发
  145. const distribute = (row: any) => {
  146. const deviceKey = row.deviceKey
  147. const strategyId = row.strategyId
  148. api.batch.distribute({ deviceKey: deviceKey, strategyId: strategyId }).then(() => {
  149. ElMessage.success('操作成功')
  150. })
  151. // 定时请求列表数据
  152. timer()
  153. }
  154. // 定时请求列表
  155. const timer = () => {
  156. // 因列表更新数据不是实时更新,需设置定时后在请求列表
  157. state.timeoutTimer = setTimeout(() => {
  158. getDetail()
  159. }, 3000)
  160. }
  161. return {
  162. getDetail,
  163. openDialog,
  164. closeDialog,
  165. onCancel,
  166. distribute,
  167. ...toRefs(state),
  168. }
  169. },
  170. })
  171. </script>
  172. <style lang="scss" scoped>
  173. .width100 {
  174. width: 100%;
  175. }
  176. </style>