张恒

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

1 module.exports = { 1 module.exports = {
2 NODE_ENV: '"development"', 2 NODE_ENV: '"development"',
3 - BASE_API: '""' 3 + BASE_API: '"http://127.0.0.1:25565"'
4 } 4 }
......
...@@ -11,5 +11,6 @@ module.exports = { ...@@ -11,5 +11,6 @@ module.exports = {
11 }, 11 },
12 UseStartupChart: true, 12 UseStartupChart: true,
13 IsUseSysTitle: true, 13 IsUseSysTitle: true,
14 - DllFolder: '' 14 + DllFolder: '',
15 + BuiltInServerPort: 25565
15 } 16 }
......
1 module.exports = { 1 module.exports = {
2 NODE_ENV: '"production"', 2 NODE_ENV: '"production"',
3 - BASE_API: '""' 3 + BASE_API: '"http://127.0.0.1:25565"'
4 } 4 }
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
74 "date-fns": "^2.11.0", 74 "date-fns": "^2.11.0",
75 "electron-updater": "^4.2.5", 75 "electron-updater": "^4.2.5",
76 "element-ui": "^2.13.0", 76 "element-ui": "^2.13.0",
77 + "express": "^4.17.1",
77 "fs-extra": "^8.1.0", 78 "fs-extra": "^8.1.0",
78 "js-cookie": "^2.2.1", 79 "js-cookie": "^2.2.1",
79 "nedb": "^1.8.0", 80 "nedb": "^1.8.0",
...@@ -130,7 +131,6 @@ ...@@ -130,7 +131,6 @@
130 "eslint-plugin-node": "^9.2.0", 131 "eslint-plugin-node": "^9.2.0",
131 "eslint-plugin-promise": "^4.2.1", 132 "eslint-plugin-promise": "^4.2.1",
132 "eslint-plugin-standard": "^4.0.0", 133 "eslint-plugin-standard": "^4.0.0",
133 - "express": "^4.17.1",
134 "file-loader": "^5.1.0", 134 "file-loader": "^5.1.0",
135 "happypack": "^5.0.1", 135 "happypack": "^5.0.1",
136 "hard-source-webpack-plugin": "^0.13.1", 136 "hard-source-webpack-plugin": "^0.13.1",
......
1 +/* eslint-disable prefer-promise-reject-errors */
2 +import app from './server'
3 +import http from 'http'
4 +import config from '@config'
5 +const port = config.BuiltInServerPort
6 +app.set('port', port)
7 +
8 +export default {
9 + StatrServer () {
10 + return new Promise((resolve, reject) => {
11 + const server = http.createServer(app)
12 + server.listen(port)
13 + server.on('error', (error) => {
14 + switch (error.code) {
15 + case 'EACCES':
16 + reject('权限不足内置服务器启动失败,请使用管理员权限运行。')
17 + break
18 + case 'EADDRINUSE':
19 + reject('内置服务器端口已被占用,请检查。')
20 + break
21 + default:
22 + reject(error)
23 + }
24 + })
25 + server.on('listening', () => {
26 + resolve('服务端运行中')
27 + })
28 + })
29 + }
30 +}
1 +import express from 'express'
2 +const app = express()
3 +
4 +app.get('/message', (req, res) => {
5 + res.send('这是来自node服务端的信息')
6 +})
7 +
8 +app.post('/message', (req, res) => {
9 + if (req) {
10 + res.send(req + '--来自node')
11 + }
12 +})
13 +
14 +export default app
1 import { ipcMain, dialog } from 'electron' 1 import { ipcMain, dialog } from 'electron'
2 +import Server from '../server/index'
2 export default { 3 export default {
3 Mainfunc (mainWindow, IsUseSysTitle) { 4 Mainfunc (mainWindow, IsUseSysTitle) {
4 ipcMain.on('IsUseSysTitle', (event) => { 5 ipcMain.on('IsUseSysTitle', (event) => {
...@@ -37,5 +38,15 @@ export default { ...@@ -37,5 +38,15 @@ export default {
37 arg.message 38 arg.message
38 ) 39 )
39 }) 40 })
41 + ipcMain.on('statr-server', (event, arg) => {
42 + Server.StatrServer().then(res => {
43 + event.reply('confirm-start', res)
44 + }).catch(err => {
45 + dialog.showErrorBox(
46 + '错误',
47 + err
48 + )
49 + })
50 + })
40 } 51 }
41 } 52 }
......
...@@ -22,3 +22,10 @@ export function logout () { ...@@ -22,3 +22,10 @@ export function logout () {
22 method: 'post' 22 method: 'post'
23 }) 23 })
24 } 24 }
25 +
26 +export function message () {
27 + return request({
28 + url: '/message',
29 + method: 'get'
30 + })
31 +}
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
26 </div> 26 </div>
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>
30 + <el-button type="primary" round @click="getMessage">查看消息</el-button>
29 </div> 31 </div>
30 </div> 32 </div>
31 </main> 33 </main>
...@@ -52,6 +54,7 @@ ...@@ -52,6 +54,7 @@
52 <script> 54 <script>
53 import SystemInformation from "./LandingPage/SystemInformation"; 55 import SystemInformation from "./LandingPage/SystemInformation";
54 import ipcApi from "../utils/ipcRenderer"; 56 import ipcApi from "../utils/ipcRenderer";
57 +import { message } from "@/api/login";
55 export default { 58 export default {
56 name: "landing-page", 59 name: "landing-page",
57 components: { SystemInformation }, 60 components: { SystemInformation },
...@@ -73,12 +76,29 @@ export default { ...@@ -73,12 +76,29 @@ export default {
73 ], 76 ],
74 dialogVisible: false, 77 dialogVisible: false,
75 progressStaus: null, 78 progressStaus: null,
76 - filePath: "", 79 + filePath: ""
77 }), 80 }),
78 created() { 81 created() {
79 - console.log(__lib) 82 + console.log(__lib);
80 }, 83 },
81 methods: { 84 methods: {
85 + getMessage() {
86 + message().then(res => {
87 + this.$alert(res.data, "提示", {
88 + confirmButtonText: "确定"
89 + });
90 + });
91 + },
92 + StartServer() {
93 + ipcApi.send("statr-server");
94 + ipcApi.on("confirm-start", (event, arg) => {
95 + console.log(arg);
96 + this.$message({
97 + type: "success",
98 + message: arg
99 + });
100 + });
101 + },
82 // 获取electron方法 102 // 获取electron方法
83 open() { 103 open() {
84 console.log(this.$electron); 104 console.log(this.$electron);
......
1 /* eslint-disable prefer-promise-reject-errors */ 1 /* eslint-disable prefer-promise-reject-errors */
2 -import { login, logout, getInfo } from '@/api/login' 2 +// import { login, logout, getInfo } from '@/api/login'
3 import { getToken, setToken, removeToken } from '@/utils/auth' 3 import { getToken, setToken, removeToken } from '@/utils/auth'
4 4
5 const user = { 5 const user = {
...@@ -37,6 +37,7 @@ const user = { ...@@ -37,6 +37,7 @@ const user = {
37 // }).catch(error => { 37 // }).catch(error => {
38 // reject(error) 38 // reject(error)
39 // }) 39 // })
40 + setToken('admin')
40 commit('SET_TOKEN', 'admin') 41 commit('SET_TOKEN', 'admin')
41 resolve() 42 resolve()
42 }) 43 })
......