diff --git a/packages/editor-setters/src/expression-setter/index.tsx b/packages/editor-setters/src/expression-setter/index.tsx index ae7cfa81b..c564bbb82 100644 --- a/packages/editor-setters/src/expression-setter/index.tsx +++ b/packages/editor-setters/src/expression-setter/index.tsx @@ -68,12 +68,13 @@ export default class ExpressionView extends PureComponent { return val; } - constructor(props: Readonly) { + constructor(props: Readonly<{}>) { super(props); this.expression = React.createRef(); this.i18n = generateI18n(props.locale, props.messages); this.state = { value: ExpressionView.getInitValue(props.value), + context: props.context || {}, dataSource: props.dataSource || [], }; } @@ -126,23 +127,32 @@ export default class ExpressionView extends PureComponent { * @return {Array} */ getDataSource(tempStr: string): any[] { - // eslint-disable-next-line no-useless-escape - if (/[^\w\.]$/.test(tempStr)) { - return []; - } else if (tempStr === null || tempStr === '') { - return this.getContextKeys([]); - } else if (/\w\.$/.test(tempStr)) { - const currentField = this.getCurrentFiled(tempStr); - if (!currentField) return null; - let tempKeys = this.getObjectKeys(currentField.str); - tempKeys = this.getContextKeys(tempKeys); - if (!tempKeys) return null; - return tempKeys; - } else if (/\.$/.test(tempStr)) { - return []; - } else { - return null; + const {editor} = this.props.field; + const schema = editor.get('designer').project.getSchema(); + const stateMap = schema.componentsTree[0].state; + let dataSource = []; + + for (let key in stateMap){ + dataSource.push(`this.state.${key}`); } + // if (/[^\w\.]$/.test(tempStr)) { + // return []; + // } else if (tempStr === null || tempStr === '') { + // return this.getContextKeys([]); + // } else if (/\w\.$/.test(tempStr)) { + // const currentField = this.getCurrentFiled(tempStr); + // if (!currentField) return null; + // let tempKeys = this.getObjectKeys(currentField.str); + // tempKeys = this.getContextKeys(tempKeys); + // if (!tempKeys) return null; + // return tempKeys; + // } else if (/\.$/.test(tempStr)) { + // return []; + // } else { + // return null; + // } + + return dataSource; } /** diff --git a/packages/plugin-source-editor/package.json b/packages/plugin-source-editor/package.json index 20efc88f7..c504707d6 100644 --- a/packages/plugin-source-editor/package.json +++ b/packages/plugin-source-editor/package.json @@ -1,6 +1,6 @@ { "name": "@ali/lowcode-plugin-source-editor", - "version": "1.0.8-0", + "version": "1.0.8-beta-1", "description": "alibaba lowcode editor source-editor plugin", "files": [ "es", diff --git a/packages/plugin-source-editor/src/index.scss b/packages/plugin-source-editor/src/index.scss index 9176056ca..1313ba8e5 100644 --- a/packages/plugin-source-editor/src/index.scss +++ b/packages/plugin-source-editor/src/index.scss @@ -13,6 +13,12 @@ height: 100%; } + .button-container{ + position: absolute; + top: 0px; + right: 10px; + } + .editor-context-container{ height: 100%; width: 100%; diff --git a/packages/plugin-source-editor/src/index.tsx b/packages/plugin-source-editor/src/index.tsx index 5341c8c09..0b5f34c8c 100644 --- a/packages/plugin-source-editor/src/index.tsx +++ b/packages/plugin-source-editor/src/index.tsx @@ -14,7 +14,7 @@ const TAB_KEY = { const defaultEditorOption = { width: '100%', - height: '100%', + height: '95%', options: { readOnly: false, automaticLayout: true, @@ -46,8 +46,6 @@ export default class SourceEditor extends Component<{ }> { private monocoEditor; - private monocoEditorCss; - private editorCmd; private editorJsRef = React.createRef(); @@ -56,12 +54,17 @@ export default class SourceEditor extends Component<{ private editorNode; - private editorParentNode; + state = { + isFullScreen:false, + tabKey: TAB_KEY.JS_TAB, + isShowSaveBtn:true + }; // eslint-disable-next-line react/no-deprecated componentWillMount() { const { editor } = this.props; + // 添加函数 editor.on('sourceEditor.addFunction', (params: FunctionEventParam) => { this.callEditorEvent('sourceEditor.addFunction', params); @@ -72,7 +75,6 @@ export default class SourceEditor extends Component<{ this.callEditorEvent('sourceEditor.focusByFunction', params); }); - // 插件面板关闭事件,监听规则同上 editor.on('skeleton.panel-dock.unactive', (pluginName) => { if (pluginName == 'sourceEditor') { @@ -93,7 +95,6 @@ export default class SourceEditor extends Component<{ componentDidMount() { this.editorNode = this.editorJsRef.current; // 记录当前dom节点; - this.editorParentNode = this.editorNode.parentNode; // 记录父节点; } /** @@ -268,11 +269,12 @@ export default class SourceEditor extends Component<{ if (newSchema != '' && JSON.stringify(newSchema) != oldSchemaStr) { editor.get('designer').project.setSchema(newSchema); + successFlag && Message.success('保存成功') } }; render() { - const { selectTab, jsCode, css } = this.state; + const { selectTab, jsCode, css ,isShowSaveBtn} = this.state; const tabs = [ { tab: 'index.js', key: TAB_KEY.JS_TAB }, { tab: 'style.css', key: TAB_KEY.CSS_TAB }, @@ -280,12 +282,13 @@ export default class SourceEditor extends Component<{ return (
+ {tabs.map((item) => ( ))} - + { isShowSaveBtn &&
}
diff --git a/packages/plugin-source-editor/src/transform.ts b/packages/plugin-source-editor/src/transform.ts index 6d4e46914..b4e91bcd6 100644 --- a/packages/plugin-source-editor/src/transform.ts +++ b/packages/plugin-source-editor/src/transform.ts @@ -54,8 +54,12 @@ const transfrom = { return `\n\t${functionName}(){\n\t}\n`; }, - setFunction2Schema(functionMap, schema) { - const pageNode = schema.componentsTree[0]; + setFunction2Schema(functionMap, schema){ + let pageNode = schema.componentsTree[0]; + // 先清除原有的schema的值 + delete pageNode.state; + pageNode.lifeCycles = {}; + pageNode.methods = {}; if (!pageNode) return ''; for (const key in functionMap) { if (key == 'state') {