index.vue 7.7 KB

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