Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import TextAreaSetter from './setter/textarea-setter';
import ArraySetter from './setter/array-setter';
import ObjectSetter from './setter/object-setter';
import VariableSetter from './setter/variable-setter';
import ResetSetter from './setter/reset-setter';
import TitleSetter from './setter/title-setter';
import EventBindDialog from './plugin/plugin-event-bind-dialog';
import VariableBindDialog from './plugin/plugin-variable-bind-dialog';
Expand Down Expand Up @@ -100,6 +101,11 @@ const DataVariableSetter = {
recommend: true,
};

const ResetSetterWrapper = {
component: ResetSetter,
title: '重置属性',
}

const FunctionBindSetter = {
component: FunctionSetter,
title: '函数绑定',
Expand Down Expand Up @@ -172,6 +178,7 @@ const engineExt = {
BoolSetter,
SelectSetter,
VariableSetter: DataVariableSetter,
ResetSetter: ResetSetterWrapper,
ExpressionSetter: DataExpressionSetter,
RadioGroupSetter,
TextAreaSetter,
Expand Down Expand Up @@ -201,6 +208,7 @@ const engineExt = {
BoolSetter,
SelectSetter,
VariableSetter: DataVariableSetter,
ResetSetter: ResetSetterWrapper,
ExpressionSetter: DataExpressionSetter,
RadioGroupSetter,
TextAreaSetter,
Expand Down
10 changes: 10 additions & 0 deletions src/setter/mixed-setter/icons/reset.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IconProps, SVGIcon } from '@alilc/lowcode-utils';

export function ResetIcon(props: IconProps) {
return (
<SVGIcon viewBox="0 0 1024 1024" {...props}>
<path d="M193.070545 70.353455l5.422546 0.930909A34.909091 34.909091 0 0 1 226.862545 111.709091l-0.023272 0.069818-12.869818 72.541091a448.698182 448.698182 0 0 1 293.888-108.939636c246.830545 0 447.022545 197.911273 447.022545 442.181818s-200.192 442.181818-447.022545 442.181818c-160.186182 0-305.687273-84.084364-385.466182-218.158545a37.794909 37.794909 0 0 1 13.358545-51.921455 38.167273 38.167273 0 0 1 52.154182 13.288727c66.210909 111.243636 186.903273 180.992 319.953455 180.992 204.869818 0 370.850909-164.096 370.850909-366.382545S712.727273 151.179636 507.857455 151.179636c-107.287273 0-206.801455 45.265455-276.317091 121.995637h141.498181a34.909091 34.909091 0 0 1 0 69.818182h-209.454545c-2.606545 0-5.189818-0.279273-7.656727-0.837819a34.629818 34.629818 0 0 1-5.259637-0.512l-5.422545-0.930909a34.909091 34.909091 0 0 1-28.346182-40.494545L152.669091 98.629818a34.909091 34.909091 0 0 1 40.401454-28.276363z" />
</SVGIcon>
);
}
ResetIcon.displayName = 'Reset';
4 changes: 4 additions & 0 deletions src/setter/mixed-setter/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@
transform: none;
}
}

.lc-setter-mixed.lc-setter-mixeds {
margin-right: 46px;
}
122 changes: 119 additions & 3 deletions src/setter/mixed-setter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { intlNode } from './locale';

import './index.less';
import { IconVariable } from './icons/variable';
import { ResetIcon } from './icons/reset';

const { editorCabin } = common;
const { computed, obx, Title, createSetterContent, observer, shallowIntl } = editorCabin;
Expand Down Expand Up @@ -183,6 +184,7 @@ export default class MixedSetter extends Component<{
firstMatched = setter;
}
}
this.used = (firstMatched || firstDefault || this.setters[0]).name;
return firstMatched || firstDefault || this.setters[0];
}

