243 lines
6.9 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';
2025-07-28 16:50:59 +08:00
import { postOneNetAccountListAsync } from '#/api-client';
export const querySchema = computed(() => [
{
component: 'Input',
2025-07-28 15:24:23 +08:00
fieldName: 'productName',
label: $t('abp.OneNETManagement.ProductName'),
},
]);
2025-07-28 15:24:23 +08:00
export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 },
{
2025-07-28 15:24:23 +08:00
field: 'oneNETProductId',
title: $t('abp.OneNETManagement.OneNETProductId'),
minWidth: '150',
},
{
2025-07-28 15:24:23 +08:00
field: 'productName',
title: $t('abp.OneNETManagement.ProductName'),
minWidth: '150',
},
{
2025-07-28 15:24:23 +08:00
field: 'productKey',
title: $t('abp.OneNETManagement.ProductKey'),
minWidth: '150',
},
{
2025-07-28 15:24:23 +08:00
field: 'productSecret',
title: $t('abp.OneNETManagement.ProductSecret'),
minWidth: '150',
},
{
2025-07-28 15:24:23 +08:00
field: 'accountName',
title: $t('abp.OneNETManagement.AccountName'),
minWidth: '150',
},
{
field: 'enabled',
title: $t('common.isEnable'),
minWidth: '150',
slots: { default: 'isEnable' },
},
{
title: $t('common.action'),
field: 'action',
fixed: 'right',
width: '150',
slots: { default: 'action' },
},
]);
2025-07-28 15:24:23 +08:00
export const addProductFormSchema: any = computed(() => [
2025-07-28 16:50:59 +08:00
{
component: 'ApiSelect',
fieldName: 'oneNETAccountId',
label: $t('abp.OneNETManagement.BelongingAccountName'),
componentProps: {
api: postOneNetAccountListAsync,
params: {
body: {
pageIndex: 1,
pageSize: 1000,
},
},
labelField: 'accountName',
valueField: 'oneNETAccountId',
immediate: true,
afterFetch: (res: any) => {
console.log('ApiSelect afterFetch res:', res);
// 如果是 Axios 响应对象,提取 data
if (res && res.data) {
console.log('提取 res.data:', res.data);
const data = res.data;
// 确保返回的是数组格式
if (Array.isArray(data)) {
console.log('返回数组,长度:', data.length);
return data;
}
// 如果是包装在 items 中的,提取出来
if (data && Array.isArray(data.items)) {
console.log('返回items数组长度:', data.items.length);
return data.items;
}
// 如果是包装在 data 中的,提取出来
if (data && Array.isArray(data.data)) {
console.log('返回data数组长度:', data.data.length);
return data.data;
}
}
// 如果都不是,返回空数组
console.log('没有找到数组数据,返回空数组');
return [];
},
placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`,
},
rules: z.string().min(1, {
message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`,
}),
},
{
component: 'Input',
2025-07-28 15:24:23 +08:00
fieldName: 'oneNETProductId',
label: $t('abp.OneNETManagement.OneNETProductId'),
rules: z.string().min(1, {
2025-07-28 15:24:23 +08:00
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.OneNETProductId')}`,
}),
},
{
component: 'Input',
2025-07-28 15:24:23 +08:00
fieldName: 'productName',
label: $t('abp.OneNETManagement.ProductName'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductName')}`,
}),
},
{
component: 'Input',
2025-07-28 15:24:23 +08:00
fieldName: 'productKey',
label: $t('abp.OneNETManagement.ProductKey'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductKey')}`,
}),
},
{
2025-07-28 15:24:23 +08:00
component: 'Input',
fieldName: 'productSecret',
label: $t('abp.OneNETManagement.ProductSecret'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductSecret')}`,
}),
},
{
component: 'Switch',
componentProps: {
class: 'w-auto',
},
2025-07-28 15:24:23 +08:00
fieldName: 'enabled',
label: $t('common.isEnable'),
},
2025-07-28 15:24:23 +08:00
]);
export const editProductFormSchemaEdit: any = computed(() => [
{
component: 'Input',
2025-07-28 15:24:23 +08:00
fieldName: 'oneNETProductId',
label: $t('abp.OneNETManagement.OneNETProductId'),
disabled: true,
},
{
component: 'Input',
2025-07-28 15:24:23 +08:00
fieldName: 'productName',
label: $t('abp.OneNETManagement.ProductName'),
rules: z.string().min(1, {
2025-07-28 15:24:23 +08:00
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductName')}`,
}),
},
{
component: 'Input',
2025-07-28 15:24:23 +08:00
fieldName: 'productKey',
label: $t('abp.OneNETManagement.ProductKey'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductKey')}`,
}),
},
{
component: 'Input',
2025-07-28 15:24:23 +08:00
fieldName: 'productSecret',
label: $t('abp.OneNETManagement.ProductSecret'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductSecret')}`,
}),
},
{
2025-07-28 16:50:59 +08:00
component: 'ApiSelect',
2025-07-28 15:24:23 +08:00
fieldName: 'accountName',
label: $t('abp.OneNETManagement.AccountName'),
2025-07-28 16:50:59 +08:00
componentProps: {
api: postOneNetAccountListAsync,
params: {
body: {
pageIndex: 1,
pageSize: 1000,
},
},
labelField: 'accountName',
valueField: 'oneNETAccountId',
immediate: true,
afterFetch: (res: any) => {
console.log('ApiSelect afterFetch res:', res);
// 如果是 Axios 响应对象,提取 data
if (res && res.data) {
console.log('提取 res.data:', res.data);
const data = res.data;
// 确保返回的是数组格式
if (Array.isArray(data)) {
console.log('返回数组,长度:', data.length);
return data;
}
// 如果是包装在 items 中的,提取出来
if (data && Array.isArray(data.items)) {
console.log('返回items数组长度:', data.items.length);
return data.items;
}
// 如果是包装在 data 中的,提取出来
if (data && Array.isArray(data.data)) {
console.log('返回data数组长度:', data.data.length);
return data.data;
}
}
// 如果都不是,返回空数组
console.log('没有找到数组数据,返回空数组');
return [];
},
placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.AccountName')}`,
},
2025-07-28 15:24:23 +08:00
rules: z.string().min(1, {
2025-07-28 16:50:59 +08:00
message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.AccountName')}`,
2025-07-28 15:24:23 +08:00
}),
},
{
component: 'Switch',
componentProps: {
class: 'w-auto',
},
2025-07-28 15:24:23 +08:00
fieldName: 'enabled',
label: $t('common.isEnable'),
},
]);