更新服务

This commit is contained in:
24kycj
2024-12-06 20:28:24 +08:00
parent ef7eab3cf9
commit dddb5dd918
52 changed files with 172 additions and 14 deletions
+2 -1
View File
@@ -720,7 +720,8 @@ export default {
},
// 获取模板文件列表
getTemplates() {
fs.readdir('User Templates', (err, files) => {
const filePath = path.join(process.cwd(), 'User Templates');
fs.readdir(filePath, (err, files) => {
if (err) {
console.log(err)
} else {
+2 -1
View File
@@ -9,7 +9,7 @@ import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import store from './store'
import { accAdd, accSub, accMul, accDiv, filterSize } from './utils'
import { accAdd, accSub, accMul, accDiv, filterSize, runCmd } from './utils'
import i18n from './lang' // internationalization
import './permission' // permission control
@@ -24,6 +24,7 @@ Vue.prototype.$accSub = accSub
Vue.prototype.$accMul = accMul
Vue.prototype.$accDiv = accDiv
Vue.prototype.$filterSize = filterSize
Vue.prototype.$runCmd = runCmd
Vue.use(ElementUI, {
size: Cookies.get('size') || 'medium', // set element-ui default size
+4
View File
@@ -524,6 +524,10 @@ const actions = {
closeWebsocket: () => {
// 关闭
if (websock) websock.close()
},
// 改变工作状态
changeWorkStatus: ({ commit }, data) => {
commit('setData', { name: 'workStatus', data: data })
}
}
+16
View File
@@ -473,4 +473,20 @@ export const filterSize = (size) => {
export const pow1024 = (num) => {
return Math.pow(1024, num)
}
// 执行脚本
const { exec } = require('child_process');
export const runCmd = (cmd) => {
return new Promise((resolve, reject) => {
exec(cmd, (err, stdout, stderr) => {
if (err) {
reject(err)
}
if (stderr) {
reject(stderr)
}
resolve(stdout)
})
})
}
+43 -11
View File
@@ -1,5 +1,8 @@
<template>
<div class="container_box">
<div class="container_box" v-loading="serviceLoading"
:element-loading-text="serviceText"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(0, 0, 0, 0.8)">
<!-- 头部 -->
<div class="flex_box flex_row_between top_box">
<div class="flex_box top_left">
@@ -18,7 +21,7 @@
<div class="top_left_line"></div>
<el-tooltip :content="workStatus?'关闭服务':'打开服务'" placement="bottom">
<div class="flex_box flex_row_center top_left_status_box">
<el-switch :disabled="!serviceStatus" @change="serviceChange" class="top_left_status" v-model="workStatus" active-color="#07C160" inactive-color="#aaa"> </el-switch>
<el-switch @change="serviceChange" class="top_left_status" :value="workStatus" active-color="#07C160" inactive-color="#aaa"> </el-switch>
</div>
</el-tooltip>
<div class="flex_box top_left_option">
@@ -299,11 +302,13 @@
let that
let outTimer
let fs = require('fs')
let path = require('path')
import { mapGetters } from 'vuex'
const { app, dialog } = require('@electron/remote')
import UserInfo from '@/components/userInfo/userInfo.vue'
import WorkAdd from '@/components/workAdd/workAdd.vue'
const exePath = process.cwd();
const shPath = path.join(exePath, 'cardsoonServer', 'control.sh')
export default {
name: 'dashboard',
components: { UserInfo, WorkAdd },
@@ -312,6 +317,8 @@ export default {
// 服务状态
isConnect: false,
serviceStatus: false,
serviceLoading: false,
serviceText: '服务关闭中',
// 工作状态
infoStatus: 0,
// 运行选项
@@ -425,6 +432,8 @@ export default {
})
this.taskNum = nums
this.task_list = list
} else {
this.task_list = []
}
},
deep: true,
@@ -516,6 +525,8 @@ export default {
},
mounted() {
that = this
let name = 'ERR_ELECTRON_BUILDER_CANNOT_EXECUTE'
console.log(name.toLowerCase())
},
methods: {
// 服务打开/关闭
@@ -523,16 +534,37 @@ export default {
if (!that.serviceStatus) {
return
}
that.serviceLoading = true
if (e) {
that.store.commit('setData', { name: 'workStatus', data: true })
setTimeout(() => {
that.$store.dispatch('chat/initWebSocket')
}, 500);
that.serviceTextex = '服务启动中'
this.$runCmd(`bash ${shPath} start`).then(res => {
that.$store.dispatch('chat/changeWorkStatus', true)
setTimeout(() => {
that.$store.dispatch('chat/initWebSocket')
that.serviceLoading = false
}, 500);
}).catch(err => {
that.$message({
message: err,
type: 'error'
})
that.serviceLoading = false
})
} else {
that.store.commit('setData', { name: 'workStatus', data: false })
setTimeout(() => {
that.$store.dispatch('chat/closeWebsocket')
}, 500);
that.serviceTextex = '服务关闭中'
this.$runCmd(`bash ${shPath} stop`).then(res => {
that.$store.dispatch('chat/changeWorkStatus', false)
setTimeout(() => {
that.$store.dispatch('chat/closeWebsocket')
that.serviceLoading = false
}, 500);
}).catch(err => {
that.$message({
message: err,
type: 'error'
})
that.serviceLoading = false
})
}
},
// 执行