资源面板弹窗交互

This commit is contained in:
zude.hzd 2020-04-22 15:26:02 +08:00
parent 8fc74de204
commit 38ca41a252
5 changed files with 109 additions and 34 deletions

View File

@ -8,7 +8,8 @@ import zhEn from '@ali/lowcode-plugin-zh-en';
import settingsPane from '@ali/lowcode-plugin-settings-pane'; import settingsPane from '@ali/lowcode-plugin-settings-pane';
import designer from '@ali/lowcode-plugin-designer'; import designer from '@ali/lowcode-plugin-designer';
import eventBindDialog from '@ali/lowcode-plugin-event-bind-dialog'; import eventBindDialog from '@ali/lowcode-plugin-event-bind-dialog';
import sourceEditor from '@ali/lowcode-plugin-source-editor' import variableBindDialog from '@ali/lowcode-plugin-variable-bind-dialog';
import sourceEditor from '@ali/lowcode-plugin-source-editor';
export default { export default {
LowcodeSkeleton, LowcodeSkeleton,
logo, logo,
@ -20,5 +21,6 @@ export default {
settingsPane, settingsPane,
designer, designer,
eventBindDialog, eventBindDialog,
variableBindDialog,
sourceEditor sourceEditor
}; };

View File

@ -148,6 +148,13 @@ export default {
"version": "^0.8.0" "version": "^0.8.0"
} }
}, },
{
"pluginKey": "variableBindDialog",
"config": {
"package": "@ali/lowcode-plugin-variable-bind-dialog",
"version": "^0.8.0"
}
}
] ]
}, },
"hooks": [], "hooks": [],

View File

