batch.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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" v-auth="'add'" @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" />
  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="info" 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>
  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>
  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>
  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="创建时间" min-width="100" align="center" />
  64. <el-table-column label="操作" width="200" align="center">
  65. <template #default="scope">
  66. <!-- <router-link :to="'/iotmanager/operation/ota/update/device/' + scope.row.id" class="link-type" style="padding-right: 12px;font-size: 12px;color: #409eff;">-->
  67. <!-- <span>查看</span>-->
  68. <!-- </router-link>-->
  69. <el-button size="small" text type="primary" @click="getDeviceList(scope.row)">查看</el-button>
  70. <!-- <el-button size="small" text type="warning" v-auth="'edit'" @click="CheckUpdate(scope.row)">编辑</el-button>-->
  71. <!-- <el-button size="small" text type="danger" v-auth="'del'" @click="del(scope.row)">删除</el-button>-->
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="getList" />
  76. <CheckConfig ref="checkRef" @getList="getList(1)" />
  77. <DeviceList ref="deviceRef" />
  78. </div>
  79. </template>
  80. <script lang="ts">
  81. import api from '/@/api/ota';
  82. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  83. import { ElMessageBox, ElMessage } from 'element-plus'
  84. import CheckConfig from '/@/views/iot/ota-update/update/component/check.vue';
  85. import DeviceList from '/@/views/iot/ota-update/update/component/deviceList.vue';
  86. // 定义接口来定义对象的类型
  87. interface TableDataRow {
  88. id: number;
  89. name: string;
  90. waitVersion: string;
  91. method: number;
  92. stratege: string;
  93. push: string;
  94. createdAt: string;
  95. }
  96. interface TableDataState {
  97. ids: number[];
  98. tableData: {
  99. data: Array<TableDataRow>;
  100. total: number;
  101. loading: boolean;
  102. param: {
  103. id: number;
  104. pageNum: number;
  105. pageSize: number;
  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: 10,
  136. keyWord: '',
  137. devOtaFirmwareId: 0,
  138. },
  139. },
  140. });
  141. // 页面加载时
  142. onMounted(() => {
  143. initTableData();
  144. });
  145. // 激活操作
  146. const activation = (row: any) => {
  147. let active = 0;
  148. if (row.active === 1) active = 0;
  149. if (row.active === 0) active = 1;
  150. api.batch.stop({ id: row.id, active: active }).then((res: any) => {
  151. ElMessage.success('操作成功');
  152. batchList();
  153. });
  154. };
  155. // 初始化表格数据
  156. const initTableData = () => {
  157. batchList();
  158. };
  159. const getList = (pageNum?: number) => {
  160. typeof pageNum === 'number' && (state.tableData.param.pageNum = pageNum)
  161. state.tableData.loading = true;
  162. state.tableData.param.devOtaFirmwareId = props.detail.id;
  163. api.batch
  164. .getList(state.tableData.param)
  165. .then((res: any) => {
  166. state.tableData.data = res.Data;
  167. state.tableData.total = res.Total;
  168. })
  169. .finally(() => (state.tableData.loading = false));
  170. };
  171. // 打开新增弹窗
  172. const onOpenAdd = () => {
  173. state.tableData.param.id = props.detail.id;
  174. checkRef.value.openDialog(state.tableData.param);
  175. };
  176. // 删除模块
  177. const onRowDel = (row?: TableDataRow) => {
  178. let msg = '你确定要删除所选数据?';
  179. let ids: number[] = [];
  180. if (row) {
  181. msg = `此操作将永久删除:“${row.name}”,是否继续?`;
  182. ids = [row.id];
  183. } else {
  184. ids = state.ids;
  185. }
  186. if (ids.length === 0) {
  187. ElMessage.error('请选择要删除的数据。');
  188. return;
  189. }
  190. ElMessageBox.confirm(msg, '提示', {
  191. confirmButtonText: '确认',
  192. cancelButtonText: '取消',
  193. type: 'warning',
  194. }).then(() => {
  195. api.batch.del(ids).then(() => {
  196. ElMessage.success('删除成功');
  197. getList();
  198. });
  199. })
  200. .catch(() => { });
  201. };
  202. /** 重置按钮操作 */
  203. const resetQuery = () => {
  204. queryRef.value.resetFields();
  205. getList();
  206. };
  207. // 多选框选中数据
  208. const handleSelectionChange = (selection: TableDataRow[]) => {
  209. state.ids = selection.map((item) => item.id);
  210. };
  211. // 获取列表
  212. const batchList = () => {
  213. getList();
  214. };
  215. const getDeviceList = (row: any) => {
  216. deviceRef.value.openDialog(row);
  217. };
  218. return {
  219. deviceRef,
  220. checkRef,
  221. queryRef,
  222. tabDataList,
  223. onOpenAdd,
  224. onRowDel,
  225. getList,
  226. activation,
  227. resetQuery,
  228. handleSelectionChange,
  229. getDeviceList,
  230. ...toRefs(props),
  231. ...toRefs(state),
  232. };
  233. },
  234. });
  235. </script>