index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div class="page">
  3. <el-card shadow="never">
  4. <el-form :model="tableData.param" ref="queryRef" inline>
  5. <el-form-item label="升级包名称" prop="keyWord">
  6. <el-input
  7. v-model="tableData.param.keyWord"
  8. placeholder="请输入升级包名称"
  9. clearable
  10. style="width: 240px"
  11. @keyup.enter.native="getList(1)"
  12. />
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" class="ml10" @click="getList(1)">
  16. <el-icon>
  17. <ele-Search />
  18. </el-icon>
  19. 查询
  20. </el-button>
  21. <el-button @click="resetQuery">
  22. <el-icon>
  23. <ele-Refresh />
  24. </el-icon>
  25. 重置
  26. </el-button>
  27. <el-button type="primary" v-auth="'add'" @click="onOpenAdd()">
  28. <el-icon>
  29. <ele-FolderAdd />
  30. </el-icon>
  31. 添加升级包
  32. </el-button>
  33. </el-form-item>
  34. </el-form>
  35. <el-table :data="tableData.data" style="width: 100%" v-loading="tableData.loading">
  36. <el-table-column label="ID" v-col="'id'" align="center" prop="id" width="100" />
  37. <el-table-column label="升级包名称" v-col="'name'" prop="name" min-width="120" show-overflow-tooltip />
  38. <el-table-column prop="types" label="类型" show-overflow-tooltip v-col="'types'">
  39. <template #default="scope">
  40. <el-tag size="small" v-if="scope.row.types == 1">整包</el-tag>
  41. <el-tag type="info" size="small" v-if="scope.row.types == 2">差分</el-tag>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="所属产品" v-col="'productName'" min-width="120" align="center" show-overflow-tooltip>
  45. <template #default="scope">
  46. <router-link :to="'/iotmanager/device/product/detail/' + scope.row.productKey" class="link-type">
  47. <span>{{ scope.row.productName }}</span>
  48. </router-link>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="模块名称" v-col="'moduleName'" align="center" show-overflow-tooltip>
  52. <template #default="scope">
  53. <router-link :to="'/iotmanager/operation/ota/module'" class="link-type">
  54. <span>{{ scope.row.moduleName }}</span>
  55. </router-link>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="需要验证" prop="check" v-col="'check'" width="120" align="center">
  59. <template #default="scope">
  60. <!-- 1需要,2不需要 -->
  61. <el-tag size="small" v-if="scope.row.check === 1">需要</el-tag>
  62. <el-tag type="danger" size="small" v-if="scope.row.check === 2">不需要</el-tag>
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="状态" prop="checkres" v-col="'checkres'" width="120" align="center">
  66. <template #default="scope">
  67. <!-- 升级包验证 0未验证,1验证中 2已验证 -->
  68. <el-tag size="small" v-if="scope.row.checkres === 1">验证中</el-tag>
  69. <el-tag type="success" size="small" v-if="scope.row.checkres === 2">已验证</el-tag>
  70. <el-tag type="danger" size="small" v-if="scope.row.checkres === 0">未验证</el-tag>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="版本号" prop="version" align="center" width="160" />
  74. <el-table-column label="创建时间" prop="createdAt" align="center" width="160" />
  75. <el-table-column label="操作" width="150" v-col="'handle'" align="center" fixed="right">
  76. <template #default="scope">
  77. <el-button size="small" text type="primary" v-if="!scope.row.folderName" @click="toDetail(scope.row.id)">查看</el-button>
  78. <el-button size="small" text type="warning" v-auth="'edit'" @click="onOpenEdit(scope.row)">编辑</el-button>
  79. <el-button size="small" text type="info" v-auth="'del'" @click="onRowDel(scope.row)">删除</el-button>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <pagination
  84. v-show="tableData.total > 0"
  85. :total="tableData.total"
  86. v-model:page="tableData.param.pageNum"
  87. v-model:limit="tableData.param.pageSize"
  88. @pagination="getList"
  89. />
  90. <EditConfig ref="editRef" @getList="getList(1)" />
  91. <CheckConfig ref="checkRef" @getList="getList(1)" />
  92. </el-card>
  93. </div>
  94. </template>
  95. <script lang="ts">
  96. import api from '/@/api/ota'
  97. import { toRefs, reactive, onMounted, ref, defineComponent, getCurrentInstance } from 'vue'
  98. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus'
  99. import EditConfig from '/@/views/iot/ota-update/update/component/edit.vue'
  100. import CheckConfig from '/@/views/iot/ota-update/update/component/check.vue'
  101. import { useRouter } from 'vue-router'
  102. // 定义接口来定义对象的类型
  103. interface TableDataRow {
  104. id: number
  105. name: string
  106. types: string
  107. productName: number
  108. moduleName: string
  109. checkres: string
  110. createdAt: string
  111. }
  112. interface TableDataState {
  113. ids: number[]
  114. tableData: {
  115. data: Array<TableDataRow>
  116. total: number
  117. loading: boolean
  118. param: {
  119. pageNum: number
  120. pageSize: number
  121. keyWord: string
  122. dateRange: string[]
  123. }
  124. }
  125. }
  126. export default defineComponent({
  127. name: 'apiV1OtaUpdateDataList',
  128. components: { EditConfig, CheckConfig },
  129. setup() {
  130. const router = useRouter()
  131. const editRef = ref()
  132. const checkRef = ref()
  133. const detailRef = ref()
  134. const queryRef = ref()
  135. const tabDataList = ref([{ dictLabel: '全部', dictValue: '' }])
  136. const state = reactive<TableDataState>({
  137. ids: [],
  138. tableData: {
  139. data: [],
  140. total: 0,
  141. loading: false,
  142. param: {
  143. dateRange: [],
  144. pageNum: 1,
  145. pageSize: 20,
  146. keyWord: '',
  147. },
  148. },
  149. })
  150. // 页面加载时
  151. onMounted(() => {
  152. initTableData()
  153. })
  154. // 初始化表格数据
  155. const initTableData = () => {
  156. manageList()
  157. }
  158. const getList = (pageNum?: number) => {
  159. typeof pageNum === 'number' && (state.tableData.param.pageNum = pageNum)
  160. state.tableData.loading = true
  161. api.manage
  162. .getList(state.tableData.param)
  163. .then((res: any) => {
  164. state.tableData.data = res.firmware
  165. state.tableData.total = res.Total
  166. })
  167. .finally(() => (state.tableData.loading = false))
  168. }
  169. // 打开新增弹窗
  170. const onOpenAdd = () => {
  171. editRef.value.openDialog()
  172. }
  173. // 打开修改弹窗
  174. const onOpenEdit = (row: TableDataRow) => {
  175. editRef.value.openDialog(row)
  176. }
  177. // 打开详情弹窗
  178. // const opOpenDetail = (row: TableDataRow) => {
  179. // };
  180. const toDetail = (id: number) => {
  181. router.push(`/iotmanager/operation/ota/update/detail/${id}`)
  182. }
  183. // 删除模块
  184. const onRowDel = (row?: TableDataRow) => {
  185. let msg = '你确定要删除所选数据?'
  186. let ids: number[] = []
  187. if (row) {
  188. msg = `此操作将永久删除:“${row.name}”,是否继续?`
  189. ids = [row.id]
  190. } else {
  191. ids = state.ids
  192. }
  193. if (ids.length === 0) {
  194. ElMessage.error('请选择要删除的数据。')
  195. return
  196. }
  197. ElMessageBox.confirm(msg, '提示', {
  198. confirmButtonText: '确认',
  199. cancelButtonText: '取消',
  200. type: 'warning',
  201. })
  202. .then(() => {
  203. api.manage.del(ids).then(() => {
  204. ElMessage.success('删除成功')
  205. getList()
  206. })
  207. })
  208. .catch(() => {})
  209. }
  210. /** 重置按钮操作 */
  211. const resetQuery = () => {
  212. if (!queryRef.value) return
  213. queryRef.value.resetFields()
  214. getList(1)
  215. }
  216. // 多选框选中数据
  217. const handleSelectionChange = (selection: TableDataRow[]) => {
  218. state.ids = selection.map((item) => item.id)
  219. }
  220. // 获取列表
  221. const manageList = () => {
  222. getList()
  223. }
  224. return {
  225. editRef,
  226. checkRef,
  227. queryRef,
  228. tabDataList,
  229. toDetail,
  230. onOpenAdd,
  231. onOpenEdit,
  232. onRowDel,
  233. getList,
  234. resetQuery,
  235. handleSelectionChange,
  236. ...toRefs(state),
  237. }
  238. },
  239. })
  240. </script>