@ -91,6 +91,13 @@ export default class EventBindDialog extends Component<{
onOk = () => { onOk = () => {
const {editor} = this.props; const {editor} = this.props;
editor.emit('event-setter.bindEvent',this.state.eventName); editor.emit('event-setter.bindEvent',this.state.eventName);
// 选中的是新建事件
if (this.state.selectedEventName == ''){
editor.emit('sourceEditor.addFunction',{
functionName:this.state.eventName
})
}
this.closeDialog(); this.closeDialog();
}; };

View File

@ -37,9 +37,13 @@ const defaultEditorOption = {
vertical: 'auto', vertical: 'auto',
horizontal: 'auto', horizontal: 'auto',
}, },
} },
}; };
interface FunctionEventParam {
functionName: String;
}
export default class SourceEditor extends Component<{ export default class SourceEditor extends Component<{
editor: Editor; editor: Editor;
}> { }> {
@ -48,8 +52,8 @@ export default class SourceEditor extends Component<{
state = { state = {
isShow: false, isShow: false,
tabKey: TAB_KEY.JS_TAB tabKey: TAB_KEY.JS_TAB,
} };
componentWillMount() { componentWillMount() {
const { editor } = this.props; const { editor } = this.props;
@ -62,10 +66,19 @@ export default class SourceEditor extends Component<{
}); });
// 添加函数 // 添加函数
editor.on('sourceEditor.addFunction',(params:Object)=>{ editor.on('sourceEditor.addFunction', (params: FunctionEventParam) => {
this.callEditorEvent('sourceEditor.addFunction', params); this.callEditorEvent('sourceEditor.addFunction', params);
this.openPluginPannel();
});
// 定位函数
editor.on('sourceEditor.focusByFunction',(params:FunctionEventParam)=>{
this.callEditorEvent('sourceEditor.focusByFunction', params);
this.openPluginPannel();
}) })
editor.once('designer.mount', (designer: Designer) => { editor.once('designer.mount', (designer: Designer) => {
// let schema = designer.project.getSchema(); // let schema = designer.project.getSchema();
// mock data // mock data
@ -90,7 +103,7 @@ export default class SourceEditor extends Component<{
}, },
methods: { methods: {
//自定义方法对象: 选填 对象类型 //自定义方法对象: 选填 对象类型
testFunc: { getData: {
//自定义方法: 选填 函数类型 //自定义方法: 选填 函数类型
type: 'JSExpression', type: 'JSExpression',
value: "function() {\n \t\tconsole.log('testFunc');\n \t}", value: "function() {\n \t\tconsole.log('testFunc');\n \t}",
@ -102,30 +115,34 @@ export default class SourceEditor extends Component<{
this.initCode(schema); this.initCode(schema);
}); });
}
openPluginPannel = () => {
setTimeout (()=>{ const {editor} = this.props;
editor.emit('sourceEditor.addFunction',{ // 判断面板是否处于激活状态
functionName:'testgaga' if (!editor.leftNav || editor.leftNav != 'sourceEditor') {
}) // 打开面板
},3000) editor.emit('leftNav.change', 'sourceEditor');
}
} }
callEditorEvent = (eventName, params) => { callEditorEvent = (eventName, params) => {
if (!this.monocoEditer) { if (!this.monocoEditer) {
this.editorCmd = { this.editorCmd = {
eventName, eventName,
params params,
}; };
return; return;
} }
if (eventName === 'sourceEditor.addFunction') { if (eventName === 'sourceEditor.addFunction') {
this.addFunction(params); this.addFunction(params);
}else if (eventName === 'sourceEditor.focusByFunction'){
this.focusByFunctionName(params);
} }
}
};
initCode = (schema) => { initCode = (schema) => {
let jsCode = js_beautify(transfrom.schema2Code(schema), { indent_size: 2, indent_empty_lines: true }); let jsCode = js_beautify(transfrom.schema2Code(schema), { indent_size: 2, indent_empty_lines: true });
@ -140,16 +157,49 @@ export default class SourceEditor extends Component<{
css, css,
selectTab: TAB_KEY.JS_TAB, selectTab: TAB_KEY.JS_TAB,
}); });
}; };
addFunction (params){ /**
* js面板中添加一个新函数
* @param params
*/
addFunction(params: FunctionEventParam) {
const count = this.monocoEditer.getModel().getLineCount() || 0; const count = this.monocoEditer.getModel().getLineCount() || 0;
const range = new monaco.Range(count, 1, count, 1); const range = new monaco.Range(count, 1, count, 1);
const functionCode = transfrom.getNewFunctionCode(params.functionName); const functionCode = transfrom.getNewFunctionCode(params.functionName);
this.monocoEditer.executeEdits('log-source', [{ identifier: 'event_id', range:range , text: functionCode, forceMoveMarkers:true }]); this.monocoEditer.executeEdits('log-source', [
{ identifier: 'event_id', range: range, text: functionCode, forceMoveMarkers: true },
]);
setTimeout(() => {
let newPosition = new monaco.Position(count + 1, 2);
this.monocoEditer.setPosition(newPosition);
this.monocoEditer.focus();
}, 100);
this.updateCode(this.monocoEditer.getModel().getValue()) this.updateCode(this.monocoEditer.getModel().getValue());
}
/**
*
* @param functionName
*/
focusByFunctionName(params: FunctionEventParam) {
const functionName = params.functionName;
const matchedResult = this.monocoEditer
.getModel()
.findMatches(`${functionName}\\s*\\([\\s\\S]*\\)[\\s\\S]*\\{`, false, true)[0];
if (matchedResult) {
setTimeout(()=>{
this.monocoEditer.revealLineInCenter(matchedResult.range.startLineNumber);
this.monocoEditer.setPosition({
column: matchedResult.range.endColumn,
lineNumber: matchedResult.range.endLineNumber,
});
this.monocoEditer.focus();
},100)
}
} }
editorDidMount = (editor, monaco) => { editorDidMount = (editor, monaco) => {
@ -214,7 +264,7 @@ export default class SourceEditor extends Component<{
} }
transfrom.code2Schema(newCode); transfrom.code2Schema(newCode);
} };
render() { render() {
const { isShow, selectTab, jsCode, css } = this.state; const { isShow, selectTab, jsCode, css } = this.state;

View File

@ -190,7 +190,7 @@ export default class EventsSetter extends Component<{
</div> </div>
<div className="event-cell" style={{ marginTop: '8px' }}> <div className="event-cell" style={{ marginTop: '8px' }}>
<Icon type="attachment" size="small" className="related-icon" /> <Icon type="attachment" size="small" className="related-icon" />
<span className="related-event-name"> <span className="related-event-name" onClick={()=>this.onRelatedEventNameClick(record.relatedEventName)}>
{record.relatedEventName || ''} {record.relatedEventName || ''}
</span> </span>
</div> </div>
@ -248,6 +248,8 @@ export default class EventsSetter extends Component<{
}); });
}; };
onEventMenuClick = (eventName: String) => { onEventMenuClick = (eventName: String) => {
const { selectType, eventDataList } = this.state; const { selectType, eventDataList } = this.state;
eventDataList.push({ eventDataList.push({
@ -264,6 +266,13 @@ export default class EventsSetter extends Component<{
this.openDialog(eventName); this.openDialog(eventName);
}; };
onRelatedEventNameClick = (eventName:String) => {
const {editor} = this.props.field;
editor.emit('sourceEditor.focusByFunction',{
functionName:eventName
})
}
closeEventMenu = () => { closeEventMenu = () => {
if (this.state.selectType !== null) { if (this.state.selectType !== null) {
this.setState({ this.setState({