index.vue 8.0 KB

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