自动重载

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"
@typing="
(val) => {
$profile.quickFeatures.apiServer.cmd = val;
serverStatus && (needRestart = true);
if ($profile.quickFeatures.apiServer.cmd !== val) {
$profile.quickFeatures.apiServer.cmd = val;
}
restartServer();
}
"
:style="{
@ -36,13 +38,13 @@
<span>的参数均会作为本脚本里的变量 </span>
</div>
<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-btn
flat
color="negative"
icon="stop"
v-if="serverStatus && !needRestart"
v-if="serverStatus && !restartTimer"
@click="stopServer"
label="停止服务"
/>
@ -50,9 +52,9 @@
flat
color="warning"
icon="restart_alt"
v-else-if="serverStatus && needRestart"
v-else-if="serverStatus && !!restartTimer"
@click="restartServer"
label="重启服务"
label="正在重载"
/>
<q-btn
flat
@ -77,13 +79,13 @@ export default {
return {
bottomHeight: 40,
serverStatus: this.$profile.quickFeatures.apiServer.serverStatus,
needRestart: null,
restartTimer: null,
};
},
mounted() {
this.$refs.editor.setEditorValue(this.$profile.quickFeatures.apiServer.cmd);
this.$refs.editor.setEditorLanguage("javascript");
this.needRestart = false;
this.restartTimer = null;
},
methods: {
enableServer() {
@ -112,15 +114,26 @@ export default {
quickcommand.showMessageBox("关闭服务成功!");
},
restartServer() {
window.quickcommandHttpServer().stop();
window
.quickcommandHttpServer()
.run(
this.$profile.quickFeatures.apiServer.cmd,
this.$profile.quickFeatures.apiServer.port
);
this.needRestart = false;
quickcommand.showMessageBox("重启服务成功!");
if (!this.serverStatus) return;
clearTimeout(this.restartTimer);
this.restartTimer = setTimeout(() => {
window.quickcommandHttpServer().stop();
window
.quickcommandHttpServer()
.run(
this.$profile.quickFeatures.apiServer.cmd,
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,
});
},
},
};