张恒

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

......@@ -42,6 +42,7 @@ npm config edit
这是花裤衩大大原本的[地址](https://github.com/PanJiaChen/electron-vue-admin)
# 更新日志
- 2020年04月30日:添加内置服务端关闭方法,进一步简化登录流程;多窗口文档已就绪,服务端说明尚未补充。
- 2020年04月29日:添加了路由多窗口示例,修复web打包,提升依赖;文档还未就绪
- 2020年02月09日:添加[中文在线文档](https://umbrella22.github.io/electron-vue-template-doc/)[国内访问地址](https://zh-sky.gitee.io/electron-vue-template-doc/)
- 剔除win打包依赖,因为太大了,将它放到码云的额外仓库中,[地址](https://gitee.com/Zh-Sky/HardToDownloadLib)
......
......@@ -86,7 +86,7 @@
"vuex-electron": "^1.0.3"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-proposal-do-expressions": "^7.8.3",
......@@ -103,11 +103,11 @@
"@babel/plugin-proposal-throw-expressions": "^7.8.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/polyfill": "^7.8.7",
"@babel/preset-env": "^7.9.5",
"@babel/preset-env": "^7.9.6",
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@babel/runtime": "^7.9.6",
"ajv": "^6.12.2",
"babel-eslint": "^9.0.0",
"babel-loader": "^8.1.0",
......@@ -119,7 +119,7 @@
"css-loader": "^3.5.3",
"del": "^5.1.0",
"electron": "^8.2.4",
"electron-builder": "^22.5.1",
"electron-builder": "^22.6.0",
"electron-devtools-installer": "^3.0.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
......
......@@ -3,12 +3,13 @@ import app from './server'
import http from 'http'
import config from '@config'
const port = config.BuiltInServerPort
var server = null
app.set('port', port)
export default {
StatrServer () {
return new Promise((resolve, reject) => {
const server = http.createServer(app)
server = http.createServer(app)
server.listen(port)
server.on('error', (error) => {
switch (error.code) {
......@@ -26,5 +27,19 @@ export default {
resolve('服务端运行中')
})
})
},
StopServer () {
return new Promise((resolve, reject) => {
console.log(server)
if (server) {
server.close()
server.on('close', () => {
server = null
resolve(1)
})
} else {
reject('服务端尚未开启')
}
})
}
}
......
......@@ -50,6 +50,16 @@ export default {
)
})
})
ipcMain.on('stop-server', (event, arg) => {
Server.StopServer().then(res => {
event.reply('confirm-stop', res)
}).catch(err => {
dialog.showErrorBox(
'错误',
err
)
})
})
ipcMain.on('open-win', (event, arg) => {
const ChildWin = new BrowserWindow({
height: 595,
......
......@@ -17,7 +17,7 @@
<div class="right-side">
<div class="doc">
<div class="title alt">您可以点击的按钮</div>
<div class="title alt">您可以点击的按钮测试功能</div>
<el-button type="primary" round @click="open()">控制台打印</el-button>
<el-button type="primary" round @click="setdata">写入数据</el-button>
<el-button type="primary" round @click="getdata">读取数据</el-button>
......@@ -27,7 +27,10 @@
<div class="doc">
<el-button type="primary" round @click="CheckUpdate('two')">检查更新(第二种方法)</el-button>
<el-button type="primary" round @click="StartServer">启动内置服务端</el-button>
<el-button type="primary" round @click="StopServer">关闭内置服务端</el-button>
<el-button type="primary" round @click="getMessage">查看消息</el-button>
</div>
<div class="doc">
<el-button type="primary" round @click="openNewWin">打开新窗口</el-button>
</div>
</div>
......@@ -82,10 +85,10 @@ export default {
console.log(__lib);
},
methods: {
openNewWin(){
openNewWin() {
let data = {
url:'/form/index'
}
url: "/form/index"
};
this.$ipcApi.send("open-win", data);
},
getMessage() {
......@@ -95,6 +98,15 @@ export default {
});
});
},
StopServer() {
this.$ipcApi.send("stop-server");
this.$ipcApi.on("confirm-stop", (event, arg) => {
this.$message({
type: "success",
message: "已关闭"
});
});
},
StartServer() {
this.$ipcApi.send("statr-server");
this.$ipcApi.on("confirm-start", (event, arg) => {
......@@ -255,9 +267,12 @@ export default {
}
},
destroyed() {
console.log("销毁了哦")
this.$ipcApi.remove("confirm-message");
this.$ipcApi.remove("download-done");
this.$ipcApi.remove("download-paused");
this.$ipcApi.remove("confirm-stop");
this.$ipcApi.remove("confirm-start");
this.$ipcApi.remove("confirm-download");
this.$ipcApi.remove("download-progress");
this.$ipcApi.remove("download-error");
......