feat(client): display option value

This commit is contained in:
chenos 2022-06-20 11:57:30 +08:00
parent 9b6c2ff7ec
commit 2b0c7384f2
3 changed files with 40 additions and 32 deletions

View File

@ -90,35 +90,35 @@ const useCreateCollectionField = () => {
return {
async run() {
await form.submit();
const options = form?.values?.uiSchema?.enum?.slice() || [];
if (options?.length) {
form.setValuesIn(
'uiSchema.enum',
options.map((option) => {
return {
value: uid(),
...option,
};
}),
);
}
function recursiveChildren(children = [], prefix = 'children') {
children.forEach((item, index) => {
const itemOptions = item.uiSchema?.enum?.slice() || [];
form.setValuesIn(
`${prefix}[${index}].uiSchema.enum`,
itemOptions.map((option) => {
return {
value: uid(),
...option,
};
}),
);
recursiveChildren(item.children, `${prefix}[${index}].children`);
});
}
// const options = form?.values?.uiSchema?.enum?.slice() || [];
// if (options?.length) {
// form.setValuesIn(
// 'uiSchema.enum',
// options.map((option) => {
// return {
// value: uid(),
// ...option,
// };
// }),
// );
// }
// function recursiveChildren(children = [], prefix = 'children') {
// children.forEach((item, index) => {
// const itemOptions = item.uiSchema?.enum?.slice() || [];
// form.setValuesIn(
// `${prefix}[${index}].uiSchema.enum`,
// itemOptions.map((option) => {
// return {
// value: uid(),
// ...option,
// };
// }),
// );
// recursiveChildren(item.children, `${prefix}[${index}].children`);
// });
// }
recursiveChildren(form?.values?.children);
// recursiveChildren(form?.values?.children);
if (['obo', 'oho', 'o2o', 'o2m', 'm2o', 'm2m', 'linkTo'].includes(form?.values?.interface) && title) {
form.setValuesIn('reverseField.uiSchema.title', title);

View File

@ -1,5 +1,6 @@
import { Field } from '@formily/core';
import { ISchema } from '@formily/react';
import { uid } from '@formily/shared';
export * as operators from './operators';
export const type: ISchema = {
@ -29,7 +30,7 @@ export const type: ISchema = {
],
};
export const relationshipType: ISchema ={
export const relationshipType: ISchema = {
type: 'string',
title: '{{t("Relationship type")}}',
required: true,
@ -127,12 +128,18 @@ export const dataSource: ISchema = {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': { title: '{{t("Option value")}}' },
'x-hidden': true,
// 'x-hidden': true,
properties: {
value: {
type: 'string',
required: true,
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-reactions': (field: Field) => {
if (!field.initialValue) {
field.initialValue = uid();
}
},
},
},
},
@ -143,6 +150,7 @@ export const dataSource: ISchema = {
properties: {
label: {
type: 'string',
required: true,
'x-decorator': 'FormItem',
'x-component': 'Input',
},

View File

@ -255,7 +255,7 @@ export default {
"Options": "选项",
"Option value": "选项值",
"Option label": "选项",
"Option label": "选项标签",
"Color": "颜色",
"Add option": "添加选项",
"Related collection": "关系表",