自动重载

This commit is contained in:
fofolee 2022-04-17 21:03:25 +08:00
parent 661c6b3711
commit 8cd035c020

View File

@ -6,8 +6,10 @@
ref="editor" ref="editor"
@typing=" @typing="
(val) => { (val) => {
$profile.quickFeatures.apiServer.cmd = val; if ($profile.quickFeatures.apiServer.cmd !== val) {
serverStatus && (needRestart = true); $profile.quickFeatures.apiServer.cmd = val;
}
restartServer();
} }
" "
:style="{ :style="{
@ -36,13 +38,13 @@
<span>的参数均会作为本脚本里的变量 </span> <span>的参数均会作为本脚本里的变量 </span>
</div> </div>
<q-btn-group unelevated> <q-btn-group unelevated>
<q-btn flat color="primary" icon="help" /> <q-btn flat color="primary" icon="help" @click="showHelp" />
<q-separator inset vertical /> <q-separator inset vertical />
<q-btn <q-btn
flat flat
color="negative" color="negative"
icon="stop" icon="stop"
v-if="serverStatus && !needRestart" v-if="serverStatus && !restartTimer"
@click="stopServer" @click="stopServer"
label="停止服务" label="停止服务"
/> />
@ -50,9 +52,9 @@
flat flat
color="warning" color="warning"
icon="restart_alt" icon="restart_alt"
v-else-if="serverStatus && needRestart" v-else-if="serverStatus && !!restartTimer"
@click="restartServer" @click="restartServer"
label="重启服务" label="正在重载"
/> />
<q-btn <q-btn
flat flat
@ -77,13 +79,13 @@ export default {
return { return {
bottomHeight: 40, bottomHeight: 40,
serverStatus: this.$profile.quickFeatures.apiServer.serverStatus, serverStatus: this.$profile.quickFeatures.apiServer.serverStatus,
needRestart: null, restartTimer: null,
}; };
}, },
mounted() { mounted() {
this.$refs.editor.setEditorValue(this.$profile.quickFeatures.apiServer.cmd); this.$refs.editor.setEditorValue(this.$profile.quickFeatures.apiServer.cmd);
this.$refs.editor.setEditorLanguage("javascript"); this.$refs.editor.setEditorLanguage("javascript");
this.needRestart = false; this.restartTimer = null;
}, },
methods: { methods: {
enableServer() { enableServer() {
@ -112,15 +114,26 @@ export default {
quickcommand.showMessageBox("关闭服务成功!"); quickcommand.showMessageBox("关闭服务成功!");
}, },
restartServer() { restartServer() {
window.quickcommandHttpServer().stop(); if (!this.serverStatus) return;
window clearTimeout(this.restartTimer);
.quickcommandHttpServer() this.restartTimer = setTimeout(() => {
.run( window.quickcommandHttpServer().stop();
this.$profile.quickFeatures.apiServer.cmd, window
this.$profile.quickFeatures.apiServer.port .quickcommandHttpServer()
); .run(
this.needRestart = false; this.$profile.quickFeatures.apiServer.cmd,
quickcommand.showMessageBox("重启服务成功!"); this.$profile.quickFeatures.apiServer.port
);
this.restartTimer = null;
}, 1000);
},
showHelp() {
utools.ubrowser
.goto("https://www.yuque.com/fofolee-awga0/cpbg1m/bg31vl#GNjEg")
.run({
width: 1380,
height: 750,
});
}, },
}, },
}; };