3535 </div >
3636</template >
3737<script >
38- import { globalDb , ruleDb , dataDb } from ' @/dataStore'
39- const appCollection = globalDb .get (' apps' )
38+ import { getApps , getAppById , editAppById , addApp , uploadApp , getRemoteApp , deleteApp } from ' @/service/global.service'
39+ import { clearRule , addRule } from ' @/service/rule.service'
40+ import { clearData } from ' @/service/data.service'
4041const { remote } = require (' electron' )
4142const fs = require (' fs' )
4243
@@ -53,35 +54,22 @@ export default {
5354 },
5455 methods: {
5556 getAppList () {
56- this .appList = JSON . parse ( JSON . stringify ( globalDb . get ( ' apps ' ). value ()) )
57+ this .appList = getApps ( )
5758 },
5859 handleCtrl ($event , app ) {
5960 if ($event === ' delete' ) {
6061 this .deleteApp (app .id )
6162 } else if ($event === ' upload' ) {
62- fetch (` ${ this .$store .state .ServerUrl } /apps` , {
63- method: ' post' ,
64- headers: {
65- ' Content-Type' : ' application/json'
66- },
67- body: JSON .stringify ({
68- appName: app .appName ,
69- ruleConfig: app .ruleConfig ,
70- localId: app .id ,
71- type: app .type
63+ uploadApp (app).then (res => {
64+ remote .dialog .showMessageBox ({
65+ type: ' info' ,
66+ title: ' 上传结果' ,
67+ message: res .message ,
68+ buttons: [' ok' ]
7269 })
7370 })
74- .then (res => res .json ())
75- .then (res => {
76- remote .dialog .showMessageBox ({
77- type: ' info' ,
78- title: ' 上传结果' ,
79- message: res .message ,
80- buttons: [' ok' ]
81- })
82- })
8371 } else if ($event === ' export' ) {
84- const details = globalDb . get ( ' apps ' ). find ({ id : app .id }). value ( )
72+ const details = getAppById ( app .id )
8573 const path = remote .dialog .showSaveDialog ({
8674 title: ' 选择保存路径' ,
8775 filters: [{
@@ -113,10 +101,8 @@ export default {
113101 * 新建触发
114102 */
115103 handleCreate (command ) {
116- ruleDb .set (' config' , {}).write ()
117- ruleDb .set (' contentUrls' , {}).write ()
118- ruleDb .set (' publishConfig' , []).write ()
119- dataDb .set (' data' , []).write ()
104+ clearRule ()
105+ clearData ()
120106 if (command === ' rule' ) {
121107 this .$router .push (' /ruleSetting' )
122108 } else {
@@ -135,25 +121,18 @@ export default {
135121 buttons: [' ok' , ' no' ]
136122 }, index => {
137123 if (index === 0 ) {
138- fetch (` ${ this .$store .state .ServerUrl } /apps` )
139- .then (res => res .json ())
124+ getRemoteApp ()
140125 .then (res => {
141126 res .data .forEach (v => {
142- const localApp = appCollection
143- .find ({ id: v .localId })
144- .value ()
145- console .log (localApp)
127+ const localApp = getAppById (v .localId )
146128 if (localApp) {
147129 const remoteApp = JSON .parse (JSON .stringify (v))
148130 remoteApp .id = remoteApp .localId
149- appCollection
150- .find ({ id: v .localId })
151- .assign ({... remoteApp})
152- .write ()
131+ editAppById (v .localId , remoteApp)
153132 } else {
154133 const remoteApp = JSON .parse (JSON .stringify (v))
155134 remoteApp .id = remoteApp .localId
156- appCollection . insert ({ ... remoteApp}). write ( )
135+ addApp ( remoteApp)
157136 this .getAppList ()
158137 }
159138 })
@@ -179,13 +158,11 @@ export default {
179158 fs .readFile (filePath[0 ], ' utf8' , (e , res ) => {
180159 if (e) throw e
181160 const data = JSON .parse (res)
182- appCollection
183- .insert ({
184- appName: filePath[0 ].match (/ ([^ \.\/\\ ] + )\. ([a-z ] + )$ / i )[1 ],
185- ruleConfig: data .ruleConfig ,
186- type: data .type
187- })
188- .write ()
161+ addApp ({
162+ appName: filePath[0 ].match (/ ([^ \.\/\\ ] + )\. ([a-z ] + )$ / i )[1 ],
163+ ruleConfig: data .ruleConfig ,
164+ type: data .type
165+ })
189166 this .getAppList ()
190167 })
191168 /* eslint-enable */
@@ -199,23 +176,19 @@ export default {
199176 buttons: [' ok' , ' no' ]
200177 }, index => {
201178 if (index === 0 ) {
202- appCollection
203- .remove ({ id: id })
204- .write ()
179+ deleteApp (id)
205180 this .getAppList ()
206181 } else {
207182 }
208183 })
209184 },
210185 toDetails (data ) {
211186 if (data .type === ' rule' ) {
212- const details = globalDb . get ( ' apps ' ). find ({ id : data .id }). value ( )
187+ const details = getAppById ( data .id )
213188 if (details) {
214189 const obj = JSON .parse (details .ruleConfig )
215- ruleDb .set (' config' , obj .config ).write ()
216- ruleDb .set (' contentUrls' , obj .contentUrls ).write ()
217- ruleDb .set (' publishConfig' , obj .publishConfig ).write ()
218- dataDb .set (' data' , []).write ()
190+ addRule (obj)
191+ clearData ()
219192 this .$nextTick (_ => {
220193 this .$router .push (` /ruleSetting?id=${ details .id } &appName=${ details .appName } ` )
221194 })
0 commit comments