mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-15 10:48:17 +00:00
style: eslint
This commit is contained in:
parent
1862b5564f
commit
b0a4dca3bf
@ -1,10 +1,10 @@
|
|||||||
import { Component, isValidElement, ReactElement, ReactNode } from 'react';
|
import { Component } from 'react';
|
||||||
import { Radio, Menu, Table, Icon, Dialog } from '@alifd/next';
|
import { Radio, Menu, Table, Icon } from '@alifd/next';
|
||||||
import nativeEvents from './native-events';
|
import nativeEvents from './native-events';
|
||||||
|
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
const { SubMenu, Item, Group, Divider } = Menu;
|
const { Item, Group } = Menu;
|
||||||
const RadioGroup = Radio.Group;
|
const RadioGroup = Radio.Group;
|
||||||
|
|
||||||
const EVENT_CONTENTS = {
|
const EVENT_CONTENTS = {
|
||||||
@ -26,14 +26,12 @@ export default class EventsSetter extends Component<{
|
|||||||
onChange: (eventList: any[]) => void;
|
onChange: (eventList: any[]) => void;
|
||||||
}> {
|
}> {
|
||||||
state = {
|
state = {
|
||||||
showEventList: false,
|
|
||||||
eventBtns: [],
|
eventBtns: [],
|
||||||
eventList: [],
|
eventList: [],
|
||||||
selectType: null,
|
selectType: null,
|
||||||
nativeEventList: [],
|
nativeEventList: [],
|
||||||
lifeCycleEventList: [],
|
lifeCycleEventList: [],
|
||||||
eventDataList: (this.props?.value?.eventDataList ? this.props.value.eventDataList : this.props?.value) || [],
|
eventDataList: (this.props?.value?.eventDataList ? this.props.value.eventDataList : this.props?.value) || [],
|
||||||
relatedEventName: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructor (){
|
// constructor (){
|
||||||
@ -87,6 +85,8 @@ export default class EventsSetter extends Component<{
|
|||||||
if (item.type === DEFINITION_EVENT_TYPE.EVENTS) {
|
if (item.type === DEFINITION_EVENT_TYPE.EVENTS) {
|
||||||
isCustom = true;
|
isCustom = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isRoot) {
|
if (isRoot) {
|
||||||
@ -145,6 +145,8 @@ export default class EventsSetter extends Component<{
|
|||||||
lifeCycleEventList: item.list,
|
lifeCycleEventList: item.list,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (nativeEventList.length == 0) {
|
if (nativeEventList.length == 0) {
|
||||||
@ -167,7 +169,11 @@ export default class EventsSetter extends Component<{
|
|||||||
if (item.name === eventDataItem.name) {
|
if (item.name === eventDataItem.name) {
|
||||||
item.disabled = true;
|
item.disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return eventDataItem;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
} else if (eventType === DEFINITION_EVENT_TYPE.NATIVE_EVENTS) {
|
} else if (eventType === DEFINITION_EVENT_TYPE.NATIVE_EVENTS) {
|
||||||
eventDataList.map(eventDataItem => {
|
eventDataList.map(eventDataItem => {
|
||||||
@ -178,8 +184,12 @@ export default class EventsSetter extends Component<{
|
|||||||
} else {
|
} else {
|
||||||
item.disabled = false;
|
item.disabled = false;
|
||||||
}
|
}
|
||||||
|
return eventItem;
|
||||||
});
|
});
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return eventDataItem;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -239,12 +249,14 @@ export default class EventsSetter extends Component<{
|
|||||||
if (item.name === eventName) {
|
if (item.name === eventName) {
|
||||||
item.disabled = !unDisabled;
|
item.disabled = !unDisabled;
|
||||||
}
|
}
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
lifeCycleEventList.map(item => {
|
lifeCycleEventList.map(item => {
|
||||||
if (item.name === eventName) {
|
if (item.name === eventName) {
|
||||||
item.disabled = !unDisabled;
|
item.disabled = !unDisabled;
|
||||||
}
|
}
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
nativeEventList.map(item => {
|
nativeEventList.map(item => {
|
||||||
@ -252,7 +264,10 @@ export default class EventsSetter extends Component<{
|
|||||||
if (itemData.name === eventName) {
|
if (itemData.name === eventName) {
|
||||||
itemData.disabled = !unDisabled;
|
itemData.disabled = !unDisabled;
|
||||||
}
|
}
|
||||||
|
return itemData;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -319,6 +334,8 @@ export default class EventsSetter extends Component<{
|
|||||||
if (item.name === eventName) {
|
if (item.name === eventName) {
|
||||||
eventDataList.splice(index, 1);
|
eventDataList.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -336,6 +353,7 @@ export default class EventsSetter extends Component<{
|
|||||||
if (item.name == bindEventName) {
|
if (item.name == bindEventName) {
|
||||||
paramStr = item.paramStr;
|
paramStr = item.paramStr;
|
||||||
}
|
}
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
this.bindEventName = bindEventName;
|
this.bindEventName = bindEventName;
|
||||||
editor.emit('eventBindDialog.openDialog', bindEventName, SETTER_NAME, paramStr);
|
editor.emit('eventBindDialog.openDialog', bindEventName, SETTER_NAME, paramStr);
|
||||||
@ -351,6 +369,8 @@ export default class EventsSetter extends Component<{
|
|||||||
item.paramStr = paramStr;
|
item.paramStr = paramStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -372,7 +392,6 @@ export default class EventsSetter extends Component<{
|
|||||||
selectType,
|
selectType,
|
||||||
eventDataList,
|
eventDataList,
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const { editor } = this.props.field;
|
|
||||||
const showEventList =
|
const showEventList =
|
||||||
lifeCycleEventList.length > 0 ? lifeCycleEventList : eventList;
|
lifeCycleEventList.length > 0 ? lifeCycleEventList : eventList;
|
||||||
return (
|
return (
|
||||||
@ -398,7 +417,7 @@ export default class EventsSetter extends Component<{
|
|||||||
className="event-menu"
|
className="event-menu"
|
||||||
onItemClick={this.onEventMenuClick}
|
onItemClick={this.onEventMenuClick}
|
||||||
>
|
>
|
||||||
{showEventList.map((item, index) => (
|
{showEventList.map((item) => (
|
||||||
<Item
|
<Item
|
||||||
key={item.name}
|
key={item.name}
|
||||||
helper={item.description}
|
helper={item.description}
|
||||||
@ -418,9 +437,9 @@ export default class EventsSetter extends Component<{
|
|||||||
>
|
>
|
||||||
{nativeEventList.map((item, index) => (
|
{nativeEventList.map((item, index) => (
|
||||||
<Group label={item.name} key={index}>
|
<Group label={item.name} key={index}>
|
||||||
{item.eventList.map(item => (
|
{item.eventList.map(groupItem => (
|
||||||
<Item key={item.name} disabled={item.disabled}>
|
<Item key={groupItem.name} disabled={groupItem.disabled}>
|
||||||
{item.name}
|
{groupItem.name}
|
||||||
</Item>
|
</Item>
|
||||||
))}
|
))}
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@ -2,9 +2,8 @@ import React, { PureComponent } from 'react';
|
|||||||
// import PropTypes from 'prop-types';
|
// import PropTypes from 'prop-types';
|
||||||
import { Button, Icon, Dialog } from '@alifd/next';
|
import { Button, Icon, Dialog } from '@alifd/next';
|
||||||
import MonacoEditor from 'react-monaco-editor';
|
import MonacoEditor from 'react-monaco-editor';
|
||||||
import { js_beautify, css_beautify } from 'js-beautify';
|
import { js_beautify } from 'js-beautify';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
import { timingSafeEqual } from 'crypto';
|
|
||||||
|
|
||||||
const SETTER_NAME = 'function-setter';
|
const SETTER_NAME = 'function-setter';
|
||||||
|
|
||||||
@ -40,25 +39,23 @@ interface FunctionSetterProps {
|
|||||||
defaultValue: string;
|
defaultValue: string;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
hasClear: boolean;
|
hasClear: boolean;
|
||||||
onChange: (icon: string | object) => undefined;
|
onChange: (icon: string) => undefined;
|
||||||
icons: string[];
|
icons: string[];
|
||||||
}
|
}
|
||||||
export default class FunctionSetter extends PureComponent<FunctionSetterProps, {}> {
|
export default class FunctionSetter extends PureComponent<FunctionSetterProps> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
value: undefined,
|
value: undefined,
|
||||||
type: 'string',
|
type: 'string',
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
hasClear: true,
|
hasClear: true,
|
||||||
placeholder: '请点击选择 Icon',
|
placeholder: '请点击选择 Icon',
|
||||||
onChange: (icon: string | object) => undefined,
|
onChange: () => undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
private emitEventName = '';
|
private emitEventName = '';
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
firstLoad: true,
|
|
||||||
isShowDialog: false,
|
isShowDialog: false,
|
||||||
functionCode: null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -79,7 +76,7 @@ export default class FunctionSetter extends PureComponent<FunctionSetterProps, {
|
|||||||
|
|
||||||
|
|
||||||
bindFunction = () => {
|
bindFunction = () => {
|
||||||
const { field, value } = this.props;
|
const { field } = this.props;
|
||||||
field.editor.emit('eventBindDialog.openDialog', field.name, this.emitEventName);
|
field.editor.emit('eventBindDialog.openDialog', field.name, this.emitEventName);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,7 +96,7 @@ export default class FunctionSetter extends PureComponent<FunctionSetterProps, {
|
|||||||
};
|
};
|
||||||
|
|
||||||
removeFunctionBind = () => {
|
removeFunctionBind = () => {
|
||||||
const { field, removeProp } = this.props;
|
const { removeProp } = this.props;
|
||||||
removeProp();
|
removeProp();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,12 +154,14 @@ export default class FunctionSetter extends PureComponent<FunctionSetterProps, {
|
|||||||
|
|
||||||
// 解析函数名
|
// 解析函数名
|
||||||
const functionName = this.parseFunctionName(value.value);
|
const functionName = this.parseFunctionName(value.value);
|
||||||
return (<div className="function-container">
|
return (
|
||||||
|
<div className="function-container">
|
||||||
<img className="funtion-icon" src="https://gw.alicdn.com/tfs/TB1NXNhk639YK4jSZPcXXXrUFXa-200-200.png" />
|
<img className="funtion-icon" src="https://gw.alicdn.com/tfs/TB1NXNhk639YK4jSZPcXXXrUFXa-200-200.png" />
|
||||||
<span className="function-name" onClick={() => this.focusFunctionName(functionName)}>{functionName}</span>
|
<span className="function-name" onClick={() => this.focusFunctionName(functionName)}>{functionName}</span>
|
||||||
<Icon type="set" size="medium" className="funtion-operate-icon" onClick={this.bindFunction} />
|
<Icon type="set" size="medium" className="funtion-operate-icon" onClick={this.bindFunction} />
|
||||||
<Icon type="ashbin" size="medium" className="funtion-operate-icon" onClick={this.removeFunctionBind} />
|
<Icon type="ashbin" size="medium" className="funtion-operate-icon" onClick={this.removeFunctionBind} />
|
||||||
</div>);
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -170,9 +169,11 @@ export default class FunctionSetter extends PureComponent<FunctionSetterProps, {
|
|||||||
* 渲染编辑函数按钮(可直接编辑函数内容)
|
* 渲染编辑函数按钮(可直接编辑函数内容)
|
||||||
*/
|
*/
|
||||||
renderEditFunctionButton = () => {
|
renderEditFunctionButton = () => {
|
||||||
return (<div>
|
return (
|
||||||
|
<div>
|
||||||
<Button type="primary" onClick={this.openDialog}><Icon type="edit" />编辑函数</Button>
|
<Button type="primary" onClick={this.openDialog}><Icon type="edit" />编辑函数</Button>
|
||||||
</div>);
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -192,13 +193,27 @@ export default class FunctionSetter extends PureComponent<FunctionSetterProps, {
|
|||||||
if (value && value.value) {
|
if (value && value.value) {
|
||||||
functionName = this.parseFunctionName(value.value);
|
functionName = this.parseFunctionName(value.value);
|
||||||
}
|
}
|
||||||
return (<div className="lc-function-setter">
|
|
||||||
|
let renderFunction;
|
||||||
|
if (value) {
|
||||||
|
if (functionName) {
|
||||||
|
renderFunction = this.renderBindFunction;
|
||||||
|
} else {
|
||||||
|
renderFunction = this.renderEditFunctionButton;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
renderFunction = this.renderButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="lc-function-setter">
|
||||||
{
|
{
|
||||||
value ? (functionName ? this.renderBindFunction() : this.renderEditFunctionButton()) : this.renderButton()
|
renderFunction()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
value && value.value && <Dialog visible={isShowDialog} closeable={'close'} title="函数编辑" onCancel={this.closeDialog} onOk={this.onDialogOk} onClose={() => { this.closeDialog(); }}>
|
value && value.value &&
|
||||||
|
<Dialog visible={isShowDialog} closeable={'close'} title="函数编辑" onCancel={this.closeDialog} onOk={this.onDialogOk} onClose={() => { this.closeDialog(); }}>
|
||||||
<div style={{ width: '500px', height: '400px' }}>
|
<div style={{ width: '500px', height: '400px' }}>
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
value={js_beautify(value.value)}
|
value={js_beautify(value.value)}
|
||||||
@ -209,8 +224,7 @@ export default class FunctionSetter extends PureComponent<FunctionSetterProps, {
|
|||||||
</div>
|
</div>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
</div>);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,10 +68,10 @@ interface IconSetterProps {
|
|||||||
defaultValue: string;
|
defaultValue: string;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
hasClear: boolean;
|
hasClear: boolean;
|
||||||
onChange: (icon: string | object) => undefined;
|
onChange: (icon: string) => undefined;
|
||||||
icons: string[];
|
icons: string[];
|
||||||
}
|
}
|
||||||
export default class IconSetter extends PureComponent<IconSetterProps, {}> {
|
export default class IconSetter extends PureComponent<IconSetterProps> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
value: undefined,
|
value: undefined,
|
||||||
type: 'string',
|
type: 'string',
|
||||||
@ -79,7 +79,7 @@ export default class IconSetter extends PureComponent<IconSetterProps, {}> {
|
|||||||
hasClear: true,
|
hasClear: true,
|
||||||
icons,
|
icons,
|
||||||
placeholder: '请点击选择 Icon',
|
placeholder: '请点击选择 Icon',
|
||||||
onChange: (icon: string | object) => undefined,
|
onChange: () => undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@ -109,7 +109,7 @@ export default class IconSetter extends PureComponent<IconSetterProps, {}> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { icons, value, defaultValue, onChange, placeholder, hasClear, type } = this.props;
|
const { value, defaultValue, onChange, placeholder, hasClear } = this.props;
|
||||||
const { firstLoad } = this.state;
|
const { firstLoad } = this.state;
|
||||||
const _value = typeof value === 'object' ? value?.props?.type : value;
|
const _value = typeof value === 'object' ? value?.props?.type : value;
|
||||||
if (firstLoad && defaultValue && typeof value === 'undefined') {
|
if (firstLoad && defaultValue && typeof value === 'undefined') {
|
||||||
|
|||||||
@ -55,9 +55,10 @@ export const DateRangeSetter = DatePicker.RangePicker;
|
|||||||
|
|
||||||
export { ExpressionSetter, EventsSetter, JsonSetter, IconSetter };
|
export { ExpressionSetter, EventsSetter, JsonSetter, IconSetter };
|
||||||
|
|
||||||
|
// eslint-disable-next-line rule
|
||||||
class StringDateSetter extends Component {
|
class StringDateSetter extends Component {
|
||||||
render() {
|
render() {
|
||||||
const { onChange, editor } = this.props;
|
const { onChange } = this.props;
|
||||||
return (
|
return (
|
||||||
<DatePicker
|
<DatePicker
|
||||||
onChange={(val) => {
|
onChange={(val) => {
|
||||||
@ -67,9 +68,11 @@ class StringDateSetter extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line rule
|
||||||
class StringTimePicker extends Component {
|
class StringTimePicker extends Component {
|
||||||
render() {
|
render() {
|
||||||
const { onChange, editor } = this.props;
|
const { onChange } = this.props;
|
||||||
return (
|
return (
|
||||||
<TimePicker
|
<TimePicker
|
||||||
onChange={(val) => {
|
onChange={(val) => {
|
||||||
|
|||||||
@ -30,6 +30,7 @@ class MonacoEditorView extends PureComponent {
|
|||||||
localeConfig('MonacoEditor', MonacoEditorView);
|
localeConfig('MonacoEditor', MonacoEditorView);
|
||||||
|
|
||||||
// monaco编辑器存在3种主题:vs、vs-dark、hc-black
|
// monaco编辑器存在3种主题:vs、vs-dark、hc-black
|
||||||
|
// eslint-disable-next-line rule
|
||||||
class MonacoEditorDefaultView extends PureComponent {
|
class MonacoEditorDefaultView extends PureComponent {
|
||||||
static displayName = 'MonacoEditorDefault';
|
static displayName = 'MonacoEditorDefault';
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ class MonacoEditorDefaultView extends PureComponent {
|
|||||||
|
|
||||||
editorParentNode: any;
|
editorParentNode: any;
|
||||||
|
|
||||||
constructor(props: Readonly<{}>) {
|
constructor(props: Readonly) {
|
||||||
super(props);
|
super(props);
|
||||||
this.strValue = '';
|
this.strValue = '';
|
||||||
this.i18n = generateI18n(props.locale, props.messages);
|
this.i18n = generateI18n(props.locale, props.messages);
|
||||||
@ -288,8 +289,12 @@ class MonacoEditorDefaultView extends PureComponent {
|
|||||||
} else if (value && typeof value === 'string') {
|
} else if (value && typeof value === 'string') {
|
||||||
try {
|
try {
|
||||||
const ret = this.toJson(value);
|
const ret = this.toJson(value);
|
||||||
if (!ret.error) tarValue = JSON.stringify(ret.value, null, 2);
|
if (!ret.error) {
|
||||||
} catch (err) {}
|
tarValue = JSON.stringify(ret.value, null, 2);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (language === 'function') {
|
} else if (language === 'function') {
|
||||||
if (typeof value === 'function') {
|
if (typeof value === 'function') {
|
||||||
@ -305,13 +310,17 @@ class MonacoEditorDefaultView extends PureComponent {
|
|||||||
try {
|
try {
|
||||||
tarValue = serialize(value, { unsafe: true });
|
tarValue = serialize(value, { unsafe: true });
|
||||||
tarValue = js_beautify(tarValue, { indent_size: 2, indent_empty_lines: true });
|
tarValue = js_beautify(tarValue, { indent_size: 2, indent_empty_lines: true });
|
||||||
} catch (err) {}
|
} catch (err) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
} else if (typeof value === 'string') {
|
} else if (typeof value === 'string') {
|
||||||
try {
|
try {
|
||||||
const ret = this.resultHandler(value, 'object');
|
const ret = this.resultHandler(value, 'object');
|
||||||
tarValue = ret.error ? ret.value : serialize(ret.value, { unsafe: true });
|
tarValue = ret.error ? ret.value : serialize(ret.value, { unsafe: true });
|
||||||
tarValue = js_beautify(tarValue, { indent_size: 2, indent_empty_lines: true });
|
tarValue = js_beautify(tarValue, { indent_size: 2, indent_empty_lines: true });
|
||||||
} catch (err) {}
|
} catch (err) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tarValue;
|
return tarValue;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user