batch.vue 7.7 KB

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