Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resetfidlds): 重置属性为初始状态 #2795

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/docs/api/configOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ config.set('enableCondition', false)
```typescript
focusNodeSelector?: (rootNode: IPublicModelNode) => Node;
```

#### supportResetGlobally - 设置所有属性支持重置
`@type {boolean}` `@default {false}`
设置所有属性支持重置, 开启后会给组件属性增加一个resetSetter,点击后会将组件的该属性重置为默认状态(defaultValue/initialValue)。如果没有设置默认值则回到该项属性不存在于props中的状态。不能重置成snippets中定义的低代码组件属性的值
#### supportVariableGlobally - 全局变量配置

`@type {boolean}` `@default {false}`
Expand Down
1 change: 1 addition & 0 deletions docs/docs/demoUsage/panels/datasource.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const preference = new Map();
enableCanvasLock: true,
// 默认绑定变量
supportVariableGlobally: true,
supportResetGlobally: true,
// simulatorUrl 在当 engine-core.js 同一个父路径下时是不需要配置的!!!
// 这里因为用的是 alifd cdn,在不同 npm 包,engine-core.js 和 react-simulator-renderer.js 是不同路径
simulatorUrl: [
Expand Down
1 change: 1 addition & 0 deletions docs/docs/specs/material-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ props 数组下对象字段描述:
| name | 属性名 | String | type = 'field' 生效 |
| defaultValue | 默认值 | Any(视字段类型而定) | type = 'field' 生效 |
| supportVariable | 是否支持配置变量 | Boolean | type = 'field' 生效 |
| supportReset | 是否支持配置重置属性 | Boolean | type = 'field' 生效 |
| condition | 配置当前 prop 是否展示 | (target: IPublicModelSettingField) => boolean; | - |
| ignoreDefaultValue | 配置当前 prop 是否忽略默认值处理逻辑,如果返回值是 true 引擎不会处理默认值 | (target: IPublicModelSettingField) => boolean; | - |
| setter | 单个控件 (setter) 描述,搭建基础协议组件的描述对象,支持 JSExpression / JSFunction / JSSlot | `String\|Object\|Function` | type = 'field' 生效 |
Expand Down
5 changes: 5 additions & 0 deletions packages/editor-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ const VALID_ENGINE_OPTIONS = {
default: false,
description: '设置所有属性支持变量配置',
},
supportResetGlobally: {
type: 'boolean',
default: false,
description: '设置所有属性支持重置',
},
visionSettings: {
type: 'object',
description: 'Vision-polyfill settings',
Expand Down
6 changes: 4 additions & 2 deletions packages/editor-skeleton/src/components/field/fields.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/no-unused-prop-types */
import { Component, ErrorInfo, MouseEvent } from 'react';
import { Component, ErrorInfo, MouseEvent, ReactNode } from 'react';
import { isObject } from 'lodash';
import classNames from 'classnames';
import { Icon } from '@alifd/next';
Expand All @@ -25,6 +25,7 @@ export interface FieldProps {
tip?: any;
onExpandChange?: (expandState: boolean) => void;
onClear?: () => void;
children: ReactNode;
}

export class Field extends Component<FieldProps> {
Expand Down Expand Up @@ -149,7 +150,8 @@ export class Field extends Component<FieldProps> {
return null;
}

const { className, children, meta, title, valueState, name: propName, tip } = this.props;
const { className, children, meta, title, valueState,
name: propName, tip } = this.props;
const { display, collapsed } = this.state;
const isAccordion = display === 'accordion';
let hostName = '';
Expand Down
3 changes: 3 additions & 0 deletions packages/editor-skeleton/src/components/field/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,7 @@
}
}
}
.lc-reseticon {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的类名在哪使用的?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个忘记删除了,,, 😰

cursor: pointer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,32 +151,32 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
}
}

// 根据是否支持reset做相应的更改
const supportReset = extraProps?.supportReset;
const supportResetGlobally = engineConfig.get('supportResetGlobally', false);
const isUseResetSetter = supportReset === false ? false :
supportReset || supportResetGlobally;

// 根据是否支持变量配置做相应的更改
const supportVariable = this.field.extraProps?.supportVariable;
// supportVariableGlobally 只对标准组件生效,vc 需要单独配置
const supportVariableGlobally = engineConfig.get('supportVariableGlobally', false) && isStandardComponent(componentMeta);
const isUseVariableSetter = shouldUseVariableSetter(supportVariable, supportVariableGlobally);
if (isUseVariableSetter === false) {
return {
setterProps,
initialValue,
setterType,
};
}
const shouldAddVariableSetter = isUseVariableSetter && !setterProps.setters?.includes('VariableSetter');
const shouldAddResetSetter = isUseResetSetter && !setterProps.setters?.includes('ResetSetter');

if (setterType === 'MixedSetter') {
// VariableSetter 不单独使用
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
if (shouldAddVariableSetter || shouldAddResetSetter) {
setterType = 'MixedSetter';
setterProps.setters = setterProps.setters || [];
setterProps.setters.push(setter);

if (shouldAddVariableSetter) {
setterProps.setters.push('VariableSetter');
}
} else {
setterType = 'MixedSetter';
setterProps = {
setters: [
setter,
'VariableSetter',
],
};

if (shouldAddResetSetter) {
setterProps.setters.push('ResetSetter');
}
}
return {
setterProps,
Expand Down Expand Up @@ -227,7 +227,6 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView

let _onChange = extraProps?.onChange;
let stageName = this.stageName;

return createField(
{
meta: field?.componentMeta?.npm || field?.componentMeta?.componentName || '',
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/shell/type/engine-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ export interface IPublicTypeEngineOptions {
*/
supportVariableGlobally?: boolean;

/**
* 设置所有属性支持重置,默认值:false
*
*/
supportResetGlobally?: boolean;

/**
* 设置 simulator 相关的 url,默认值:undefined
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/shell/type/field-extra-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export interface IPublicTypeFieldExtraProps {
*/
supportVariable?: boolean;

/**
* 是否支持重置变量
*/
supportReset?: boolean;

/**
* compatiable vision display
*/
Expand Down
Loading