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"
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
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 >
8045import 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+
8151import " codemirror/theme/base16-dark.css" ;
8252import " codemirror/lib/codemirror.css" ;
8353import " codemirror/addon/hint/show-hint.css" ;
@@ -88,18 +58,7 @@ import "./css/solarized.jdl.css";
8858
8959import _ from " lodash" ;
9060import 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" ;
9561import 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
10463import " codemirror/addon/selection/active-line" ;
10564import " 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 ;
0 commit comments