1
0
mirror of https://github.com/sahadev/vue-component-creater-ui.git synced 2025-06-07 21:54:05 +08:00

增加语法检查能力

This commit is contained in:
shangbin 2021-09-15 10:54:05 +08:00
parent 7795d52f95
commit cc20787843
2 changed files with 17 additions and 8 deletions

View File

@ -5,8 +5,8 @@
<div style="text-align:center;padding: 10px;">
<el-button type="primary" @click="onSave">确认修改</el-button>
<div style="color: #f5222d; font-size:12px; margin-top:5px;">Tips: 确认修改之后将会影响最终生成的代码逻辑</div>
<div style="color: #6c6c6c; font-size:12px; margin-top:5px;">Tips: 确认修改之后将会影响最终生成的代码逻辑</div>
<div v-if="error" style="color: red; font-size:12px; margin-top:5px;">请检查语法错误{{error}}</div>
</div>
</el-dialog>
@ -23,6 +23,7 @@ export default {
data() {
return {
error: ''
};
},
beforeCreate() { },
@ -42,8 +43,18 @@ export default {
},
onSave() {
const code = this.$refs.codeEditor.getEditorCode();
this.$emit("saveJSCode", code);
//
const temp = code.replace(/.+\*\/\s*/gs, "");
try {
//
const JSCodeInfo = eval(`(function(){return ${temp}})()`);
this.$emit("saveJSCode", JSCodeInfo);
this.handleClose();
this.error = '';
} catch (error) {
console.warn(error);
this.error = error;
}
}
},
watch: {

View File

@ -110,10 +110,8 @@ export class MainPanelProvider {
}
saveJSCode(code) {
const temp = code.replace(/.+\*\/\s*/gs, "");
const JSCodeInfo = eval(`(function(){return ${temp}})()`);
this.externalJS = JSCodeInfo;
this.codeGenerator.setExternalJS(JSCodeInfo);
this.externalJS = code;
this.codeGenerator.setExternalJS(code);
this.reRender();
}