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

View File

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

View File

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