feat: 添加新功能

This commit is contained in:
陈益 2025-07-30 23:44:47 +08:00
parent a894b1d510
commit 4185ad0d10
2 changed files with 114 additions and 87 deletions

View File

@ -12,11 +12,10 @@ import { message as Message, Modal, Tag } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
postDeviceInfoArchivesDown,
postAggregationDeviceCreateAsync,
postAggregationDeviceDeleteAsync,
postDeviceInfoArchivesDown,
postDeviceInfoPage,
postAggregationDeviceFindByIdAsync,
} from '#/api-client';
import { TableAction } from '#/components/table-action';
import { $t } from '#/locales';
@ -125,9 +124,9 @@ async function submit() {
const formValues = await formApi.getValues();
//
let processedFormValues = { ...formValues };
const processedFormValues = { ...formValues };
if (formValues.ioTPlatform === '2') {
if (formValues.ioTPlatform === 2 || formValues.ioTPlatform === '2') {
// OneNET
processedFormValues.ioTPlatformAccountId = formValues.oneNETAccountId;
processedFormValues.ioTPlatformProductId = formValues.oneNETProductId;
@ -136,7 +135,7 @@ async function submit() {
delete processedFormValues.oneNETProductId;
delete processedFormValues.ctWingAccountId;
delete processedFormValues.ctWingProductId;
} else if (formValues.ioTPlatform === '1') {
} else if (formValues.ioTPlatform === 1 || formValues.ioTPlatform === '1') {
// CTWing
processedFormValues.ioTPlatformAccountId = formValues.ctWingAccountId;
processedFormValues.ioTPlatformProductId = formValues.ctWingProductId;
@ -206,7 +205,9 @@ function onDel(row: any) {
title: `${$t('common.confirmDelete')}${row.deviceName || row.deviceAddress} ?`,
onOk: async () => {
try {
const result = await postAggregationDeviceDeleteAsync({ body: { id: row.id } });
const result = await postAggregationDeviceDeleteAsync({
body: { id: row.id },
});
if (result.data) {
gridApi.reload();
Message.success($t('common.deleteSuccess'));
@ -262,7 +263,8 @@ const openAddModal = async () => {
<Page auto-content-height>
<Grid>
<template #toolbar-actions>
<TableAction :actions="[
<TableAction
:actions="[
{
label: $t('common.add'),
type: 'primary',
@ -270,15 +272,10 @@ const openAddModal = async () => {
onClick: openAddModal.bind(null),
auth: ['AbpIdentity.Users.Create'],
},
]" />
]"
/>
</template>
<template #isMeterType="{ row }">
{{ meterTypeOptions[row.meterType - 1]?.label }}
</template>
<template #isSingleRate="{ row }">
{{rateOptions.find((item) => item.value === row.singleRate)?.label}}
</template>
<template #isArchiveStatus="{ row }">
{{
row.archiveStatus ? $t('common.Issued') : $t('common.Undistributed')
@ -288,32 +285,45 @@ const openAddModal = async () => {
{{ row.tripState ? $t('common.SwitchOff') : $t('common.Closing') }}
</template>
<template #isHaveValve="{ row }">
<component :is="h(Tag, { color: row.haveValve ? 'green' : 'red' }, () =>
<component
:is="
h(Tag, { color: row.haveValve ? 'green' : 'red' }, () =>
row.haveValve ? $t('common.yes') : $t('common.no'),
)
" />
"
/>
</template>
<template #isSelfDevelop="{ row }">
<component :is="h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () =>
<component
:is="
h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () =>
row.selfDevelop ? $t('common.yes') : $t('common.no'),
)
" />
"
/>
</template>
<template #isDynamicPassword="{ row }">
<component :is="h(Tag, { color: row.dynamicPassword ? 'green' : 'red' }, () =>
<component
:is="
h(Tag, { color: row.dynamicPassword ? 'green' : 'red' }, () =>
row.dynamicPassword ? $t('common.yes') : $t('common.no'),
)
" />
"
/>
</template>
<template #isEnable="{ row }">
<component :is="h(Tag, { color: row.enabled ? 'green' : 'red' }, () =>
<component
:is="
h(Tag, { color: row.enabled ? 'green' : 'red' }, () =>
row.enabled ? $t('common.yes') : $t('common.no'),
)
" />
"
/>
</template>
<template #action="{ row }">
<TableAction :actions="[
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
@ -321,7 +331,8 @@ const openAddModal = async () => {
auth: ['AbpIdentity.Users.Update'],
onClick: onEdit.bind(null, row),
},
]" :drop-down-actions="[
]"
:drop-down-actions="[
{
label: $t('common.delete'),
icon: 'ant-design:delete-outlined',
@ -346,10 +357,14 @@ const openAddModal = async () => {
auth: ['AbpIdentity.Users.Delete'],
onClick: archivesIssued.bind(null, row),
},
]" />
]"
/>
</template>
</Grid>
<UserModal :title="editRow.id ? $t('common.edit') : $t('common.add')" class="w-[800px]">
<UserModal
:title="editRow.id ? $t('common.edit') : $t('common.add')"
class="w-[800px]"
>
<component :is="editRow.id ? EditForm : AddForm" />
</UserModal>
</Page>

View File

@ -21,20 +21,6 @@ export const querySchema = computed(() => [
},
]);
export const ioTPlatformOptions = [
{
label: 'OneNET',
value: 1,
},
{
label: 'CTWing',
value: 2,
},
{
label: 'Other',
value: 0,
},
];
export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 },
{
@ -134,10 +120,10 @@ export const addDeviceFormSchema: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformAccountName'),
dependencies: {
show(values: any) {
return values.ioTPlatform === '2'; // OneNET平台
return values.ioTPlatform === 2 || values.ioTPlatform === '2'; // OneNET平台
},
rules(values: any) {
if (values.ioTPlatform === '2') {
if (values.ioTPlatform === 2 || values.ioTPlatform === '2') {
return 'required';
}
return null;
@ -187,15 +173,15 @@ export const addDeviceFormSchema: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformAccountName'),
dependencies: {
show(values: any) {
return values.ioTPlatform === '1'; // CTWing平台
return values.ioTPlatform === 1 || values.ioTPlatform === '1'; // CTWing平台
},
rules(values: any) {
if (values.ioTPlatform === '1') {
if (values.ioTPlatform === 1 || values.ioTPlatform === '1') {
return 'required';
}
return null;
},
triggerFields: ['ioTPlatform'],
triggerFields: ['ioTPlatform'], // 添加这一行,使其能够响应平台切换
},
componentProps: {
api: postCtWingAccountListAsync,
@ -206,7 +192,7 @@ export const addDeviceFormSchema: any = computed(() => [
},
},
labelField: 'accountName',
valueField: 'ctWingAccountId',
valueField: 'accountId',
immediate: true,
afterFetch: (res: any) => {
// 如果是 Axios 响应对象,提取 data
@ -240,10 +226,16 @@ export const addDeviceFormSchema: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformProductName'),
dependencies: {
show(values: any) {
return values.ioTPlatform === '2' && values.oneNETAccountId; // OneNET平台且已选择账号
return (
(values.ioTPlatform === 2 || values.ioTPlatform === '2') &&
values.oneNETAccountId
); // OneNET平台且已选择账号
},
rules(values: any) {
if (values.ioTPlatform === '2' && values.oneNETAccountId) {
if (
(values.ioTPlatform === 2 || values.ioTPlatform === '2') &&
values.oneNETAccountId
) {
return 'required';
}
return null;
@ -297,10 +289,16 @@ export const addDeviceFormSchema: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformProductName'),
dependencies: {
show(values: any) {
return values.ioTPlatform === '1' && values.ctWingAccountId; // CTWing平台且已选择账号
return (
(values.ioTPlatform === 1 || values.ioTPlatform === '1') &&
values.ctWingAccountId
); // CTWing平台且已选择账号
},
rules(values: any) {
if (values.ioTPlatform === '1' && values.ctWingAccountId) {
if (
(values.ioTPlatform === 1 || values.ioTPlatform === '1') &&
values.ctWingAccountId
) {
return 'required';
}
return null;
@ -334,9 +332,10 @@ export const addDeviceFormSchema: any = computed(() => [
items = data.data;
}
// 为每个产品项添加组合标签
// 为每个产品项添加组合标签并确保产品ID是字符串类型
return items.map((item: any) => ({
...item,
ioTPlatformProductId: String(item.ioTPlatformProductId || ''),
label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`,
}));
}
@ -401,10 +400,10 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformAccountName'),
dependencies: {
show(values: any) {
return values.ioTPlatform === '2'; // OneNET平台
return values.ioTPlatform === 2 || values.ioTPlatform === '2'; // OneNET平台
},
rules(values: any) {
if (values.ioTPlatform === '2') {
if (values.ioTPlatform === 2 || values.ioTPlatform === '2') {
return 'required';
}
return null;
@ -454,10 +453,10 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformAccountName'),
dependencies: {
show(values: any) {
return values.ioTPlatform === '1'; // CTWing平台
return values.ioTPlatform === 1 || values.ioTPlatform === '1'; // CTWing平台
},
rules(values: any) {
if (values.ioTPlatform === '1') {
if (values.ioTPlatform === 1 || values.ioTPlatform === '1') {
return 'required';
}
return null;
@ -507,10 +506,16 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformProductName'),
dependencies: {
show(values: any) {
return values.ioTPlatform === '2' && values.oneNETAccountId; // OneNET平台且已选择账号
return (
(values.ioTPlatform === 2 || values.ioTPlatform === '2') &&
values.oneNETAccountId
); // OneNET平台且已选择账号
},
rules(values: any) {
if (values.ioTPlatform === '2' && values.oneNETAccountId) {
if (
(values.ioTPlatform === 2 || values.ioTPlatform === '2') &&
values.oneNETAccountId
) {
return 'required';
}
return null;
@ -564,10 +569,16 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformProductName'),
dependencies: {
show(values: any) {
return values.ioTPlatform === '1' && values.ctWingAccountId; // CTWing平台且已选择账号
return (
(values.ioTPlatform === 1 || values.ioTPlatform === '1') &&
values.ctWingAccountId
); // CTWing平台且已选择账号
},
rules(values: any) {
if (values.ioTPlatform === '1' && values.ctWingAccountId) {
if (
(values.ioTPlatform === 1 || values.ioTPlatform === '1') &&
values.ctWingAccountId
) {
return 'required';
}
return null;
@ -601,9 +612,10 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
items = data.data;
}
// 为每个产品项添加组合标签
// 为每个产品项添加组合标签并确保产品ID是字符串类型
return items.map((item: any) => ({
...item,
ioTPlatformProductId: String(item.ioTPlatformProductId || ''),
label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`,
}));
}