index.vue 7.1 KB

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