完善字典明细新增与修改

This commit is contained in:
ChenYi 2026-04-29 10:45:33 +08:00
parent 893733d593
commit 3648af31ab
3 changed files with 139 additions and 101 deletions

View File

@ -131,6 +131,7 @@
"status": "Status",
"description": "Description",
"extendedAttribute": "ExtendedAttribute",
"extendedAttributeValue": "ExtendedAttributeValue",
"type": "Type"
},
"organizationunit": {

View File

@ -124,6 +124,7 @@
"status": "状态",
"description": "描述",
"extendedAttribute": "扩展属性",
"extendedAttributeValue": "扩展属性值",
"type": "字典类型"
},
"organizationunit": {

View File

@ -1,5 +1,5 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
@ -17,115 +17,143 @@ defineOptions({
const emit = defineEmits(['reload']);
const data = ref<Record<string, any>>({});
const formSchema = computed(() => [
{
component: 'Input',
componentProps: {
disabled: true,
},
fieldName: 'typeDisplayText',
label: $t('abp.dataDictionary.type'),
},
{
component: 'Input',
componentProps: {
placeholder: $t('common.pleaseInput'),
},
fieldName: 'code',
label: $t('abp.dataDictionary.code'),
rules: 'required',
},
{
component: 'Input',
componentProps: {
placeholder: $t('common.pleaseInput'),
},
fieldName: 'displayText',
label: $t('abp.dataDictionary.name'),
rules: 'required',
},
{
component: 'Input',
componentProps: {
placeholder: $t('common.pleaseInput'),
},
fieldName: 'order',
label: $t('abp.dataDictionary.order'),
rules: 'required',
},
{
component: 'ApiSelect',
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'StandardThingModelDataTypeEnum',
},
},
labelField: 'value',
valueField: 'secondValue',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder:
$t('common.pleaseSelect') +
$t('abp.dataDictionary.extendedAttribute'),
afterFetch: (res: any) => {
if (Array.isArray(res)) {
return res;
}
if (res && Array.isArray(res.items)) {
return res.items;
}
if (res && Array.isArray(res.data)) {
return res.data;
}
return [];
},
},
fieldName: 'extendedAttribute',
label: $t('abp.dataDictionary.extendedAttribute'),
rules: 'required',
},
{
component: 'Textarea',
componentProps: {
placeholder: '{"InputData":[],"OutputData":[]}',
rows: 6,
},
fieldName: 'extendedAttributeValue',
label: $t('abp.dataDictionary.extendedAttributeValue'),
defaultValue: '',
},
{
component: 'Textarea',
componentProps: {
placeholder: $t('common.pleaseInput'),
},
fieldName: 'description',
label: $t('abp.dataDictionary.description'),
},
]);
const [Form, formApi] = useVbenForm({
//
commonConfig: {
//
componentProps: {
class: 'w-full',
},
},
showDefaultActions: false,
// labelinputvertical
// labelinput
layout: 'horizontal',
schema: [
{
component: 'Input',
componentProps: {
disabled: true,
},
fieldName: 'typeDisplayText',
label: $t('abp.dataDictionary.type'),
},
{
// #/adapter.ts
component: 'Input',
//
componentProps: {
placeholder: $t('common.pleaseInput'),
},
//
fieldName: 'code',
// label
label: $t('abp.dataDictionary.code'),
rules: 'required',
},
{
component: 'Input',
componentProps: {
placeholder: $t('common.pleaseInput'),
},
fieldName: 'displayText',
label: $t('abp.dataDictionary.name'),
rules: 'required',
},
{
component: 'Input',
componentProps: {
placeholder: $t('common.pleaseInput'),
},
fieldName: 'order',
label: $t('abp.dataDictionary.order'),
rules: 'required',
},
{
component: 'ApiSelect',
componentProps: {
api: getCommonGetSelectList,
params: {
query: {
typeName: 'StandardThingModelDataTypeEnum',
},
},
labelField: 'value',
valueField: 'secondValue',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder:
$t('common.pleaseSelect') +
$t('abp.dataDictionary.extendedAttribute'),
afterFetch: (res: any) => {
//
if (Array.isArray(res)) {
return res;
}
// items
if (res && Array.isArray(res.items)) {
return res.items;
}
// data
if (res && Array.isArray(res.data)) {
return res.data;
}
//
return [];
},
},
fieldName: 'extendedAttribute',
label: $t('abp.dataDictionary.extendedAttribute'),
rules: 'required',
},
{
component: 'Textarea',
componentProps: {
placeholder: $t('common.pleaseInput'),
},
fieldName: 'description',
label: $t('abp.dataDictionary.description'),
},
],
schema: formSchema.value,
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({
onOpenChange(isOpen: boolean) {
if (isOpen) {
data.value = modalApi.getData<Record<string, any>>();
if (data.value.isEdit) {
const row = data.value.row;
formApi.setValues({
...data.value.row,
...row,
typeDisplayText: data.value.type,
extendedAttributeValue: formatExtendedAttributeValue(
row.extendedAttributeValue,
),
});
} else {
formApi.setValues({ typeDisplayText: data.value.type });
@ -138,17 +166,25 @@ const [Modal, modalApi] = useVbenModal({
const { valid } = await formApi.validate();
if (!valid) return;
const values = await formApi.getValues();
const submitData: Record<string, any> = {
...values,
extendedAttributeValue: parseExtendedAttributeValue(
values.extendedAttributeValue,
),
};
await (data.value.isEdit
? postDataDictionaryUpdateDetail({
body: {
...values,
id: data.value.row.id,
dataDictionaryId: data.value.id,
},
})
body: {
...submitData,
id: data.value.row.id,
dataDictionaryId: data.value.id,
},
})
: postDataDictionaryCreateDetail({
body: { ...values, id: data.value.id },
}));
body: { ...submitData, id: data.value.id },
}));
emit('reload');
modalApi.close();
} finally {