Expand All @@ -198,6 +200,8 @@ export default class MixedSetter extends Component<{
// dirty fix vision variable setter logic
private hasVariableSetter = this.setters.some((item) => item.name === 'VariableSetter');

private hasResetSetter = this.setters.some((item) => item.name === 'ResetSetter');

private useSetter = (name: string, usedName: string) => {
this.fromMixedSetterSelect = true;
const { field } = this.props;
Expand Down Expand Up @@ -403,6 +407,84 @@ export default class MixedSetter extends Component<{
};
}

// 有resetSetter的处理
private contentsFromPolyfill2() {
const { field } = this.props;

const n = this.setters.length;

let setterContent: any;
let actions: any;
if (n < 3) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这块的逻辑,可以在PR里面补充一些截图吗?我想看看交互/逻辑上要不要优化。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ResetSetter不会单独存在,两个setter的时候resetset在最后面。大于两个了前面是切换setter后面是resetsetter
image
一开始想把resetsetter合到切换setter中,但是重置的时候使用不方便,但是放两个图标有的不开启resetsetter又不太好看

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

都超过2个了这种ui看着还凑合
image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

image

这种场景下展示的效果呢?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

另外,这里没有重置按钮吗?

image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

我么有开启全局resetsetter,这个属性也没有配置resetsetter

可以开启全局,我看一下这里的效果。

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

之前那个截图就是开启了全局的
image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

开启全局会影响这个地方吗?

image

image

我觉得不影响比较好。重置的时候,清空变量绑定,并将值还原。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

嗯,那就按你说的这个逻辑我改一下。在有三个setter并且有variable和reset setter时,最后一个位置放resetsetter,倒数第二个放variableSetter。如果没有variableSetter第二个位置就是switchAction。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

如果没有variableSetter,就直接放 reset setter 就好。

const tipContent = field.isUseVariable()
? intlNode('Binded: {expr}', { expr: field.getValue()?.value })
: intlNode('Variable Binding');
if (n === 1) {
// 只有一个resetSetter,在actions中展示
} else if (n === 2) {
// =2: 另外一个 Setter 原地展示,如果是 VariableSetter 点击弹出调用 VariableSetter.show
const otherSetter = this.setters.find((item) => item.name !== 'ResetSetter')!;
if (otherSetter.name === 'VariableSetter') {
const variableSetterComponent = getSetter('VariableSetter')?.component as any;
setterContent = (
<a
onClick={() => {
variableSetterComponent.show({ prop: field });
}}
>
{tipContent}
</a>
)
this.used = 'VariableSetter';
} else {
setterContent = this.renderCurrentSetter(otherSetter, {
value: field.getMockOrValue(),
});
}
}
actions = this.handleResetSetterAction();
} else {
// >=3: 原地展示当前 setter<当前绑定的值,点击调用 VariableSetter.show>,icon tip 提示绑定的值,点击展示切换 Setter,点击其它 setter 直接切换,点击 Variable Setter-> VariableSetter.show
// 点击resetSetter 重置属性
const currentSetter =
!this.used && field.isUseVariable()
? this.setters.find((item) => item.name === 'VariableSetter')
: this.getCurrentSetter();
if (currentSetter?.name === 'VariableSetter') {
const variableSetterComponent = getSetter('VariableSetter')?.component as any;
setterContent = (
<a
onClick={() => {
variableSetterComponent.show({ prop: field });
}}
>
{intlNode('Binded: {expr}', { expr: field.getValue()?.value })}
</a>
);
} else {
setterContent = this.renderCurrentSetter(currentSetter);
}
actions = this.renderSwitchAction(currentSetter);
// 添加resetSetter
const resetAction = this.handleResetSetterAction();
actions = (<>{actions}{resetAction}</>)
}

return {
setterContent,
actions,
};
}


private getClassName() {
const n = this.setters.length;
if (this.hasResetSetter && n > 2) {
// 通过class来修改样式
return 'lc-setter-mixeds';
}
}

