Compare commits
No commits in common. "3648af31ab2fcd9e1f68fe220cb808463efab25b" and "62ce737dea3a2f44e46704b97b62841db43155fb" have entirely different histories.
3648af31ab
...
62ce737dea
@ -131,7 +131,6 @@
|
|||||||
"status": "Status",
|
"status": "Status",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
"extendedAttribute": "ExtendedAttribute",
|
"extendedAttribute": "ExtendedAttribute",
|
||||||
"extendedAttributeValue": "ExtendedAttributeValue",
|
|
||||||
"type": "Type"
|
"type": "Type"
|
||||||
},
|
},
|
||||||
"organizationunit": {
|
"organizationunit": {
|
||||||
|
|||||||
@ -124,7 +124,6 @@
|
|||||||
"status": "状态",
|
"status": "状态",
|
||||||
"description": "描述",
|
"description": "描述",
|
||||||
"extendedAttribute": "扩展属性",
|
"extendedAttribute": "扩展属性",
|
||||||
"extendedAttributeValue": "扩展属性值",
|
|
||||||
"type": "字典类型"
|
"type": "字典类型"
|
||||||
},
|
},
|
||||||
"organizationunit": {
|
"organizationunit": {
|
||||||
|
|||||||
@ -148,16 +148,16 @@ const allColumns = computed(() => {
|
|||||||
if (!isGridInitialized.value) {
|
if (!isGridInitialized.value) {
|
||||||
const baseColumns = [...fixedBaseColumns];
|
const baseColumns = [...fixedBaseColumns];
|
||||||
if (showSubDeviceColumn.value) {
|
if (showSubDeviceColumn.value) {
|
||||||
baseColumns.push(subDeviceColumn);
|
baseColumns.push(subDeviceColumn, dataTypeColumn);
|
||||||
}
|
}
|
||||||
return baseColumns;
|
return baseColumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns = [...fixedBaseColumns];
|
const columns = [...fixedBaseColumns];
|
||||||
|
|
||||||
// 根据 DeviceType 控制 Sub_Device 列是否显示(DataType 始终隐藏)
|
// 根据 DeviceType 控制 Sub_Device、DataType 列是否显示
|
||||||
if (showSubDeviceColumn.value) {
|
if (showSubDeviceColumn.value) {
|
||||||
columns.push(subDeviceColumn);
|
columns.push(subDeviceColumn, dataTypeColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 安全地添加动态列
|
// 安全地添加动态列
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
@ -17,8 +17,19 @@ defineOptions({
|
|||||||
|
|
||||||
const emit = defineEmits(['reload']);
|
const emit = defineEmits(['reload']);
|
||||||
const data = ref<Record<string, any>>({});
|
const data = ref<Record<string, any>>({});
|
||||||
|
const [Form, formApi] = useVbenForm({
|
||||||
const formSchema = computed(() => [
|
// 所有表单项共用,可单独在表单内覆盖
|
||||||
|
commonConfig: {
|
||||||
|
// 所有表单项
|
||||||
|
componentProps: {
|
||||||
|
class: 'w-full',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
showDefaultActions: false,
|
||||||
|
// 垂直布局,label和input在不同行,值为vertical
|
||||||
|
// 水平布局,label和input在同一行
|
||||||
|
layout: 'horizontal',
|
||||||
|
schema: [
|
||||||
{
|
{
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
@ -28,11 +39,15 @@ const formSchema = computed(() => [
|
|||||||
label: $t('abp.dataDictionary.type'),
|
label: $t('abp.dataDictionary.type'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
// 组件需要在 #/adapter.ts内注册,并加上类型
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
// 对应组件的参数
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: $t('common.pleaseInput'),
|
placeholder: $t('common.pleaseInput'),
|
||||||
},
|
},
|
||||||
|
// 字段名
|
||||||
fieldName: 'code',
|
fieldName: 'code',
|
||||||
|
// 界面显示的label
|
||||||
label: $t('abp.dataDictionary.code'),
|
label: $t('abp.dataDictionary.code'),
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
@ -72,15 +87,19 @@ const formSchema = computed(() => [
|
|||||||
$t('common.pleaseSelect') +
|
$t('common.pleaseSelect') +
|
||||||
$t('abp.dataDictionary.extendedAttribute'),
|
$t('abp.dataDictionary.extendedAttribute'),
|
||||||
afterFetch: (res: any) => {
|
afterFetch: (res: any) => {
|
||||||
|
// 确保返回的是数组格式
|
||||||
if (Array.isArray(res)) {
|
if (Array.isArray(res)) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
// 如果是包装在 items 中的,提取出来
|
||||||
if (res && Array.isArray(res.items)) {
|
if (res && Array.isArray(res.items)) {
|
||||||
return res.items;
|
return res.items;
|
||||||
}
|
}
|
||||||
|
// 如果是包装在 data 中的,提取出来
|
||||||
if (res && Array.isArray(res.data)) {
|
if (res && Array.isArray(res.data)) {
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
// 如果都不是,返回空数组
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -88,16 +107,6 @@ const formSchema = computed(() => [
|
|||||||
label: $t('abp.dataDictionary.extendedAttribute'),
|
label: $t('abp.dataDictionary.extendedAttribute'),
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
component: 'Textarea',
|
|
||||||
componentProps: {
|
|
||||||
placeholder: '{"InputData":[],"OutputData":[]}',
|
|
||||||
rows: 6,
|
|
||||||
},
|
|
||||||
fieldName: 'extendedAttributeValue',
|
|
||||||
label: $t('abp.dataDictionary.extendedAttributeValue'),
|
|
||||||
defaultValue: '',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
component: 'Textarea',
|
component: 'Textarea',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
@ -106,54 +115,17 @@ const formSchema = computed(() => [
|
|||||||
fieldName: 'description',
|
fieldName: 'description',
|
||||||
label: $t('abp.dataDictionary.description'),
|
label: $t('abp.dataDictionary.description'),
|
||||||
},
|
},
|
||||||
]);
|
],
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
|
||||||
commonConfig: {
|
|
||||||
componentProps: {
|
|
||||||
class: 'w-full',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
showDefaultActions: false,
|
|
||||||
layout: 'horizontal',
|
|
||||||
schema: formSchema.value,
|
|
||||||
wrapperClass: 'grid-cols-1',
|
wrapperClass: 'grid-cols-1',
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatExtendedAttributeValue(value: any): string {
|
|
||||||
if (!value) return '';
|
|
||||||
if (typeof value === 'string') {
|
|
||||||
try {
|
|
||||||
JSON.parse(value);
|
|
||||||
return value;
|
|
||||||
} catch {
|
|
||||||
return JSON.stringify(value, null, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return JSON.stringify(value, null, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseExtendedAttributeValue(value: string): any {
|
|
||||||
if (!value || value.trim() === '') return undefined;
|
|
||||||
try {
|
|
||||||
return JSON.parse(value);
|
|
||||||
} catch {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
onOpenChange(isOpen: boolean) {
|
onOpenChange(isOpen: boolean) {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
data.value = modalApi.getData<Record<string, any>>();
|
data.value = modalApi.getData<Record<string, any>>();
|
||||||
if (data.value.isEdit) {
|
if (data.value.isEdit) {
|
||||||
const row = data.value.row;
|
|
||||||
formApi.setValues({
|
formApi.setValues({
|
||||||
...row,
|
...data.value.row,
|
||||||
typeDisplayText: data.value.type,
|
typeDisplayText: data.value.type,
|
||||||
extendedAttributeValue: formatExtendedAttributeValue(
|
|
||||||
row.extendedAttributeValue,
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
formApi.setValues({ typeDisplayText: data.value.type });
|
formApi.setValues({ typeDisplayText: data.value.type });
|
||||||
@ -166,24 +138,16 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
const values = await formApi.getValues();
|
const values = await formApi.getValues();
|
||||||
|
|
||||||
const submitData: Record<string, any> = {
|
|
||||||
...values,
|
|
||||||
extendedAttributeValue: parseExtendedAttributeValue(
|
|
||||||
values.extendedAttributeValue,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
await (data.value.isEdit
|
await (data.value.isEdit
|
||||||
? postDataDictionaryUpdateDetail({
|
? postDataDictionaryUpdateDetail({
|
||||||
body: {
|
body: {
|
||||||
...submitData,
|
...values,
|
||||||
id: data.value.row.id,
|
id: data.value.row.id,
|
||||||
dataDictionaryId: data.value.id,
|
dataDictionaryId: data.value.id,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
: postDataDictionaryCreateDetail({
|
: postDataDictionaryCreateDetail({
|
||||||
body: { ...submitData, id: data.value.id },
|
body: { ...values, id: data.value.id },
|
||||||
}));
|
}));
|
||||||
emit('reload');
|
emit('reload');
|
||||||
modalApi.close();
|
modalApi.close();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user