TurbineInfo.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div class="device-page">
  3. <a-card :bordered="false">
  4. <a-row :gutter="[12, 12]" align="middle">
  5. <a-col :xs="24" :md="8">
  6. <StationSelector v-model:value="queryParams.configStationId" :options="stationOptions" :multiple="false" />
  7. </a-col>
  8. <a-col :xs="24" :md="6">
  9. <a-input v-model:value="queryParams.name" placeholder="请输入设备名称" allow-clear @press-enter="handleQuery" />
  10. </a-col>
  11. <a-col :xs="24" :md="4" class="action-bar">
  12. <a-space>
  13. <a-button type="primary" :loading="loading" @click="handleQuery"><BearJiaIcon icon="SearchOutlined" />查询</a-button>
  14. <a-button @click="resetQuery">重置</a-button>
  15. </a-space>
  16. </a-col>
  17. </a-row>
  18. </a-card>
  19. <a-card title="光伏设备信息" :bordered="false" class="section">
  20. <a-space class="table-actions">
  21. <a-button type="primary" @click="openForm"><BearJiaIcon icon="plus-outlined" />新增</a-button>
  22. <a-button danger type="primary" :disabled="selectedRowKeys.length <= 0" @click="handleBatchDelete"><BearJiaIcon icon="delete-outlined" />删除</a-button>
  23. <a-button @click="handleExport"><BearJiaIcon icon="export-outlined" />导出</a-button>
  24. </a-space>
  25. <a-table
  26. :columns="columns"
  27. :data-source="rows"
  28. :loading="loading"
  29. :pagination="pagination"
  30. :locale="{emptyText: '暂无数据'}"
  31. row-key="id"
  32. :row-selection="rowSelection"
  33. @change="handleTableChange"
  34. >
  35. <template #bodyCell="{ column, record }">
  36. <template v-if="column.key === 'operation'">
  37. <TableActionBar :record="record" :has-view="false" :has-edit="true" :has-delete="true" @edit="openForm(record)" @delete="handleDeleteRecord(record)" />
  38. </template>
  39. </template>
  40. </a-table>
  41. </a-card>
  42. <a-modal v-model:open="formOpen" :title="form.id ? '编辑设备' : '新增设备'" width="640px" @ok="submitForm">
  43. <a-form ref="formRef" :model="form" :rules="rules" :label-col="{span: 5}" :wrapper-col="{span: 17}">
  44. <a-form-item label="设备名称" name="name">
  45. <a-input v-model:value="form.name" allow-clear placeholder="请输入设备名称" />
  46. </a-form-item>
  47. <a-form-item label="通道" name="configChannelId">
  48. <a-select v-model:value="form.configChannelId" :options="channelOptions" placeholder="请选择通道" />
  49. </a-form-item>
  50. <a-form-item label="所属场站" name="configStationId">
  51. <a-select v-model:value="form.configStationId" :options="stationOptions" placeholder="请选择所属场站" />
  52. </a-form-item>
  53. <a-form-item label="设备类型" name="tp">
  54. <a-select v-model:value="form.tp" :options="tpOptions" placeholder="请选择设备类型" />
  55. </a-form-item>
  56. <a-form-item label="品牌" name="brand">
  57. <a-input v-model:value="form.brand" allow-clear placeholder="请输入品牌" />
  58. </a-form-item>
  59. <a-form-item label="型号" name="model">
  60. <a-input v-model:value="form.model" allow-clear placeholder="请输入型号" />
  61. </a-form-item>
  62. <a-form-item label="序列号" name="serialNumber">
  63. <a-input v-model:value="form.serialNumber" allow-clear placeholder="请输入序列号" />
  64. </a-form-item>
  65. <a-form-item label="状态" name="status">
  66. <a-select v-model:value="form.status" :options="statusOptions" placeholder="请选择状态" />
  67. </a-form-item>
  68. <a-form-item label="投运日期" name="installDate">
  69. <a-date-picker v-model:value="form.installDate" value-format="YYYY-MM-DD" style="width: 100%" placeholder="请选择投运日期" />
  70. </a-form-item>
  71. </a-form>
  72. </a-modal>
  73. </div>
  74. </template>
  75. <script setup name="ElectricityTurbineInfo">
  76. import {computed, onMounted, reactive, ref} from 'vue';
  77. import {message, Modal} from 'ant-design-vue';
  78. import BearJiaUtil from '@/utils/BearJiaUtil';
  79. import {listStation} from '@/api/config/station';
  80. import {listChannel} from '@/api/config/channel';
  81. import {addDevice, delDevice, getDevice, listDevice, updateDevice} from '@/api/config/device';
  82. import StationSelector from '../components/StationSelector.vue';
  83. import TableActionBar from '@/components/TableActionBar/index.vue';
  84. import {normalizeRows} from '../components/dataAdapter';
  85. import {toStationOptions} from '../components/stationAdapter';
  86. import {BearJiaIcon} from '@/utils/BearJiaIcon.js';
  87. const loading = ref(false);
  88. const rows = ref([]);
  89. const stationOptions = ref([]);
  90. const channelOptions = ref([]);
  91. const selectedRowKeys = ref([]);
  92. const formOpen = ref(false);
  93. const formRef = ref();
  94. const queryParams = reactive({
  95. pageNum: 1,
  96. pageSize: 10,
  97. configStationId: undefined,
  98. name: undefined
  99. });
  100. const pagination = reactive({
  101. current: 1,
  102. pageSize: 10,
  103. total: 0,
  104. showSizeChanger: true
  105. });
  106. const form = reactive({});
  107. const rowSelection = computed(() => ({
  108. selectedRowKeys: selectedRowKeys.value,
  109. onChange: (keys) => {
  110. selectedRowKeys.value = keys;
  111. }
  112. }));
  113. const tpOptions = [
  114. {label: '气象设备', value: 'WEATHER'},
  115. {label: 'agvc设备', value: 'AGVC'}
  116. ];
  117. const statusOptions = [
  118. {label: '在线', value: 'GOOD'},
  119. {label: '离线', value: 'OFF'}
  120. ];
  121. const rules = {
  122. name: [{required: true, message: '请输入设备名称', trigger: 'blur'}],
  123. configChannelId: [{required: true, message: '请选择通道', trigger: 'change'}],
  124. configStationId: [{required: true, message: '请选择所属场站', trigger: 'change'}],
  125. tp: [{required: true, message: '请选择设备类型', trigger: 'change'}],
  126. brand: [{required: true, message: '请输入品牌', trigger: 'blur'}],
  127. model: [{required: true, message: '请输入型号', trigger: 'blur'}],
  128. serialNumber: [{required: true, message: '请输入序列号', trigger: 'blur'}],
  129. status: [{required: true, message: '请选择状态', trigger: 'change'}],
  130. installDate: [{required: true, message: '请选择投运日期', trigger: 'change'}]
  131. };
  132. const columns = [
  133. {
  134. title: '序号', width: 120, align: 'center',
  135. customRender: ({index}) => (pagination.current - 1) * pagination.pageSize + index + 1
  136. },
  137. {title: '设备名称', dataIndex: 'name'},
  138. {title: '通道', dataIndex: 'channelName'},
  139. {title: '所属场站', dataIndex: 'stationName'},
  140. {
  141. title: '设备类型', dataIndex: 'tp',
  142. customRender: ({text}) => (text === 'WEATHER' ? '气象设备' : text === 'AGVC' ? 'agvc设备' : text)
  143. },
  144. {title: '品牌', dataIndex: 'brand'},
  145. {title: '型号', dataIndex: 'model'},
  146. {title: '序列号', dataIndex: 'serialNumber'},
  147. {
  148. title: '状态', dataIndex: 'status', width: 120,
  149. customRender: ({text}) => (text === 'GOOD' ? '在线' : '离线')
  150. },
  151. {title: '投运日期', dataIndex: 'installDate', width: 180},
  152. {title: '操作', key: 'operation', dataIndex: 'operation', width: 200, fixed: 'right'}
  153. ];
  154. const resetObject = (target, source = {}) => {
  155. Object.keys(target).forEach((key) => delete target[key]);
  156. Object.assign(target, source);
  157. };
  158. const loadStationOptions = async () => {
  159. const res = await listStation({pageNum: 1, pageSize: 500});
  160. stationOptions.value = toStationOptions(normalizeRows(res));
  161. };
  162. const loadChannelOptions = async () => {
  163. const res = await listChannel({pageNum: 1, pageSize: 500});
  164. const channelRows = res?.rows || res?.data || [];
  165. channelOptions.value = channelRows.map((item) => ({label: item.name || item.id, value: item.id}));
  166. };
  167. const handleQuery = async () => {
  168. loading.value = true;
  169. try {
  170. const res = await listDevice(queryParams);
  171. rows.value = res?.rows || res?.data || [];
  172. pagination.total = res?.total || rows.value.length;
  173. pagination.current = queryParams.pageNum;
  174. pagination.pageSize = queryParams.pageSize;
  175. } finally {
  176. loading.value = false;
  177. }
  178. };
  179. const resetQuery = () => {
  180. queryParams.pageNum = 1;
  181. queryParams.configStationId = undefined;
  182. queryParams.name = undefined;
  183. handleQuery();
  184. };
  185. const handleTableChange = (page) => {
  186. queryParams.pageNum = page.current;
  187. queryParams.pageSize = page.pageSize;
  188. handleQuery();
  189. };
  190. const openForm = async (record) => {
  191. if (record?.id) {
  192. const res = await getDevice(record.id);
  193. resetObject(form, {...res.data});
  194. } else {
  195. resetObject(form, {configStationId: queryParams.configStationId});
  196. }
  197. formOpen.value = true;
  198. };
  199. const submitForm = async () => {
  200. await formRef.value?.validate();
  201. if (form.id) await updateDevice(form); else await addDevice(form);
  202. message.success('保存成功');
  203. formOpen.value = false;
  204. handleQuery();
  205. };
  206. const handleDeleteRecord = (record) => {
  207. Modal.confirm({
  208. title: '确认删除',
  209. content: '确认删除该设备?',
  210. okText: '确定',
  211. cancelText: '取消',
  212. onOk: async () => {
  213. await delDevice(record.id);
  214. message.success('删除成功');
  215. handleQuery();
  216. }
  217. });
  218. };
  219. const handleBatchDelete = () => {
  220. if (selectedRowKeys.value.length <= 0) {
  221. message.warning('请至少选择一条数据');
  222. return;
  223. }
  224. Modal.confirm({
  225. title: '确认删除',
  226. content: `确认删除选中的 ${selectedRowKeys.value.length} 条数据?`,
  227. okText: '确定',
  228. cancelText: '取消',
  229. onOk: async () => {
  230. await delDevice(selectedRowKeys.value);
  231. message.success('删除成功');
  232. selectedRowKeys.value = [];
  233. handleQuery();
  234. }
  235. });
  236. };
  237. const handleExport = () => {
  238. BearJiaUtil.download('config/device/export', queryParams, '设备配置.xlsx');
  239. };
  240. onMounted(async () => {
  241. await loadStationOptions();
  242. await loadChannelOptions();
  243. await handleQuery();
  244. });
  245. </script>
  246. <style lang="less" scoped>
  247. .device-page { padding: 16px; }
  248. .section { margin-top: 16px; }
  249. .action-bar { display: flex; justify-content: flex-end; }
  250. .table-actions { display: flex; margin-bottom: 12px; }
  251. </style>