快捷命令服务改为内置 feature

This commit is contained in:
fofolee 2022-05-08 23:30:07 +08:00
parent 1e3042d7a0
commit 1b40855578
9 changed files with 105 additions and 56 deletions

View File

@ -52,6 +52,14 @@
"分享中心", "分享中心",
"ShareCenter" "ShareCenter"
] ]
},
{
"code": "server",
"explain": "配置快捷命令后台服务",
"cmds": [
"快捷命令服务配置",
"quickcommandServer"
]
} }
] ]
} }

View File

@ -83,8 +83,8 @@ export default defineComponent({
this.runCronTask(featureCode, cronExp); this.runCronTask(featureCode, cronExp);
}); });
// //
if (this.nativeProfile.apiServerStatus && this.profile.apiServerEnable) { if (this.nativeProfile.serverStatus && this.profile.apiServerEnable) {
window.quickcommandHttpServer().run(this.profile.apiServerPort); window.quickcommandHttpServer().run(this.nativeProfile.serverPort);
console.log("Server Start..."); console.log("Server Start...");
} }
}, },

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -118,36 +118,57 @@
<q-item-section side> <q-item-section side>
<q-icon name="api" /> <q-icon name="api" />
</q-item-section> </q-item-section>
<q-input <q-field dense outlined style="width: 280px">
dense <template v-slot:control>
prefix="开启快捷命令服务" <div
suffix="端口" class="self-center full-width no-outline"
outlined tabindex="0"
v-model="$root.profile.apiServerPort"
input-class="text-center"
style="width: 280px"
type="text"
> >
快捷命令服务
</div>
</template>
<template v-slot:append> <template v-slot:append>
<q-toggle <q-btn
@click="toggleFeature('apiServer')" flat
v-model="$root.profile.apiServerEnable" @click="$router.push('server')"
checked-icon="check" icon="open_in_new"
color="primary"
/> />
</template> </template>
<q-tooltip <q-tooltip
>启用后在主输入框输入快捷命令服务可以进入配置一个后台服务<br /> >通过本地监听
通过本地监听{{ {{ $root.nativeProfile.serverPort }}
$root.profile.apiServerPort 端口的形式接收用户传送过来的参数然后根据参数执行不同的操作
}}端口的形式接收用户传送过来的参数然后根据参数执行不同的操作
<br /> <br />
本功能的意义在于 utools 需要配置插件跟随 utools 启动和保留后台<br />
的接口暴露出来可以通过命令行等外部途径 <br /> 也可在主输入框通过关键字快捷命令服务配置进入
直接启用 ubrowser 或者直接redirect 到相应的插件<br />
需要配置插件跟随 utools 启动和保留后台
</q-tooltip> </q-tooltip>
</q-input> </q-field>
</q-item>
<q-item>
<q-item-section side>
<q-icon name="code" />
</q-item-section>
<q-field dense outlined style="width: 280px">
<template v-slot:control>
<div
class="self-center full-width no-outline"
tabindex="0"
>
运行代码
</div>
</template>
<template v-slot:append>
<q-btn
flat
@click="$router.push('code')"
icon="open_in_new"
/>
</template>
<q-tooltip
>一个可以直接运行代码的代码编辑器<br />
也可在主输入框输入关键字RunCode进入
</q-tooltip>
</q-field>
</q-item> </q-item>
</q-list> </q-list>
</q-menu> </q-menu>
@ -384,6 +405,7 @@ export default {
showAbout: false, showAbout: false,
showPanelConf: false, showPanelConf: false,
features: features, features: features,
redirect: utools.redirect,
}; };
}, },
computed: { computed: {
@ -457,7 +479,7 @@ export default {
this.$root.utools.whole.setFeature(_.cloneDeep(this.features[type])); this.$root.utools.whole.setFeature(_.cloneDeep(this.features[type]));
if (type === "apiServer" && !this.$root.profile.apiServerEnable) { if (type === "apiServer" && !this.$root.profile.apiServerEnable) {
window.quickcommandHttpServer().stop(); window.quickcommandHttpServer().stop();
this.$root.nativeProfile.apiServerStatus = false; this.$root.nativeProfile.serverStatus = false;
} }
}, },
}, },

View File

@ -12,11 +12,10 @@ export default {
quickUrlTag: "网址", quickUrlTag: "网址",
pluNickNameEnable: false, pluNickNameEnable: false,
pluNickNameTag: "别名", pluNickNameTag: "别名",
apiServerEnable: false,
apiServerPort: 33442,
}, },
native: { native: {
crontabs: {}, crontabs: {},
apiServerStatus: false serverPort: 33442,
serverStatus: false
} }
} }

View File

@ -42,13 +42,6 @@ const quickFeatures = {
cmds: ["插件别名"], cmds: ["插件别名"],
icon: require("../../assets/feature/plugin.png"), icon: require("../../assets/feature/plugin.png"),
platform: ["win32", "darwin", "linux"], platform: ["win32", "darwin", "linux"],
},
apiServer: {
code: "feature_apiServer",
explain: "配置快捷命令后台服务",
cmds: ["快捷命令服务配置", "quickcommandServer"],
icon: require("../../assets/feature/api.png"),
platform: ["win32", "darwin", "linux"],
} }
} }

View File

