From 95e4e7e7b03718debbcb25f92eac1a495a45c784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rairn?= <958414905@qq.com> Date: Wed, 26 Apr 2023 09:56:25 +0800 Subject: [PATCH] fix(variable-input): fix style (#1761) * fix(variable-input): fix style * refactor: avoid lint error * feat: add invariable * fix: fix the default value variable of the expression is empty --- .../collection-manager/interfaces/linkTo.ts | 1 + .../src/collection-manager/interfaces/m2m.tsx | 1 + .../src/collection-manager/interfaces/m2o.tsx | 1 + .../src/collection-manager/interfaces/o2m.tsx | 1 + .../src/collection-manager/interfaces/o2o.tsx | 3 + .../collection-manager/interfaces/types.ts | 2 + .../antd/form-item/FormItem.tsx | 18 +- .../schema-component/antd/variable/Input.tsx | 161 +++++++++--------- .../antd/variable/Variable.tsx | 7 +- .../VariableInput/VariableInput.tsx | 9 +- .../client/components/DynamicExpression.tsx | 13 +- .../src/client/interfaces/expression.tsx | 1 + 12 files changed, 126 insertions(+), 92 deletions(-) diff --git a/packages/core/client/src/collection-manager/interfaces/linkTo.ts b/packages/core/client/src/collection-manager/interfaces/linkTo.ts index 58ccf3d55d..94d459b28a 100644 --- a/packages/core/client/src/collection-manager/interfaces/linkTo.ts +++ b/packages/core/client/src/collection-manager/interfaces/linkTo.ts @@ -175,4 +175,5 @@ export const linkTo: IField = { // }, ], }, + invariable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/m2m.tsx b/packages/core/client/src/collection-manager/interfaces/m2m.tsx index 9e35b7327c..d8ca366b89 100644 --- a/packages/core/client/src/collection-manager/interfaces/m2m.tsx +++ b/packages/core/client/src/collection-manager/interfaces/m2m.tsx @@ -282,4 +282,5 @@ export const m2m: IField = { // }, ], }, + invariable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/m2o.tsx b/packages/core/client/src/collection-manager/interfaces/m2o.tsx index d4319ad9cd..9b3c8d193f 100644 --- a/packages/core/client/src/collection-manager/interfaces/m2o.tsx +++ b/packages/core/client/src/collection-manager/interfaces/m2o.tsx @@ -214,4 +214,5 @@ export const m2o: IField = { // }, ], }, + invariable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/o2m.tsx b/packages/core/client/src/collection-manager/interfaces/o2m.tsx index ab5a058a1e..32b6df46bf 100644 --- a/packages/core/client/src/collection-manager/interfaces/o2m.tsx +++ b/packages/core/client/src/collection-manager/interfaces/o2m.tsx @@ -273,4 +273,5 @@ export const o2m: IField = { // }, ], }, + invariable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/o2o.tsx b/packages/core/client/src/collection-manager/interfaces/o2o.tsx index 7d5fed65f7..6b2700e28b 100644 --- a/packages/core/client/src/collection-manager/interfaces/o2o.tsx +++ b/packages/core/client/src/collection-manager/interfaces/o2o.tsx @@ -252,6 +252,7 @@ export const o2o: IField = { // }, ], }, + invariable: true, }; export const oho: IField = { @@ -422,6 +423,7 @@ export const oho: IField = { // }, ], }, + invariable: true, }; export const obo: IField = { @@ -605,4 +607,5 @@ export const obo: IField = { // }, ], }, + invariable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/types.ts b/packages/core/client/src/collection-manager/interfaces/types.ts index 48245011ea..c2fbb51b34 100644 --- a/packages/core/client/src/collection-manager/interfaces/types.ts +++ b/packages/core/client/src/collection-manager/interfaces/types.ts @@ -10,5 +10,7 @@ export interface IField extends ISchema { default?: IDefault; operators?: any[]; filterable?: any; + /** 不支持使用变量的值进行设置 */ + invariable?: boolean; [key: string]: any; } diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx index b4d8499478..136a513356 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx @@ -18,9 +18,16 @@ import { SchemaComponent } from '../../core'; import { useCompile, useDesignable, useFieldComponentOptions } from '../../hooks'; import { BlockItem } from '../block-item'; import { HTMLEncode } from '../input/shared'; +import { isInvariable } from '../variable'; import { FilterFormDesigner } from './FormItem.FilterFormDesigner'; import { useEnsureOperatorsValid } from './SchemaSettingOptions'; +const defaultInputStyle = css` + & > .nb-form-item { + flex: 1; + } +`; + const divWrap = (schema: ISchema) => { return { type: 'void', @@ -420,8 +427,7 @@ FormItem.Designer = function Designer() { type: 'object', title: t('Set default value'), properties: { - // 关系字段不支持设置变量 - default: collectionField?.target + default: isInvariable(interfaceConfig) ? { ...(fieldSchema || {}), 'x-decorator': 'FormItem', @@ -434,6 +440,12 @@ FormItem.Designer = function Designer() { service: { resource: collectionField?.target, }, + // for DynamicExpression + sourceCollection: form?.values.sourceCollection, + style: { + width: '100%', + verticalAlign: 'top', + }, }, name: 'default', title: t('Default value'), @@ -447,6 +459,7 @@ FormItem.Designer = function Designer() { ...(fieldSchema?.['x-component-props'] || {}), collectionName: collectionField?.collectionName, schema: collectionField?.uiSchema, + className: defaultInputStyle, renderSchemaComponent: function Com(props) { const s = _.cloneDeep(fieldSchema) || ({} as Schema); s.title = ''; @@ -464,6 +477,7 @@ FormItem.Designer = function Designer() { defaultValue: getFieldDefaultValue(s, collectionField), style: { width: '100%', + verticalAlign: 'top', }, }, }} diff --git a/packages/core/client/src/schema-component/antd/variable/Input.tsx b/packages/core/client/src/schema-component/antd/variable/Input.tsx index 819d7f2d84..c007b4e32d 100644 --- a/packages/core/client/src/schema-component/antd/variable/Input.tsx +++ b/packages/core/client/src/schema-component/antd/variable/Input.tsx @@ -6,6 +6,7 @@ import moment from 'moment'; import React from 'react'; import { useTranslation } from 'react-i18next'; +import classNames from 'classnames'; import { useCompile } from '../..'; import { XButton } from './XButton'; @@ -51,7 +52,7 @@ const ConstantTypes = { boolean: { label: `{{t("Boolean")}}`, value: 'boolean', - component({ onChange, value }) { + component: function Com({ onChange, value }) { const { t } = useTranslation(); return (