Skip to content

Commit 4626261

Browse files
author
jxw
committed
split main component,formeditor,exeutor
1 parent a7b9be7 commit 4626261

15 files changed

+190
-194
lines changed

package-lock.json

+41-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
"jhipster-core": "3.6.10",
4444
"lodash": "^4.17.15",
4545
"vue": "^2.6.10",
46-
"vue-localstorage": "^0.6.2"
46+
"vue-bus": "^1.2.1",
47+
"vue-js-toolbar": "^1.0.0",
48+
"vue-router": "^3.0.2",
49+
"vuex": "^3.1.0"
4750
},
4851
"devDependencies": {
4952
"@vue/cli-plugin-babel": "^3.10.0",

packages/vue-jdlstudio/src/JdlStudio.vue

+29-90
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
<template>
22
<div v-bind:class="[isActive? 'canvas-mode' : '', 'jdl-editor']">
3-
<nav class="isFixed">
4-
<el-form :inline="true">
5-
<el-form-item label="ApplicationName">
6-
<el-input
7-
size="mini"
8-
v-model="settings.baseName"
9-
placeholder="please input Application Name"
10-
></el-input>
11-
</el-form-item>
12-
<el-form-item label>
13-
<a href="javascript:void(0);" @click="settingdialogVisiable=true">
14-
<i class="el-icon-setting">setting</i>
15-
</a>
16-
</el-form-item>
17-
</el-form>
18-
</nav>
19-
203
<textarea id="textarea" ref="jdlcode" v-model="code"></textarea>
214
<canvas
225
id="canvas"
@@ -30,7 +13,6 @@
3013
@mouseleave="mouseUp"
3114
v-bind:style="{width:pannerStyle.w}"
3215
></div>
33-
3416
<div class="tools">
3517
<el-col :span="6">
3618
<el-upload
@@ -57,27 +39,15 @@
5739
</a>
5840
</el-col>
5941
</div>
60-
<el-dialog title :visible.sync="settingdialogVisiable" width="30%" :before-close="handleClose">
61-
<el-tabs type="border-card">
62-
<el-tab-pane label="Application" name="first">
63-
<!-- Application form -->
64-
</el-tab-pane>
65-
<el-tab-pane label="entities" name="second">
66-
<!--entities form -->
67-
</el-tab-pane>
68-
<el-tab-pane label="otherSettings" name="third">
69-
<!-- otherSettings form -->
70-
</el-tab-pane>
71-
</el-tabs>
72-
<span slot="footer" class="dialog-footer">
73-
<el-button @click="settingdialogVisiable = false">cancel</el-button>
74-
<el-button type="primary" @click="settingdialogVisiable = false">save</el-button>
75-
</span>
76-
</el-dialog>
7742
</div>
7843
</template>
7944
<script>
8045
import Vue from "vue";
46+
import { mapState, mapGetters } from "vuex";
47+
import CodeMirror from "./lib/codemirror/codemirror.custom";
48+
import nomnoml from "./lib/nomnoml/nomnoml.custom";
49+
import skanaar from "./lib/nomnoml/shannar.custom";
50+
8151
import "codemirror/theme/base16-dark.css";
8252
import "codemirror/lib/codemirror.css";
8353
import "codemirror/addon/hint/show-hint.css";
@@ -88,18 +58,7 @@ import "./css/solarized.jdl.css";
8858
8959
import _ from "lodash";
9060
import saveAs from "file-saver";
91-
92-
import CodeMirror from "./js/codemirror/codemirror.custom";
93-
import nomnoml from "./js/nomnoml/nomnoml.custom";
94-
import skanaar from "./js/nomnoml/shannar.custom";
9561
import parser from "jhipster-core/lib/dsl/api";
96-
import {
97-
DatabaseTypes,
98-
ApplicationTypes,
99-
convertToJHipsterJSON
100-
} from "jhipster-core";
101-
102-
import JDLCore from "jhipster-core";
10362
10463
import "codemirror/addon/selection/active-line";
10564
import "codemirror/addon/edit/matchbrackets";
@@ -126,17 +85,6 @@ export default {
12685
scrollbarStyle: "simple"
12786
},
12887
129-
code: `
130-
entity Region {
131-
regionName String
132-
}
133-
entity Country {
134-
countryName String
135-
}
136-
relationship OneToOne {
137-
Country{region} to Region
138-
}
139-
`,
14088
canvasElement: {},
14189
canvasStyle: {
14290
t: 0,
@@ -157,31 +105,31 @@ relationship OneToOne {
157105
y: 0
158106
},
159107
mouseDownPoint: false,
160-
settings: {
161-
baseName: "test",
162-
applicationType: "microservice",
163-
packageName: "com.test",
164-
prodDatabaseType: "mysql",
165-
devDatabaseType: "mysql",
166-
buildTool: "maven",
167-
cacheProvider: "hazelcast"
168-
},
169-
settingdialogVisiable: false,
170-
editor: {},
171108
fileList: []
172109
};
173110
},
174-
computed: {},
111+
computed: {
112+
...mapState({
113+
code: state => state.jdl.code,
114+
editor: state => state.jdl.editor
115+
}),
116+
...mapGetters({
117+
editorValue: "editorValue"
118+
})
119+
},
175120
created() {},
176121
mounted() {
177-
this.editor = CodeMirror.fromTextArea(this.$refs.jdlcode, this.cmOptions);
122+
let editor = CodeMirror.fromTextArea(this.$refs.jdlcode, this.cmOptions);
178123
this.canvasElement = document.getElementById("canvas");
179124
this.canvasPanner = document.getElementById("canvas-panner");
180-
this.editor.on("changes", _.debounce(this.sourceChanged, 300));
181-
this.editor.setSize(
125+
editor.on("changes", _.debounce(this.sourceChanged, 300));
126+
editor.setSize(
182127
document.documentElement.clientWidth,
183128
document.documentElement.clientHeight * 0.95
184129
);
130+
//更新editor
131+
this.$store.commit("setEditor", editor);
132+
185133
this.vm = skanaar.vector;
186134
window.addEventListener(
187135
"resize",
@@ -226,14 +174,10 @@ relationship OneToOne {
226174
try {
227175
let superSampling = window.devicePixelRatio || 1;
228176
let scale = superSampling * Math.exp(this.zoomLevel / 10);
229-
let model = nomnoml.draw(
230-
this.canvasElement,
231-
this.editor.getValue(),
232-
scale
233-
);
177+
let model = nomnoml.draw(this.canvasElement, this.editorValue, scale);
234178
this.positionCanvas(this.canvasElement, superSampling, this.offset);
235179
//save context
236-
Vue.localStorage.set(this.settings.baseName, this.editor.getValue());
180+
237181
//save file
238182
} catch (e) {
239183
console.error(e);
@@ -275,30 +219,25 @@ relationship OneToOne {
275219
console.log(data);
276220
}
277221
if (_.endsWith(file.name, ".jdl")) {
278-
this.editor.setValue(data);
222+
this.$store.commit("setEditorValue", data);
279223
//data->jdlobject
280224
data = data.replace(/\/\/[^\n\r]*/gm, "");
281225
let jdlObject = parser.parse(data);
282-
console.log(jdlObject);
283-
//TODO convert jdlObject to JSON
284-
// let jdlconfig = {
285-
// jdlObject: jdlObject,
286-
// databaseType: JDLCore.JHipsterDatabaseTypes.MYSQL,
287-
// applicationType: JDLCore.JHipsterApplicationTypes.MICROSERVICE
288-
// };
289-
// convertToJHipsterJSON(jdlconfig);
226+
this.$store.commit("setJdlObject", jdlObject);
290227
}
291228
this.fileList = [];
292229
};
293230
},
294231
addHandle() {},
295232
downHandle() {
296-
let text = this.editor.getValue();
297-
let blob = new Blob([text], { type: "text/plain;charset=utf-8" });
233+
let blob = new Blob([this.editorValue], {
234+
type: "text/plain;charset=utf-8"
235+
});
298236
saveAs(blob, this.settings.baseName + ".jdl");
299237
},
300238
delHandle() {
301-
this.editor.setValue("");
239+
this.$store.commit("setEditorValue", "");
240+
this.$store.commit("setJdlObject", {});
302241
},
303242
handleClose() {
304243
this.settingdialogVisiable = false;
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default {
2+
state: {
3+
code: `
4+
entity Region {
5+
regionName String
6+
}
7+
entity Country {
8+
countryName String
9+
}
10+
relationship OneToOne {
11+
Country{region} to Region
12+
}
13+
`,
14+
editor: {},
15+
jdlObject: {}
16+
},
17+
getters: {
18+
editorValue: state => {
19+
return state.editor.getValue();
20+
}
21+
},
22+
actions: {},
23+
mutations: {
24+
setEditor(state, editor) {
25+
state.editor = editor;
26+
},
27+
setEditorValue(state, value) {
28+
state.editor.setValue(value);
29+
},
30+
setJdlObject(state, value) {
31+
state.jdlObject = value;
32+
}
33+
}
34+
};

src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ body,
2525
text-align: left;
2626
color: #2c3e50;
2727
background: #151515;
28-
margin-top: -15px;
28+
margin-top: -25px;
2929
}
3030
body {
3131
margin: 0px;

0 commit comments

Comments
 (0)