@ -4,7 +4,6 @@
<script> <script>
import PluginNickName from "components/quickFeatures/PluginNickName"; import PluginNickName from "components/quickFeatures/PluginNickName";
import ApiServer from "components/quickFeatures/ApiServer";
import FavFile from "components/quickFeatures/FavFile"; import FavFile from "components/quickFeatures/FavFile";
import FavUrl from "components/quickFeatures/FavUrl"; import FavUrl from "components/quickFeatures/FavUrl";
import { markRaw } from "vue"; import { markRaw } from "vue";
@ -12,7 +11,6 @@ import { markRaw } from "vue";
export default { export default {
components: { components: {
pluNickName: markRaw(PluginNickName), pluNickName: markRaw(PluginNickName),
apiServer: markRaw(ApiServer),
favFile: markRaw(FavFile), favFile: markRaw(FavFile),
favUrl: markRaw(FavUrl), favUrl: markRaw(FavUrl),
}, },

View File

@ -28,10 +28,19 @@
height: bottomHeight + 'px', height: bottomHeight + 'px',
}" }"
> >
<div class="q-gutter-xs"> <div class="q-gutter-xs flex items-center full-height content-center">
<q-badge color="primary" dense square>POST</q-badge <q-badge color="primary" dense square>POST</q-badge
><q-badge color="primary" dense square>GET</q-badge> ><q-badge color="primary" dense square>GET</q-badge>
<span> http://127.0.0.1:{{ $root.profile.apiServerPort }} </span> <span> http://127.0.0.1:</span>
<q-input
borderless
dense
v-model="$root.nativeProfile.serverPort"
style="width: 40px"
input-class="text-weight-bolder"
@blur="restartServer"
><q-tooltip>点击修改端口</q-tooltip></q-input
>
<span>的参数均会作为本脚本里的变量 </span> <span>的参数均会作为本脚本里的变量 </span>
</div> </div>
<q-btn-group unelevated> <q-btn-group unelevated>
@ -51,7 +60,7 @@
flat flat
color="negative" color="negative"
icon="stop" icon="stop"
v-if="$root.nativeProfile.apiServerStatus" v-if="$root.nativeProfile.serverStatus"
@click="stopServer" @click="stopServer"
label="停止服务" label="停止服务"
/> />
@ -97,16 +106,29 @@ export default {
"FBI WARNING" "FBI WARNING"
) )
.then(() => { .then(() => {
this.$root.nativeProfile.apiServerStatus = true; this.$root.nativeProfile.serverStatus = true;
window.quickcommandHttpServer().run(this.$root.profile.apiServerPort); window
.quickcommandHttpServer()
.run(this.$root.nativeProfile.serverPort);
quickcommand.showMessageBox("启动服务成功!"); quickcommand.showMessageBox("启动服务成功!");
}); });
}, },
stopServer() { stopServer() {
window.quickcommandHttpServer().stop(); window.quickcommandHttpServer().stop();
this.$root.nativeProfile.apiServerStatus = false; this.$root.nativeProfile.serverStatus = false;
quickcommand.showMessageBox("关闭服务成功!"); quickcommand.showMessageBox("关闭服务成功!");
}, },
restartServer() {
if (!this.$root.nativeProfile.serverPort)
this.$root.nativeProfile.serverPort = 33442;
if ((this.$root.nativeProfile.serverStatus = true)) {
window.quickcommandHttpServer().stop();
window
.quickcommandHttpServer()
.run(this.$root.nativeProfile.serverPort);
quickcommand.showMessageBox("服务已重启");
}
},
saveCode() { saveCode() {
clearTimeout(this.saveCodeTimer); clearTimeout(this.saveCodeTimer);
this.saveCodeTimer = setTimeout(() => { this.saveCodeTimer = setTimeout(() => {

View File

@ -2,54 +2,61 @@ const routes = [{
path: '/configuration', path: '/configuration',
name: 'configuration', name: 'configuration',
component: () => component: () =>
import('pages/ConfigurationPage.vue') import ('pages/ConfigurationPage.vue')
}, },
{ {
path: '/code', path: '/code',
name: 'code', name: 'code',
component: () => component: () =>
import('pages/RunCodePage.vue') import ('pages/RunCodePage.vue')
}, },
{ {
path: '/newcommand', path: '/newcommand',
name: 'newcommand', name: 'newcommand',
component: () => component: () =>
import('pages/ConfigurationPage.vue') import ('pages/ConfigurationPage.vue')
}, },
{ {
path: '/:type(default|files|img|key|regex|window|professional)_:uid(\\w+)', path: '/:type(default|files|img|key|regex|window|professional)_:uid(\\w+)',
name: 'command', name: 'command',
component: () => component: () =>
import('pages/CommandPage.vue') import ('pages/CommandPage.vue')
}, },
{ {
path: '/panel_:tags(\\w+)', path: '/panel_:tags(\\w+)',
name: 'panel', name: 'panel',
component: () => component: () =>
import('pages/ConfigurationPage.vue') import ('pages/ConfigurationPage.vue')
}, },
{ {
path: '/needupdate', path: '/needupdate',
name: 'needupdate', name: 'needupdate',
props: true, props: true,
component: () => component: () =>
import('pages/updateWarningPage.vue') import ('pages/updateWarningPage.vue')
}, },
{ {
path: '/', path: '/',
name: 'loading', name: 'loading',
component: () => component: () =>
import('pages/LoadingPage.vue') import ('pages/LoadingPage.vue')
}, { }, {
path: '/share', path: '/share',
name: 'share', name: 'share',
component: () => component: () =>
import('pages/ShareCenterPage.vue') import ('pages/ShareCenterPage.vue')
}, },
{ {
path: '/feature_:featuretype(\\w+)', path: '/feature_:featuretype(\\w+)',
name: 'feature', name: 'feature',
component: () => import('pages/quickFeaturesPage.vue') component: () =>
import ('pages/FeaturesPage.vue')
},
{
path: '/server',
name: 'server',
component: () =>
import ('pages/ServerPage.vue')
} }
] ]