private renderSwitchAction(currentSetter?: SetterItem) {
const usedName = currentSetter?.name || this.used;
const triggerNode = (
Expand All @@ -424,7 +506,7 @@ export default class MixedSetter extends Component<{
onItemClick={(name) => this.useSetter(name, usedName)}
>
{this.setters
.filter((setter) => setter.list || setter.name === usedName)
.filter((setter) => (setter.list || setter.name === usedName) && setter.name!== 'ResetSetter')
.map((setter) => {
return (
<Menu.Item key={setter.name}>
Expand All @@ -437,6 +519,38 @@ export default class MixedSetter extends Component<{
);
}

private handleResetSetterAction() {
return (<Title
title={{
icon: <ResetIcon size={24} />,
tip: intlNode('Reset Attribute'),
}}
onClick={() => this.resetClickHandler()}
/>)
}

resetClickHandler() {
const { onChange, initialValue, field } = this.props;
let newValue = initialValue;
if (this.used === 'VariableSetter') {
const fieldValue = field.getValue();
const value =
Object.prototype.toString.call(fieldValue) === '[object Object]'
? fieldValue.mock
: fieldValue;
// 清除变量绑定
field.setValue(value);
// 清除标记
this.used = undefined;
newValue = newValue??value;
}
// fixme 属性为children默认使用StringSetter并且不配置defaultValue时,onChange(null)画布不会更新,so做此处理。例如antd物料的button组件
if (this.used === 'StringSetter') {
newValue = newValue?? '';
}
onChange(newValue)
}

render() {
const { className } = this.props;
let contents:
Expand All @@ -446,7 +560,9 @@ export default class MixedSetter extends Component<{
}
| undefined;

if (this.hasVariableSetter) {
if (this.hasResetSetter) {
contents = this.contentsFromPolyfill2();
} else if (this.hasVariableSetter) {
// polyfill vision variable setter logic
const setterComponent = getSetter('VariableSetter')?.component as any;
if (setterComponent && setterComponent.isPopup) {
Expand All @@ -466,7 +582,7 @@ export default class MixedSetter extends Component<{
ref={(shell) => {
this.shell = shell;
}}
className={classNames('lc-setter-mixed', className)}
className={classNames('lc-setter-mixed', className, this.getClassName())}
>
{contents.setterContent}
<div className="lc-setter-actions">{contents.actions}</div>
Expand Down
3 changes: 2 additions & 1 deletion src/setter/mixed-setter/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Multiple Value, Click to Clear": "Multiple Value, Click to Clear",
"Required": "Required",
"Setted Value, Click to Clear": "Setted Value, Click to Clear",
"Multiple Value": "Multiple Value"
"Multiple Value": "Multiple Value",
"Reset Attribute": "Reset Attribute"
}
3 changes: 2 additions & 1 deletion src/setter/mixed-setter/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Multiple Value, Click to Clear": "多种值, 点击清除",
"Required": "必填项",
"Setted Value, Click to Clear": "已设置值,点击清除",
"Multiple Value": "多种值"
"Multiple Value": "多种值",
"Reset Attribute": "重置属性"
}
1 change: 1 addition & 0 deletions src/setter/reset-setter/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* write style here */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个文件是不是可以删掉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

可以删除的,我把他和variable-setter的一块删除了吧

15 changes: 15 additions & 0 deletions src/setter/reset-setter/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { PureComponent } from 'react';
import './index.less';
import { intlNode } from '../mixed-setter/locale';

export default class SetterReset extends PureComponent {
static displayName = 'ResetSetter';
static isPopup = true;

render() {
const tipContext = intlNode('Reset Attribute');

// return <a onClick={ this.resetIconClickHandler }> {tipContext} </a>;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里的注释去掉。

return <a > {tipContext} </a>;
}
}
10 changes: 10 additions & 0 deletions src/setter/reset-setter/resetIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IconProps, SVGIcon } from '@alilc/lowcode-utils';

export function ResetIcon(props: IconProps) {
return (
<SVGIcon viewBox="0 0 1024 1024" {...props}>
<path d="M193.070545 70.353455l5.422546 0.930909A34.909091 34.909091 0 0 1 226.862545 111.709091l-0.023272 0.069818-12.869818 72.541091a448.698182 448.698182 0 0 1 293.888-108.939636c246.830545 0 447.022545 197.911273 447.022545 442.181818s-200.192 442.181818-447.022545 442.181818c-160.186182 0-305.687273-84.084364-385.466182-218.158545a37.794909 37.794909 0 0 1 13.358545-51.921455 38.167273 38.167273 0 0 1 52.154182 13.288727c66.210909 111.243636 186.903273 180.992 319.953455 180.992 204.869818 0 370.850909-164.096 370.850909-366.382545S712.727273 151.179636 507.857455 151.179636c-107.287273 0-206.801455 45.265455-276.317091 121.995637h141.498181a34.909091 34.909091 0 0 1 0 69.818182h-209.454545c-2.606545 0-5.189818-0.279273-7.656727-0.837819a34.629818 34.629818 0 0 1-5.259637-0.512l-5.422545-0.930909a34.909091 34.909091 0 0 1-28.346182-40.494545L152.669091 98.629818a34.909091 34.909091 0 0 1 40.401454-28.276363z" />
</SVGIcon>
);
}
ResetIcon.displayName = 'Reset';