282 lines
6.6 KiB
TypeScript
Raw Normal View History

import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed } from 'vue';
import { z } from '@vben/common-ui';
import { $t } from '#/locales';
export const querySchema = computed(() => [
{
component: 'Input',
2025-07-25 17:27:41 +08:00
fieldName: 'deviceAddress',
label: $t('abp.deviceInfos.deviceAddress'),
},
]);
export const meterTypeOptions = [
{
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.ElectricityMeter'),
value: 1,
},
{
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.waterMeter'),
value: 2,
},
{
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.GasMeter'),
value: 3,
},
{
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.HeatMeter'),
value: 4,
},
{
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.WaterMeterFlowmeter'),
value: 5,
},
{
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.GasMeterFlowmeter'),
value: 6,
},
];
export const rateOptions = [
{
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.MultipleRate'),
value: false,
},
{
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.SingleRate'),
value: true,
},
];
export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 },
{
2025-07-25 17:27:41 +08:00
field: 'deviceName',
title: $t('abp.deviceInfos.deviceName'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'deviceAddress',
title: $t('abp.deviceInfos.deviceAddress'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatform',
title: $t('abp.deviceInfos.ioTPlatform'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformName',
title: $t('abp.deviceInfos.ioTPlatformName'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformDeviceOpenInfo',
title: $t('abp.deviceInfos.ioTPlatformDeviceOpenInfo'),
minWidth: '100',
},
{
2025-07-25 17:27:41 +08:00
field: 'platformPassword',
title: $t('abp.deviceInfos.platformPassword'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformProductName',
title: $t('abp.deviceInfos.ioTPlatformProductName'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformAccountName',
title: $t('abp.deviceInfos.ioTPlatformAccountName'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformResponse',
title: $t('abp.deviceInfos.ioTPlatformResponse'),
minWidth: '150',
},
{
title: $t('common.action'),
field: 'action',
fixed: 'right',
width: '150',
slots: { default: 'action' },
},
]);
2025-07-25 17:27:41 +08:00
export const addDeviceFormSchema: any = computed(() => [
{
component: 'Input',
2025-07-25 17:27:41 +08:00
fieldName: 'deviceAddress',
label: $t('abp.deviceInfos.deviceAddress'),
rules: z.string().min(1, {
2025-07-25 17:27:41 +08:00
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceAddress')}`,
}),
},
{
component: 'Input',
2025-07-25 17:27:41 +08:00
fieldName: 'platformPassword',
label: $t('abp.deviceInfos.platformPassword'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.platformPassword')}`,
}),
},
]);
2025-07-25 17:27:41 +08:00
export const editDeviceFormSchemaEdit: any = computed(() => [
{
component: 'Input',
2025-07-25 17:27:41 +08:00
fieldName: 'deviceAddress',
label: $t('abp.deviceInfos.deviceAddress'),
rules: z.string().min(1, {
2025-07-25 17:27:41 +08:00
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.deviceInfos.deviceAddress')}`,
}),
},
{
component: 'Input',
2025-07-25 17:27:41 +08:00
fieldName: 'platformPassword',
label: $t('abp.deviceInfos.platformPassword'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.deviceInfos.platformPassword')}`,
}),
},
{
component: 'Select',
componentProps: {
allowClear: true,
options: meterTypeOptions,
2025-07-25 17:27:41 +08:00
placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.meterType')}`,
},
fieldName: 'meterType',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.meterType'),
rules: z
.number()
.min(1, {
2025-07-25 17:27:41 +08:00
message: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.meterType')}`,
})
.default(1),
},
{
component: 'Select',
componentProps: {
allowClear: true,
options: rateOptions,
2025-07-25 17:27:41 +08:00
placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.singleRate')}`,
},
dependencies: {
show(values: any) {
return values.meterType === 1;
},
rules(values: any) {
if (values.meterType === 1) {
return 'required';
}
return null;
},
triggerFields: ['meterType'],
},
fieldName: 'singleRate',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.singleRate'),
},
{
component: 'Switch',
componentProps: {
class: 'w-auto',
},
fieldName: 'selfDevelop',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.selfDevelop'),
},
{
component: 'Input',
fieldName: 'brandType',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.brandType'),
rules: z.string().optional(),
},
{
component: 'Switch',
componentProps: {
class: 'w-auto',
},
fieldName: 'dynamicPassword',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.dynamicPassword'),
},
{
component: 'Input',
fieldName: 'password',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.password'),
rules: z.string().optional(),
},
{
component: 'Switch',
componentProps: {
class: 'w-auto',
},
dependencies: {
show(values: any) {
return values.meterType === 2;
},
triggerFields: ['meterType'],
},
fieldName: 'haveValve',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.haveValve'),
},
{
component: 'Input',
fieldName: 'timesA',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.timesA'),
componentProps: {
allowClear: true,
2025-07-25 17:27:41 +08:00
placeholder: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.timesA')}`,
},
dependencies: {
show(values: any) {
return values.meterType === 1;
},
triggerFields: ['meterType'],
},
rules: z
.string({
2025-07-25 17:27:41 +08:00
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.timesA')}`,
})
.default('1'),
},
{
component: 'Input',
fieldName: 'timev',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.timev'),
componentProps: {
allowClear: true,
2025-07-25 17:27:41 +08:00
placeholder: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.timev')}`,
},
dependencies: {
show(values: any) {
return values.meterType === 1;
},
triggerFields: ['meterType'],
},
rules: z
.string({
2025-07-25 17:27:41 +08:00
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.timev')}`,
})
.default('1'),
},
{
component: 'Input',
fieldName: 'meteringCode',
2025-07-25 17:27:41 +08:00
label: $t('abp.deviceInfos.meteringCode'),
componentProps: {
allowClear: true,
2025-07-25 17:27:41 +08:00
placeholder: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.meteringCode')}`,
},
rules: z
.string({
2025-07-25 17:27:41 +08:00
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.meteringCode')}`,
})
.min(1, {
message: `${$t('common.MustGreaterTthan0')}`,
})
.default('1'),
},
]);