| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- <template>
- <div class="device-page">
- <a-card :bordered="false">
- <a-row :gutter="[12, 12]" align="middle">
- <a-col :xs="24" :md="8">
- <StationSelector v-model:value="queryParams.configStationId" :options="stationOptions" :multiple="false" />
- </a-col>
- <a-col :xs="24" :md="6">
- <a-input v-model:value="queryParams.name" placeholder="请输入设备名称" allow-clear @press-enter="handleQuery" />
- </a-col>
- <a-col :xs="24" :md="4" class="action-bar">
- <a-space>
- <a-button type="primary" :loading="loading" @click="handleQuery"><BearJiaIcon icon="SearchOutlined" />查询</a-button>
- <a-button @click="resetQuery">重置</a-button>
- </a-space>
- </a-col>
- </a-row>
- </a-card>
- <a-card title="光伏设备信息" :bordered="false" class="section">
- <a-space class="table-actions">
- <a-button type="primary" @click="openForm"><BearJiaIcon icon="plus-outlined" />新增</a-button>
- <a-button danger type="primary" :disabled="selectedRowKeys.length <= 0" @click="handleBatchDelete"><BearJiaIcon icon="delete-outlined" />删除</a-button>
- <a-button @click="handleExport"><BearJiaIcon icon="export-outlined" />导出</a-button>
- </a-space>
- <a-table
- :columns="columns"
- :data-source="rows"
- :loading="loading"
- :pagination="pagination"
- :locale="{emptyText: '暂无数据'}"
- row-key="id"
- :row-selection="rowSelection"
- @change="handleTableChange"
- >
- <template #bodyCell="{ column, record }">
- <template v-if="column.key === 'operation'">
- <TableActionBar :record="record" :has-view="false" :has-edit="true" :has-delete="true" @edit="openForm(record)" @delete="handleDeleteRecord(record)" />
- </template>
- </template>
- </a-table>
- </a-card>
- <a-modal v-model:open="formOpen" :title="form.id ? '编辑设备' : '新增设备'" width="640px" @ok="submitForm">
- <a-form ref="formRef" :model="form" :rules="rules" :label-col="{span: 5}" :wrapper-col="{span: 17}">
- <a-form-item label="设备名称" name="name">
- <a-input v-model:value="form.name" allow-clear placeholder="请输入设备名称" />
- </a-form-item>
- <a-form-item label="通道" name="configChannelId">
- <a-select v-model:value="form.configChannelId" :options="channelOptions" placeholder="请选择通道" />
- </a-form-item>
- <a-form-item label="所属场站" name="configStationId">
- <a-select v-model:value="form.configStationId" :options="stationOptions" placeholder="请选择所属场站" />
- </a-form-item>
- <a-form-item label="设备类型" name="tp">
- <a-select v-model:value="form.tp" :options="tpOptions" placeholder="请选择设备类型" />
- </a-form-item>
- <a-form-item label="品牌" name="brand">
- <a-input v-model:value="form.brand" allow-clear placeholder="请输入品牌" />
- </a-form-item>
- <a-form-item label="型号" name="model">
- <a-input v-model:value="form.model" allow-clear placeholder="请输入型号" />
- </a-form-item>
- <a-form-item label="序列号" name="serialNumber">
- <a-input v-model:value="form.serialNumber" allow-clear placeholder="请输入序列号" />
- </a-form-item>
- <a-form-item label="状态" name="status">
- <a-select v-model:value="form.status" :options="statusOptions" placeholder="请选择状态" />
- </a-form-item>
- <a-form-item label="投运日期" name="installDate">
- <a-date-picker v-model:value="form.installDate" value-format="YYYY-MM-DD" style="width: 100%" placeholder="请选择投运日期" />
- </a-form-item>
- </a-form>
- </a-modal>
- </div>
- </template>
- <script setup name="ElectricityTurbineInfo">
- import {computed, onMounted, reactive, ref} from 'vue';
- import {message, Modal} from 'ant-design-vue';
- import BearJiaUtil from '@/utils/BearJiaUtil';
- import {listStation} from '@/api/config/station';
- import {listChannel} from '@/api/config/channel';
- import {addDevice, delDevice, getDevice, listDevice, updateDevice} from '@/api/config/device';
- import StationSelector from '../components/StationSelector.vue';
- import TableActionBar from '@/components/TableActionBar/index.vue';
- import {normalizeRows} from '../components/dataAdapter';
- import {toStationOptions} from '../components/stationAdapter';
- import {BearJiaIcon} from '@/utils/BearJiaIcon.js';
- const loading = ref(false);
- const rows = ref([]);
- const stationOptions = ref([]);
- const channelOptions = ref([]);
- const selectedRowKeys = ref([]);
- const formOpen = ref(false);
- const formRef = ref();
- const queryParams = reactive({
- pageNum: 1,
- pageSize: 10,
- configStationId: undefined,
- name: undefined
- });
- const pagination = reactive({
- current: 1,
- pageSize: 10,
- total: 0,
- showSizeChanger: true
- });
- const form = reactive({});
- const rowSelection = computed(() => ({
- selectedRowKeys: selectedRowKeys.value,
- onChange: (keys) => {
- selectedRowKeys.value = keys;
- }
- }));
- const tpOptions = [
- {label: '气象设备', value: 'WEATHER'},
- {label: 'agvc设备', value: 'AGVC'}
- ];
- const statusOptions = [
- {label: '在线', value: 'GOOD'},
- {label: '离线', value: 'OFF'}
- ];
- const rules = {
- name: [{required: true, message: '请输入设备名称', trigger: 'blur'}],
- configChannelId: [{required: true, message: '请选择通道', trigger: 'change'}],
- configStationId: [{required: true, message: '请选择所属场站', trigger: 'change'}],
- tp: [{required: true, message: '请选择设备类型', trigger: 'change'}],
- brand: [{required: true, message: '请输入品牌', trigger: 'blur'}],
- model: [{required: true, message: '请输入型号', trigger: 'blur'}],
- serialNumber: [{required: true, message: '请输入序列号', trigger: 'blur'}],
- status: [{required: true, message: '请选择状态', trigger: 'change'}],
- installDate: [{required: true, message: '请选择投运日期', trigger: 'change'}]
- };
- const columns = [
- {
- title: '序号', width: 120, align: 'center',
- customRender: ({index}) => (pagination.current - 1) * pagination.pageSize + index + 1
- },
- {title: '设备名称', dataIndex: 'name'},
- {title: '通道', dataIndex: 'channelName'},
- {title: '所属场站', dataIndex: 'stationName'},
- {
- title: '设备类型', dataIndex: 'tp',
- customRender: ({text}) => (text === 'WEATHER' ? '气象设备' : text === 'AGVC' ? 'agvc设备' : text)
- },
- {title: '品牌', dataIndex: 'brand'},
- {title: '型号', dataIndex: 'model'},
- {title: '序列号', dataIndex: 'serialNumber'},
- {
- title: '状态', dataIndex: 'status', width: 120,
- customRender: ({text}) => (text === 'GOOD' ? '在线' : '离线')
- },
- {title: '投运日期', dataIndex: 'installDate', width: 180},
- {title: '操作', key: 'operation', dataIndex: 'operation', width: 200, fixed: 'right'}
- ];
- const resetObject = (target, source = {}) => {
- Object.keys(target).forEach((key) => delete target[key]);
- Object.assign(target, source);
- };
- const loadStationOptions = async () => {
- const res = await listStation({pageNum: 1, pageSize: 500});
- stationOptions.value = toStationOptions(normalizeRows(res));
- };
- const loadChannelOptions = async () => {
- const res = await listChannel({pageNum: 1, pageSize: 500});
- const channelRows = res?.rows || res?.data || [];
- channelOptions.value = channelRows.map((item) => ({label: item.name || item.id, value: item.id}));
- };
- const handleQuery = async () => {
- loading.value = true;
- try {
- const res = await listDevice(queryParams);
- rows.value = res?.rows || res?.data || [];
- pagination.total = res?.total || rows.value.length;
- pagination.current = queryParams.pageNum;
- pagination.pageSize = queryParams.pageSize;
- } finally {
- loading.value = false;
- }
- };
- const resetQuery = () => {
- queryParams.pageNum = 1;
- queryParams.configStationId = undefined;
- queryParams.name = undefined;
- handleQuery();
- };
- const handleTableChange = (page) => {
- queryParams.pageNum = page.current;
- queryParams.pageSize = page.pageSize;
- handleQuery();
- };
- const openForm = async (record) => {
- if (record?.id) {
- const res = await getDevice(record.id);
- resetObject(form, {...res.data});
- } else {
- resetObject(form, {configStationId: queryParams.configStationId});
- }
- formOpen.value = true;
- };
- const submitForm = async () => {
- await formRef.value?.validate();
- if (form.id) await updateDevice(form); else await addDevice(form);
- message.success('保存成功');
- formOpen.value = false;
- handleQuery();
- };
- const handleDeleteRecord = (record) => {
- Modal.confirm({
- title: '确认删除',
- content: '确认删除该设备?',
- okText: '确定',
- cancelText: '取消',
- onOk: async () => {
- await delDevice(record.id);
- message.success('删除成功');
- handleQuery();
- }
- });
- };
- const handleBatchDelete = () => {
- if (selectedRowKeys.value.length <= 0) {
- message.warning('请至少选择一条数据');
- return;
- }
- Modal.confirm({
- title: '确认删除',
- content: `确认删除选中的 ${selectedRowKeys.value.length} 条数据?`,
- okText: '确定',
- cancelText: '取消',
- onOk: async () => {
- await delDevice(selectedRowKeys.value);
- message.success('删除成功');
- selectedRowKeys.value = [];
- handleQuery();
- }
- });
- };
- const handleExport = () => {
- BearJiaUtil.download('config/device/export', queryParams, '设备配置.xlsx');
- };
- onMounted(async () => {
- await loadStationOptions();
- await loadChannelOptions();
- await handleQuery();
- });
- </script>
- <style lang="less" scoped>
- .device-page { padding: 16px; }
- .section { margin-top: 16px; }
- .action-bar { display: flex; justify-content: flex-end; }
- .table-actions { display: flex; margin-bottom: 12px; }
- </style>
|