79 lines
1.9 KiB
Vue
79 lines
1.9 KiB
Vue
<template>
|
||
<div>
|
||
{{ruleEngineId}}
|
||
<div ref="editor" style="height: 300px; border: 1px solid #ccc; padding: 10px;"></div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import 'codemirror/lib/codemirror.css';
|
||
import 'codemirror/mode/javascript/javascript.js';
|
||
import CodeMirror from 'codemirror';
|
||
import {getRuleContent, ruleengine} from "@/api/ruleengine/ruleengine";
|
||
export default {
|
||
name: "EngineVersion",
|
||
data() {
|
||
return {
|
||
ruleEngineId:0,
|
||
editor: null,
|
||
ruleContentReq:{},
|
||
value:''
|
||
}
|
||
},
|
||
watch: {
|
||
'$route.query.id': function(toVal, oldVal) {
|
||
this.ruleEngineId = toVal;
|
||
if (this.ruleEngineId) {
|
||
this.getRuleContentAndUpdateEditor();
|
||
}
|
||
}
|
||
},
|
||
created() {
|
||
this.ruleEngineId=this.$route.query && this.$route.query.id
|
||
// 初始化 CodeMirror(如果尚未初始化)
|
||
if (!this.editor) {
|
||
this.$nextTick(() => {
|
||
this.editor = CodeMirror(this.$refs.editor, {
|
||
value: "",
|
||
mode: "javascript",
|
||
lineNumbers: true,
|
||
});
|
||
if (this.ruleEngineId) {
|
||
this.getRuleContentAndUpdateEditor();
|
||
}
|
||
});
|
||
}
|
||
},
|
||
methods: {
|
||
getRuleContentAndUpdateEditor() {
|
||
getRuleContent(this.ruleEngineId).then(
|
||
res => {
|
||
if (res && res.data && res.data.ruleContent) {
|
||
console.log('Received rule content:', res.data.ruleContent);
|
||
this.editor.setValue(res.data.ruleContent);
|
||
} else {
|
||
console.log('No rule content found for id', this.ruleEngineId);
|
||
}
|
||
}
|
||
).catch(error => {
|
||
console.error('Error fetching rule content:', error);
|
||
});
|
||
},
|
||
tosend(){
|
||
const code = this.editor.getValue();
|
||
this.ruleContentReq.ruleContent=code
|
||
console.log(this.ruleContentReq)
|
||
ruleengine(this.ruleContentReq).then(
|
||
res=>{
|
||
this.$message.success(res.data)
|
||
}
|
||
)
|
||
},
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
|
||
</style>
|