batch.vue 8.2 KB

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