Compare commits
2 Commits
62ce737dea
...
3648af31ab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3648af31ab | ||
|
|
893733d593 |
@ -131,6 +131,7 @@
|
|||||||
"status": "Status",
|
"status": "Status",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
"extendedAttribute": "ExtendedAttribute",
|
"extendedAttribute": "ExtendedAttribute",
|
||||||
|
"extendedAttributeValue": "ExtendedAttributeValue",
|
||||||
"type": "Type"
|
"type": "Type"
|
||||||
},
|
},
|
||||||
"organizationunit": {
|
"organizationunit": {
|
||||||
|
|||||||
@ -124,6 +124,7 @@
|
|||||||
"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, dataTypeColumn);
|
baseColumns.push(subDeviceColumn);
|
||||||
}
|
}
|
||||||
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, dataTypeColumn);
|
columns.push(subDeviceColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 安全地添加动态列
|
// 安全地添加动态列
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
@ -17,115 +17,143 @@ defineOptions({
|
|||||||
|
|
||||||
const emit = defineEmits(['reload']);
|
const emit = defineEmits(['reload']);
|
||||||
const data = ref<Record<string, any>>({});
|
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({
|
const [Form, formApi] = useVbenForm({
|
||||||
// 所有表单项共用,可单独在表单内覆盖
|
|
||||||
commonConfig: {
|
commonConfig: {
|
||||||
// 所有表单项
|
|
||||||
componentProps: {
|
componentProps: {
|
||||||
class: 'w-full',
|
class: 'w-full',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
// 垂直布局,label和input在不同行,值为vertical
|
|
||||||
// 水平布局,label和input在同一行
|
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
schema: [
|
schema: formSchema.value,
|
||||||
{
|
|
||||||
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'),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
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({
|
||||||
...data.value.row,
|
...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 });
|
||||||
@ -138,17 +166,25 @@ 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: {
|
||||||
...values,
|
...submitData,
|
||||||
id: data.value.row.id,
|
id: data.value.row.id,
|
||||||
dataDictionaryId: data.value.id,
|
dataDictionaryId: data.value.id,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
: postDataDictionaryCreateDetail({
|
: postDataDictionaryCreateDetail({
|
||||||
body: { ...values, id: data.value.id },
|
body: { ...submitData, id: data.value.id },
|
||||||
}));
|
}));
|
||||||
emit('reload');
|
emit('reload');
|
||||||
modalApi.close();
|
modalApi.close();
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user