张恒

更新依赖,添加关闭内置服务端方法

...@@ -42,6 +42,7 @@ npm config edit ...@@ -42,6 +42,7 @@ npm config edit
42 这是花裤衩大大原本的[地址](https://github.com/PanJiaChen/electron-vue-admin) 42 这是花裤衩大大原本的[地址](https://github.com/PanJiaChen/electron-vue-admin)
43 43
44 # 更新日志 44 # 更新日志
45 +- 2020年04月30日:添加内置服务端关闭方法,进一步简化登录流程;多窗口文档已就绪,服务端说明尚未补充。
45 - 2020年04月29日:添加了路由多窗口示例,修复web打包,提升依赖;文档还未就绪 46 - 2020年04月29日:添加了路由多窗口示例,修复web打包,提升依赖;文档还未就绪
46 - 2020年02月09日:添加[中文在线文档](https://umbrella22.github.io/electron-vue-template-doc/)[国内访问地址](https://zh-sky.gitee.io/electron-vue-template-doc/) 47 - 2020年02月09日:添加[中文在线文档](https://umbrella22.github.io/electron-vue-template-doc/)[国内访问地址](https://zh-sky.gitee.io/electron-vue-template-doc/)
47 - 剔除win打包依赖,因为太大了,将它放到码云的额外仓库中,[地址](https://gitee.com/Zh-Sky/HardToDownloadLib) 48 - 剔除win打包依赖,因为太大了,将它放到码云的额外仓库中,[地址](https://gitee.com/Zh-Sky/HardToDownloadLib)
......
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
86 "vuex-electron": "^1.0.3" 86 "vuex-electron": "^1.0.3"
87 }, 87 },
88 "devDependencies": { 88 "devDependencies": {
89 - "@babel/core": "^7.9.0", 89 + "@babel/core": "^7.9.6",
90 "@babel/plugin-proposal-class-properties": "^7.8.3", 90 "@babel/plugin-proposal-class-properties": "^7.8.3",
91 "@babel/plugin-proposal-decorators": "^7.8.3", 91 "@babel/plugin-proposal-decorators": "^7.8.3",
92 "@babel/plugin-proposal-do-expressions": "^7.8.3", 92 "@babel/plugin-proposal-do-expressions": "^7.8.3",
...@@ -103,11 +103,11 @@ ...@@ -103,11 +103,11 @@
103 "@babel/plugin-proposal-throw-expressions": "^7.8.3", 103 "@babel/plugin-proposal-throw-expressions": "^7.8.3",
104 "@babel/plugin-syntax-dynamic-import": "^7.8.3", 104 "@babel/plugin-syntax-dynamic-import": "^7.8.3",
105 "@babel/plugin-syntax-import-meta": "^7.8.3", 105 "@babel/plugin-syntax-import-meta": "^7.8.3",
106 - "@babel/plugin-transform-runtime": "^7.9.0", 106 + "@babel/plugin-transform-runtime": "^7.9.6",
107 "@babel/polyfill": "^7.8.7", 107 "@babel/polyfill": "^7.8.7",
108 - "@babel/preset-env": "^7.9.5", 108 + "@babel/preset-env": "^7.9.6",
109 "@babel/register": "^7.9.0", 109 "@babel/register": "^7.9.0",
110 - "@babel/runtime": "^7.9.2", 110 + "@babel/runtime": "^7.9.6",
111 "ajv": "^6.12.2", 111 "ajv": "^6.12.2",
112 "babel-eslint": "^9.0.0", 112 "babel-eslint": "^9.0.0",
113 "babel-loader": "^8.1.0", 113 "babel-loader": "^8.1.0",
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
119 "css-loader": "^3.5.3", 119 "css-loader": "^3.5.3",
120 "del": "^5.1.0", 120 "del": "^5.1.0",
121 "electron": "^8.2.4", 121 "electron": "^8.2.4",
122 - "electron-builder": "^22.5.1", 122 + "electron-builder": "^22.6.0",
123 "electron-devtools-installer": "^3.0.0", 123 "electron-devtools-installer": "^3.0.0",
124 "eslint": "^6.8.0", 124 "eslint": "^6.8.0",
125 "eslint-config-standard": "^14.1.1", 125 "eslint-config-standard": "^14.1.1",
......
...@@ -3,12 +3,13 @@ import app from './server' ...@@ -3,12 +3,13 @@ import app from './server'
3 import http from 'http' 3 import http from 'http'
4 import config from '@config' 4 import config from '@config'
5 const port = config.BuiltInServerPort 5 const port = config.BuiltInServerPort
6 +var server = null
6 app.set('port', port) 7 app.set('port', port)
7 8
8 export default { 9 export default {
9 StatrServer () { 10 StatrServer () {
10 return new Promise((resolve, reject) => { 11 return new Promise((resolve, reject) => {
11 - const server = http.createServer(app) 12 + server = http.createServer(app)
12 server.listen(port) 13 server.listen(port)
13 server.on('error', (error) => { 14 server.on('error', (error) => {
14 switch (error.code) { 15 switch (error.code) {
...@@ -26,5 +27,19 @@ export default { ...@@ -26,5 +27,19 @@ export default {
26 resolve('服务端运行中') 27 resolve('服务端运行中')
27 }) 28 })
28 }) 29 })
30 + },
31 + StopServer () {
32 + return new Promise((resolve, reject) => {
33 + console.log(server)
34 + if (server) {
35 + server.close()
36 + server.on('close', () => {
37 + server = null
38 + resolve(1)
39 + })
40 + } else {
41 + reject('服务端尚未开启')
42 + }
43 + })
29 } 44 }
30 } 45 }
......
...@@ -50,6 +50,16 @@ export default { ...@@ -50,6 +50,16 @@ export default {
50 ) 50 )
51 }) 51 })
52 }) 52 })
53 + ipcMain.on('stop-server', (event, arg) => {
54 + Server.StopServer().then(res => {
55 + event.reply('confirm-stop', res)
56 + }).catch(err => {
57 + dialog.showErrorBox(
58 + '错误',
59 + err
60 + )
61 + })
62 + })
53 ipcMain.on('open-win', (event, arg) => { 63 ipcMain.on('open-win', (event, arg) => {
54 const ChildWin = new BrowserWindow({ 64 const ChildWin = new BrowserWindow({
55 height: 595, 65 height: 595,
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 17
18 <div class="right-side"> 18 <div class="right-side">
19 <div class="doc"> 19 <div class="doc">
20 - <div class="title alt">您可以点击的按钮</div> 20 + <div class="title alt">您可以点击的按钮测试功能</div>
21 <el-button type="primary" round @click="open()">控制台打印</el-button> 21 <el-button type="primary" round @click="open()">控制台打印</el-button>
22 <el-button type="primary" round @click="setdata">写入数据</el-button> 22 <el-button type="primary" round @click="setdata">写入数据</el-button>
23 <el-button type="primary" round @click="getdata">读取数据</el-button> 23 <el-button type="primary" round @click="getdata">读取数据</el-button>
...@@ -27,7 +27,10 @@ ...@@ -27,7 +27,10 @@
27 <div class="doc"> 27 <div class="doc">
28 <el-button type="primary" round @click="CheckUpdate('two')">检查更新(第二种方法)</el-button> 28 <el-button type="primary" round @click="CheckUpdate('two')">检查更新(第二种方法)</el-button>
29 <el-button type="primary" round @click="StartServer">启动内置服务端</el-button> 29 <el-button type="primary" round @click="StartServer">启动内置服务端</el-button>
30 + <el-button type="primary" round @click="StopServer">关闭内置服务端</el-button>
30 <el-button type="primary" round @click="getMessage">查看消息</el-button> 31 <el-button type="primary" round @click="getMessage">查看消息</el-button>
32 + </div>
33 + <div class="doc">
31 <el-button type="primary" round @click="openNewWin">打开新窗口</el-button> 34 <el-button type="primary" round @click="openNewWin">打开新窗口</el-button>
32 </div> 35 </div>
33 </div> 36 </div>
...@@ -82,10 +85,10 @@ export default { ...@@ -82,10 +85,10 @@ export default {
82 console.log(__lib); 85 console.log(__lib);
83 }, 86 },
84 methods: { 87 methods: {
85 - openNewWin(){ 88 + openNewWin() {
86 let data = { 89 let data = {
87 - url:'/form/index' 90 + url: "/form/index"
88 - } 91 + };
89 this.$ipcApi.send("open-win", data); 92 this.$ipcApi.send("open-win", data);
90 }, 93 },
91 getMessage() { 94 getMessage() {
...@@ -95,6 +98,15 @@ export default { ...@@ -95,6 +98,15 @@ export default {
95 }); 98 });
96 }); 99 });
97 }, 100 },
101 + StopServer() {
102 + this.$ipcApi.send("stop-server");
103 + this.$ipcApi.on("confirm-stop", (event, arg) => {
104 + this.$message({
105 + type: "success",
106 + message: "已关闭"
107 + });
108 + });
109 + },
98 StartServer() { 110 StartServer() {
99 this.$ipcApi.send("statr-server"); 111 this.$ipcApi.send("statr-server");
100 this.$ipcApi.on("confirm-start", (event, arg) => { 112 this.$ipcApi.on("confirm-start", (event, arg) => {
...@@ -255,9 +267,12 @@ export default { ...@@ -255,9 +267,12 @@ export default {
255 } 267 }
256 }, 268 },
257 destroyed() { 269 destroyed() {
270 + console.log("销毁了哦")
258 this.$ipcApi.remove("confirm-message"); 271 this.$ipcApi.remove("confirm-message");
259 this.$ipcApi.remove("download-done"); 272 this.$ipcApi.remove("download-done");
260 this.$ipcApi.remove("download-paused"); 273 this.$ipcApi.remove("download-paused");
274 + this.$ipcApi.remove("confirm-stop");
275 + this.$ipcApi.remove("confirm-start");
261 this.$ipcApi.remove("confirm-download"); 276 this.$ipcApi.remove("confirm-download");
262 this.$ipcApi.remove("download-progress"); 277 this.$ipcApi.remove("download-progress");
263 this.$ipcApi.remove("download-error"); 278 this.$ipcApi.remove("download-error");
......