1
1
<template >
2
2
<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
-
20
3
<textarea id =" textarea" ref =" jdlcode" v-model =" code" ></textarea >
21
4
<canvas
22
5
id =" canvas"
30
13
@mouseleave =" mouseUp"
31
14
v-bind:style =" {width:pannerStyle.w}"
32
15
></div >
33
-
34
16
<div class =" tools" >
35
17
<el-col :span =" 6" >
36
18
<el-upload
57
39
</a >
58
40
</el-col >
59
41
</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 >
77
42
</div >
78
43
</template >
79
44
<script >
80
45
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
+
81
51
import " codemirror/theme/base16-dark.css" ;
82
52
import " codemirror/lib/codemirror.css" ;
83
53
import " codemirror/addon/hint/show-hint.css" ;
@@ -88,18 +58,7 @@ import "./css/solarized.jdl.css";
88
58
89
59
import _ from " lodash" ;
90
60
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" ;
95
61
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" ;
103
62
104
63
import " codemirror/addon/selection/active-line" ;
105
64
import " codemirror/addon/edit/matchbrackets" ;
@@ -126,17 +85,6 @@ export default {
126
85
scrollbarStyle: " simple"
127
86
},
128
87
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
- ` ,
140
88
canvasElement: {},
141
89
canvasStyle: {
142
90
t: 0 ,
@@ -157,31 +105,31 @@ relationship OneToOne {
157
105
y: 0
158
106
},
159
107
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: {},
171
108
fileList: []
172
109
};
173
110
},
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
+ },
175
120
created () {},
176
121
mounted () {
177
- this . editor = CodeMirror .fromTextArea (this .$refs .jdlcode , this .cmOptions );
122
+ let editor = CodeMirror .fromTextArea (this .$refs .jdlcode , this .cmOptions );
178
123
this .canvasElement = document .getElementById (" canvas" );
179
124
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 (
182
127
document .documentElement .clientWidth ,
183
128
document .documentElement .clientHeight * 0.95
184
129
);
130
+ // 更新editor
131
+ this .$store .commit (" setEditor" , editor);
132
+
185
133
this .vm = skanaar .vector ;
186
134
window .addEventListener (
187
135
" resize" ,
@@ -226,14 +174,10 @@ relationship OneToOne {
226
174
try {
227
175
let superSampling = window .devicePixelRatio || 1 ;
228
176
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);
234
178
this .positionCanvas (this .canvasElement , superSampling, this .offset );
235
179
// save context
236
- Vue . localStorage . set ( this . settings . baseName , this . editor . getValue ());
180
+
237
181
// save file
238
182
} catch (e) {
239
183
console .error (e);
@@ -275,30 +219,25 @@ relationship OneToOne {
275
219
console .log (data);
276
220
}
277
221
if (_ .endsWith (file .name , " .jdl" )) {
278
- this .editor . setValue ( data);
222
+ this .$store . commit ( " setEditorValue " , data);
279
223
// data->jdlobject
280
224
data = data .replace (/ \/\/ [^ \n\r ] * / gm , " " );
281
225
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);
290
227
}
291
228
this .fileList = [];
292
229
};
293
230
},
294
231
addHandle () {},
295
232
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
+ });
298
236
saveAs (blob, this .settings .baseName + " .jdl" );
299
237
},
300
238
delHandle () {
301
- this .editor .setValue (" " );
239
+ this .$store .commit (" setEditorValue" , " " );
240
+ this .$store .commit (" setJdlObject" , {});
302
241
},
303
242
handleClose () {
304
243
this .settingdialogVisiable = false ;
0 commit comments