2025-06-25 17:29:57 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import type { VbenFormProps } from '#/adapter/form';
|
|
|
|
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
|
|
|
|
|
|
|
|
import { h, ref } from 'vue';
|
|
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
|
|
|
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
|
|
|
|
|
|
|
|
|
import { message as Message, Modal, Tag } from 'ant-design-vue';
|
|
|
|
|
|
|
|
|
|
import { useVbenForm } from '#/adapter/form';
|
|
|
|
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
|
|
|
import {
|
2025-07-28 14:38:00 +08:00
|
|
|
postAggregationDeviceCreateAsync,
|
|
|
|
|
postAggregationDeviceDeleteAsync,
|
2025-07-30 23:44:47 +08:00
|
|
|
postDeviceInfoArchivesDown,
|
2025-07-25 17:27:41 +08:00
|
|
|
postDeviceInfoPage,
|
2025-07-28 14:38:00 +08:00
|
|
|
} from '#/api-client';
|
2025-06-25 17:29:57 +08:00
|
|
|
import { TableAction } from '#/components/table-action';
|
|
|
|
|
import { $t } from '#/locales';
|
|
|
|
|
|
|
|
|
|
import {
|
2025-07-25 17:27:41 +08:00
|
|
|
addDeviceFormSchema,
|
|
|
|
|
editDeviceFormSchemaEdit,
|
2025-06-25 17:29:57 +08:00
|
|
|
querySchema,
|
|
|
|
|
tableSchema,
|
|
|
|
|
} from './schema';
|
|
|
|
|
|
|
|
|
|
defineOptions({
|
2025-07-25 17:27:41 +08:00
|
|
|
name: 'DeviceInfo',
|
2025-06-25 17:29:57 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const formOptions: VbenFormProps = {
|
|
|
|
|
schema: querySchema.value,
|
|
|
|
|
};
|
|
|
|
|
const gridOptions: VxeGridProps<any> = {
|
|
|
|
|
checkboxConfig: {
|
|
|
|
|
highlight: true,
|
|
|
|
|
labelField: 'name',
|
|
|
|
|
},
|
|
|
|
|
columns: tableSchema.value,
|
|
|
|
|
height: 'auto',
|
|
|
|
|
keepSource: true,
|
|
|
|
|
pagerConfig: {},
|
|
|
|
|
toolbarConfig: {
|
|
|
|
|
custom: true,
|
|
|
|
|
},
|
|
|
|
|
customConfig: {
|
|
|
|
|
storage: true,
|
|
|
|
|
},
|
|
|
|
|
proxyConfig: {
|
|
|
|
|
ajax: {
|
|
|
|
|
query: async ({ page }, formValues) => {
|
2025-07-25 17:27:41 +08:00
|
|
|
const { data } = await postDeviceInfoPage({
|
2025-06-25 17:29:57 +08:00
|
|
|
body: {
|
|
|
|
|
pageIndex: page.currentPage,
|
|
|
|
|
pageSize: page.pageSize,
|
|
|
|
|
...formValues,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
|
|
|
|
|
|
|
|
|
const editRow: Record<string, any> = ref({});
|
|
|
|
|
const [UserModal, userModalApi] = useVbenModal({
|
|
|
|
|
draggable: true,
|
|
|
|
|
onConfirm: submit,
|
|
|
|
|
onBeforeClose: () => {
|
|
|
|
|
editRow.value = {};
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [AddForm, addFormApi] = useVbenForm({
|
|
|
|
|
// 默认展开
|
|
|
|
|
collapsed: false,
|
|
|
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
|
|
|
commonConfig: {
|
|
|
|
|
labelWidth: 110,
|
|
|
|
|
componentProps: {
|
|
|
|
|
class: 'w-4/5',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
layout: 'horizontal',
|
2025-07-25 17:27:41 +08:00
|
|
|
schema: addDeviceFormSchema.value,
|
2025-06-25 17:29:57 +08:00
|
|
|
showCollapseButton: false,
|
|
|
|
|
showDefaultActions: false,
|
|
|
|
|
wrapperClass: 'grid-cols-2',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [EditForm, editFormApi] = useVbenForm({
|
|
|
|
|
// 默认展开
|
|
|
|
|
collapsed: false,
|
|
|
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
|
|
|
commonConfig: {
|
|
|
|
|
labelWidth: 110,
|
|
|
|
|
componentProps: {
|
|
|
|
|
class: 'w-4/5',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// 提交函数
|
|
|
|
|
layout: 'horizontal',
|
2025-07-25 17:27:41 +08:00
|
|
|
schema: editDeviceFormSchemaEdit.value,
|
2025-06-25 17:29:57 +08:00
|
|
|
showCollapseButton: false,
|
|
|
|
|
showDefaultActions: false,
|
|
|
|
|
wrapperClass: 'grid-cols-2',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 新增和编辑提交的逻辑
|
|
|
|
|
async function submit() {
|
|
|
|
|
const isEdit = !!editRow.value.id;
|
|
|
|
|
const formApi = isEdit ? editFormApi : addFormApi;
|
2025-07-28 16:50:59 +08:00
|
|
|
const api = postAggregationDeviceCreateAsync; // 目前只有创建接口,编辑也使用创建接口
|
2025-06-25 17:29:57 +08:00
|
|
|
const { valid } = await formApi.validate();
|
|
|
|
|
if (!valid) return;
|
|
|
|
|
|
|
|
|
|
const formValues = await formApi.getValues();
|
2025-07-30 23:44:47 +08:00
|
|
|
|
2025-07-30 15:05:32 +08:00
|
|
|
// 根据平台类型处理数据
|
2025-07-30 23:44:47 +08:00
|
|
|
const processedFormValues = { ...formValues };
|
|
|
|
|
|
|
|
|
|
if (formValues.ioTPlatform === 2 || formValues.ioTPlatform === '2') {
|
2025-07-30 15:05:32 +08:00
|
|
|
// OneNET平台
|
|
|
|
|
processedFormValues.ioTPlatformAccountId = formValues.oneNETAccountId;
|
|
|
|
|
processedFormValues.ioTPlatformProductId = formValues.oneNETProductId;
|
|
|
|
|
// 清理不需要的字段
|
|
|
|
|
delete processedFormValues.oneNETAccountId;
|
|
|
|
|
delete processedFormValues.oneNETProductId;
|
|
|
|
|
delete processedFormValues.ctWingAccountId;
|
|
|
|
|
delete processedFormValues.ctWingProductId;
|
2025-07-30 23:44:47 +08:00
|
|
|
} else if (formValues.ioTPlatform === 1 || formValues.ioTPlatform === '1') {
|
2025-07-30 15:05:32 +08:00
|
|
|
// CTWing平台
|
|
|
|
|
processedFormValues.ioTPlatformAccountId = formValues.ctWingAccountId;
|
|
|
|
|
processedFormValues.ioTPlatformProductId = formValues.ctWingProductId;
|
|
|
|
|
// 清理不需要的字段
|
|
|
|
|
delete processedFormValues.ctWingAccountId;
|
|
|
|
|
delete processedFormValues.ctWingProductId;
|
|
|
|
|
delete processedFormValues.oneNETAccountId;
|
|
|
|
|
delete processedFormValues.oneNETProductId;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-25 17:29:57 +08:00
|
|
|
const fetchParams: any = isEdit
|
|
|
|
|
? {
|
2025-07-28 16:50:59 +08:00
|
|
|
id: editRow.value.id,
|
2025-07-30 15:05:32 +08:00
|
|
|
...processedFormValues,
|
2025-07-28 16:50:59 +08:00
|
|
|
}
|
2025-06-25 17:29:57 +08:00
|
|
|
: {
|
2025-07-30 15:05:32 +08:00
|
|
|
...processedFormValues,
|
2025-07-28 16:50:59 +08:00
|
|
|
};
|
2025-06-25 17:29:57 +08:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
userModalApi.setState({ loading: true, confirmLoading: true });
|
|
|
|
|
const resp = await api({ body: fetchParams });
|
|
|
|
|
if (resp.data) {
|
|
|
|
|
Message.success(
|
|
|
|
|
editRow.value.id ? $t('common.editSuccess') : $t('common.addSuccess'),
|
|
|
|
|
);
|
|
|
|
|
userModalApi.close();
|
2025-07-28 16:50:59 +08:00
|
|
|
editRow.value = {};
|
2025-06-25 17:29:57 +08:00
|
|
|
gridApi.reload();
|
|
|
|
|
} else {
|
|
|
|
|
Message.error(
|
|
|
|
|
editRow.value.id ? $t('common.editFail') : $t('common.addFail'),
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-07-28 16:50:59 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error('设备操作失败:', error);
|
|
|
|
|
Message.error(
|
|
|
|
|
editRow.value.id ? $t('common.editFail') : $t('common.addFail'),
|
|
|
|
|
);
|
2025-06-25 17:29:57 +08:00
|
|
|
} finally {
|
|
|
|
|
userModalApi.setState({ loading: false, confirmLoading: false });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function onEdit(record: any) {
|
|
|
|
|
editRow.value = record;
|
|
|
|
|
userModalApi.open();
|
2025-07-30 23:44:47 +08:00
|
|
|
|
2025-07-30 15:05:32 +08:00
|
|
|
// 根据平台类型设置表单值
|
|
|
|
|
const formValues = { ...record };
|
2025-07-30 23:44:47 +08:00
|
|
|
|
2025-07-30 17:17:08 +08:00
|
|
|
if (record.ioTPlatform === 2 || record.ioTPlatform === '2') {
|
2025-07-30 15:05:32 +08:00
|
|
|
// OneNET平台
|
|
|
|
|
formValues.oneNETAccountId = record.ioTPlatformAccountId;
|
|
|
|
|
formValues.oneNETProductId = record.ioTPlatformProductId;
|
2025-07-30 17:17:08 +08:00
|
|
|
} else if (record.ioTPlatform === 1 || record.ioTPlatform === '1') {
|
2025-07-30 15:05:32 +08:00
|
|
|
// CTWing平台
|
|
|
|
|
formValues.ctWingAccountId = record.ioTPlatformAccountId;
|
|
|
|
|
formValues.ctWingProductId = record.ioTPlatformProductId;
|
|
|
|
|
}
|
2025-07-30 23:44:47 +08:00
|
|
|
|
2025-07-30 15:05:32 +08:00
|
|
|
editFormApi.setValues(formValues);
|
2025-06-25 17:29:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDel(row: any) {
|
|
|
|
|
Modal.confirm({
|
2025-07-28 16:50:59 +08:00
|
|
|
title: `${$t('common.confirmDelete')}${row.deviceName || row.deviceAddress} ?`,
|
2025-06-25 17:29:57 +08:00
|
|
|
onOk: async () => {
|
2025-07-28 16:50:59 +08:00
|
|
|
try {
|
2025-07-30 23:44:47 +08:00
|
|
|
const result = await postAggregationDeviceDeleteAsync({
|
|
|
|
|
body: { id: row.id },
|
|
|
|
|
});
|
2025-07-28 16:50:59 +08:00
|
|
|
if (result.data) {
|
|
|
|
|
gridApi.reload();
|
|
|
|
|
Message.success($t('common.deleteSuccess'));
|
|
|
|
|
} else {
|
|
|
|
|
Message.error($t('common.deleteFail'));
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('删除设备失败:', error);
|
2025-06-25 17:29:57 +08:00
|
|
|
Message.error($t('common.deleteFail'));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const toStatusData = (row: Record<string, any>) => {
|
|
|
|
|
// 或者使用编程式导航
|
|
|
|
|
router.push({
|
2025-07-14 11:06:36 +08:00
|
|
|
path: '/iotdb/deviceData',
|
2025-06-25 17:29:57 +08:00
|
|
|
query: {
|
2025-07-28 16:50:59 +08:00
|
|
|
DeviceType: row.ioTPlatform,
|
|
|
|
|
DeviceId: row.deviceAddress,
|
|
|
|
|
FocusAddress: row.ioTPlatformDeviceOpenInfo,
|
|
|
|
|
DataBaseName: row.deviceName,
|
2025-06-25 17:29:57 +08:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
// 档案下发
|
|
|
|
|
const archivesIssued = async (row: Record<string, any>) => {
|
2025-07-28 16:50:59 +08:00
|
|
|
try {
|
|
|
|
|
const result = await postDeviceInfoArchivesDown({
|
|
|
|
|
body: {
|
|
|
|
|
meterAddress: row.deviceAddress,
|
|
|
|
|
meterType: row.ioTPlatform,
|
|
|
|
|
focusAddress: row.ioTPlatformDeviceOpenInfo,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
if (result.data) {
|
|
|
|
|
Message.success($t('common.operationSuccess'));
|
|
|
|
|
} else {
|
|
|
|
|
Message.error($t('common.operationFail'));
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('档案下发失败:', error);
|
|
|
|
|
Message.error($t('common.operationFail'));
|
2025-06-25 17:29:57 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const openAddModal = async () => {
|
|
|
|
|
editRow.value = {};
|
|
|
|
|
userModalApi.open();
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Page auto-content-height>
|
|
|
|
|
<Grid>
|
|
|
|
|
<template #toolbar-actions>
|
2025-07-30 23:44:47 +08:00
|
|
|
<TableAction
|
|
|
|
|
:actions="[
|
|
|
|
|
{
|
|
|
|
|
label: $t('common.add'),
|
|
|
|
|
type: 'primary',
|
|
|
|
|
icon: 'ant-design:plus-outlined',
|
|
|
|
|
onClick: openAddModal.bind(null),
|
|
|
|
|
auth: ['AbpIdentity.Users.Create'],
|
|
|
|
|
},
|
|
|
|
|
]"
|
|
|
|
|
/>
|
2025-06-25 17:29:57 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<template #isArchiveStatus="{ row }">
|
|
|
|
|
{{
|
|
|
|
|
row.archiveStatus ? $t('common.Issued') : $t('common.Undistributed')
|
|
|
|
|
}}
|
|
|
|
|
</template>
|
|
|
|
|
<template #isTripState="{ row }">
|
|
|
|
|
{{ row.tripState ? $t('common.SwitchOff') : $t('common.Closing') }}
|
|
|
|
|
</template>
|
|
|
|
|
<template #isHaveValve="{ row }">
|
2025-07-30 23:44:47 +08:00
|
|
|
<component
|
|
|
|
|
:is="
|
|
|
|
|
h(Tag, { color: row.haveValve ? 'green' : 'red' }, () =>
|
|
|
|
|
row.haveValve ? $t('common.yes') : $t('common.no'),
|
|
|
|
|
)
|
|
|
|
|
"
|
|
|
|
|
/>
|
2025-06-25 17:29:57 +08:00
|
|
|
</template>
|
|
|
|
|
<template #isSelfDevelop="{ row }">
|
2025-07-30 23:44:47 +08:00
|
|
|
<component
|
|
|
|
|
:is="
|
|
|
|
|
h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () =>
|
|
|
|
|
row.selfDevelop ? $t('common.yes') : $t('common.no'),
|
|
|
|
|
)
|
|
|
|
|
"
|
|
|
|
|
/>
|
2025-06-25 17:29:57 +08:00
|
|
|
</template>
|
|
|
|
|
<template #isDynamicPassword="{ row }">
|
2025-07-30 23:44:47 +08:00
|
|
|
<component
|
|
|
|
|
:is="
|
|
|
|
|
h(Tag, { color: row.dynamicPassword ? 'green' : 'red' }, () =>
|
|
|
|
|
row.dynamicPassword ? $t('common.yes') : $t('common.no'),
|
|
|
|
|
)
|
|
|
|
|
"
|
|
|
|
|
/>
|
2025-06-25 17:29:57 +08:00
|
|
|
</template>
|
|
|
|
|
<template #isEnable="{ row }">
|
2025-07-30 23:44:47 +08:00
|
|
|
<component
|
|
|
|
|
:is="
|
|
|
|
|
h(Tag, { color: row.enabled ? 'green' : 'red' }, () =>
|
|
|
|
|
row.enabled ? $t('common.yes') : $t('common.no'),
|
|
|
|
|
)
|
|
|
|
|
"
|
|
|
|
|
/>
|
2025-06-25 17:29:57 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<template #action="{ row }">
|
2025-07-30 23:44:47 +08:00
|
|
|
<TableAction
|
|
|
|
|
:actions="[
|
|
|
|
|
{
|
|
|
|
|
label: $t('common.edit'),
|
|
|
|
|
type: 'link',
|
|
|
|
|
size: 'small',
|
|
|
|
|
auth: ['AbpIdentity.Users.Update'],
|
|
|
|
|
onClick: onEdit.bind(null, row),
|
|
|
|
|
},
|
|
|
|
|
]"
|
|
|
|
|
:drop-down-actions="[
|
2025-06-25 17:29:57 +08:00
|
|
|
{
|
|
|
|
|
label: $t('common.delete'),
|
|
|
|
|
icon: 'ant-design:delete-outlined',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
auth: ['AbpIdentity.Users.Delete'],
|
|
|
|
|
popConfirm: {
|
|
|
|
|
title: $t('common.askConfirmDelete'),
|
|
|
|
|
confirm: onDel.bind(null, row),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-07-25 17:27:41 +08:00
|
|
|
label: $t('abp.DeviceInfo.pointData'),
|
2025-06-25 17:29:57 +08:00
|
|
|
icon: 'ant-design:profile-outlined',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
auth: ['AbpIdentity.Users.Delete'],
|
|
|
|
|
onClick: toStatusData.bind(null, row),
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-07-25 17:27:41 +08:00
|
|
|
label: $t('abp.DeviceInfo.archivesIssued'),
|
2025-06-25 17:29:57 +08:00
|
|
|
icon: 'ant-design:cloud-download-outlined',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
auth: ['AbpIdentity.Users.Delete'],
|
|
|
|
|
onClick: archivesIssued.bind(null, row),
|
|
|
|
|
},
|
2025-07-30 23:44:47 +08:00
|
|
|
]"
|
|
|
|
|
/>
|
2025-06-25 17:29:57 +08:00
|
|
|
</template>
|
|
|
|
|
</Grid>
|
2025-07-30 23:44:47 +08:00
|
|
|
<UserModal
|
|
|
|
|
:title="editRow.id ? $t('common.edit') : $t('common.add')"
|
|
|
|
|
class="w-[800px]"
|
|
|
|
|
>
|
2025-06-25 17:29:57 +08:00
|
|
|
<component :is="editRow.id ? EditForm : AddForm" />
|
|
|
|
|
</UserModal>
|
|
|
|
|
</Page>
|
|
|
|
|
</template>
|