张恒

添加内置服务器实例,修正开发环境下重置到登录页和登录时闪烁两次

module.exports = {
NODE_ENV: '"development"',
BASE_API: '""'
BASE_API: '"http://127.0.0.1:25565"'
}
......
......@@ -11,5 +11,6 @@ module.exports = {
},
UseStartupChart: true,
IsUseSysTitle: true,
DllFolder: ''
DllFolder: '',
BuiltInServerPort: 25565
}
......
module.exports = {
NODE_ENV: '"production"',
BASE_API: '""'
BASE_API: '"http://127.0.0.1:25565"'
}
......
......@@ -74,6 +74,7 @@
"date-fns": "^2.11.0",
"electron-updater": "^4.2.5",
"element-ui": "^2.13.0",
"express": "^4.17.1",
"fs-extra": "^8.1.0",
"js-cookie": "^2.2.1",
"nedb": "^1.8.0",
......@@ -130,7 +131,6 @@
"eslint-plugin-node": "^9.2.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"express": "^4.17.1",
"file-loader": "^5.1.0",
"happypack": "^5.0.1",
"hard-source-webpack-plugin": "^0.13.1",
......
/* eslint-disable prefer-promise-reject-errors */
import app from './server'
import http from 'http'
import config from '@config'
const port = config.BuiltInServerPort
app.set('port', port)
export default {
StatrServer () {
return new Promise((resolve, reject) => {
const server = http.createServer(app)
server.listen(port)
server.on('error', (error) => {
switch (error.code) {
case 'EACCES':
reject('权限不足内置服务器启动失败,请使用管理员权限运行。')
break
case 'EADDRINUSE':
reject('内置服务器端口已被占用,请检查。')
break
default:
reject(error)
}
})
server.on('listening', () => {
resolve('服务端运行中')
})
})
}
}
import express from 'express'
const app = express()
app.get('/message', (req, res) => {
res.send('这是来自node服务端的信息')
})
app.post('/message', (req, res) => {
if (req) {
res.send(req + '--来自node')
}
})
export default app
import { ipcMain, dialog } from 'electron'
import Server from '../server/index'
export default {
Mainfunc (mainWindow, IsUseSysTitle) {
ipcMain.on('IsUseSysTitle', (event) => {
......@@ -37,5 +38,15 @@ export default {
arg.message
)
})
ipcMain.on('statr-server', (event, arg) => {
Server.StatrServer().then(res => {
event.reply('confirm-start', res)
}).catch(err => {
dialog.showErrorBox(
'错误',
err
)
})
})
}
}
......
......@@ -22,3 +22,10 @@ export function logout () {
method: 'post'
})
}
export function message () {
return request({
url: '/message',
method: 'get'
})
}
......
......@@ -26,6 +26,8 @@
</div>
<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="getMessage">查看消息</el-button>
</div>
</div>
</main>
......@@ -52,6 +54,7 @@
<script>
import SystemInformation from "./LandingPage/SystemInformation";
import ipcApi from "../utils/ipcRenderer";
import { message } from "@/api/login";
export default {
name: "landing-page",
components: { SystemInformation },
......@@ -73,12 +76,29 @@ export default {
],
dialogVisible: false,
progressStaus: null,
filePath: "",
filePath: ""
}),
created() {
console.log(__lib)
console.log(__lib);
},
methods: {
getMessage() {
message().then(res => {
this.$alert(res.data, "提示", {
confirmButtonText: "确定"
});
});
},
StartServer() {
ipcApi.send("statr-server");
ipcApi.on("confirm-start", (event, arg) => {
console.log(arg);
this.$message({
type: "success",
message: arg
});
});
},
// 获取electron方法
open() {
console.log(this.$electron);
......
/* eslint-disable prefer-promise-reject-errors */
import { login, logout, getInfo } from '@/api/login'
// import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
const user = {
......@@ -37,6 +37,7 @@ const user = {
// }).catch(error => {
// reject(error)
// })
setToken('admin')
commit('SET_TOKEN', 'admin')
resolve()
})
......