更改全局变量存储方式

This commit is contained in:
fofolee
2022-04-19 00:06:22 +08:00
parent a27fe4c338
commit ca01808c93
19 changed files with 209 additions and 180 deletions

View File

@@ -36,8 +36,8 @@
dense
flat
round
color="blue-9"
icon="insights"
:color="!!cronExp ? 'amber' : 'blue-9'"
:icon="!!cronExp ? 'timer' : 'insights'"
>
<q-tooltip anchor="top middle" self="center middle">
设置
@@ -79,9 +79,9 @@
<q-item-section side>
<q-icon name="timer" />
</q-item-section>
<q-item-section>添加定时任务</q-item-section>
<q-item-section>定时任务</q-item-section>
<q-tooltip
>定时执行当前命令仅匹配类型为关键字时可用</q-tooltip
>在后台定时执行当前命令仅匹配类型为关键字时可用且一律忽略输出</q-tooltip
>
</q-item>
</q-list>
@@ -231,8 +231,7 @@
</div>
<q-dialog v-model="showCrontab">
<CrontabSetting
:cronStatus="$profile.crontabs[featureCode]?.status"
:cronExp="$profile.crontabs[featureCode]?.cronExp"
:cronExp="cronExp"
@addCrontab="addCrontab"
@delCrontab="delCrontab"
/>
@@ -249,7 +248,7 @@ export default {
components: { CrontabSetting },
data() {
return {
allProgrammings: this.$programmings,
allProgrammings: this.$root.programs,
maxCmdStingLen: 8,
commandTypes: commandTypes,
platformTypes: platformTypes,
@@ -314,6 +313,9 @@ export default {
featureCode() {
return this.commandInfo.features.code;
},
cronExp() {
return this.$root.profile.crontabs[this.featureCode];
},
},
props: {
commandInfo: Object,
@@ -358,19 +360,12 @@ export default {
this.$emit("commandChanged", event);
},
addCrontab(cronExp) {
this.$profile.crontabs[this.featureCode] = {
cronStatus: true,
cronExp: cronExp,
};
this.cronJob = this.$Cron(cronExp, () => {
this.runCommand();
});
this.$root.profile.crontabs[this.featureCode] = cronExp;
this.$root.runCronTask(this.featureCode, cronExp);
},
delCrontab() {
this.$profile.crontabs[this.featureCode] = {
cronStatus: false,
};
this.cronJob.stop();
delete this.$root.profile.crontabs[this.featureCode];
this.$root.cronJobs[this.featureCode].stop();
},
// 启用/禁用命令
toggleCommandActivated() {

View File

@@ -61,13 +61,13 @@
>
<template v-slot:append>
<q-avatar size="lg" square>
<img :src="$programmings[quickcommandInfo.program].icon" />
<img :src="$root.programs[quickcommandInfo.program].icon" />
</q-avatar>
</template>
<template v-slot:option="scope">
<q-item v-bind="scope.itemProps">
<q-item-section avatar>
<img width="32" :src="$programmings[scope.opt].icon" />
<img width="32" :src="$root.programs[scope.opt].icon" />
</q-item-section>
<q-item-section>
<q-item-label v-html="scope.opt" />
@@ -166,7 +166,7 @@ export default {
components: { MonacoEditor, CommandSideBar, CommandRunResult },
data() {
return {
programLanguages: Object.keys(this.$programmings),
programLanguages: Object.keys(this.$root.programs),
sideBarWidth: 250,
languageBarHeight: 40,
canCommandSave: this.action.type === "code" ? false : true,
@@ -214,7 +214,7 @@ export default {
init() {
let quickCommandInfo =
this.action.type !== "edit"
? this.$utools.getDB(this.$utools.DBPRE.CFG + "preferences")
? this.$root.utools.getDB(this.$root.utools.DBPRE.CFG + "preferences")
?.codeHistory[this.action.type]
: this.action.data;
quickCommandInfo?.program &&
@@ -234,7 +234,7 @@ export default {
},
// 匹配编程语言
matchLanguage() {
let language = Object.values(this.$programmings).filter(
let language = Object.values(this.$root.programs).filter(
(program) => program.ext === this.quickcommandInfo.customOptions.ext
);
if (language.length) {
@@ -243,7 +243,7 @@ export default {
},
// 设置编程语言
setLanguage(language) {
let highlight = this.$programmings[language].highlight;
let highlight = this.$root.programs[language].highlight;
this.$refs.editor.setEditorLanguage(highlight ? highlight : language);
},
// 打开文档
@@ -330,9 +330,9 @@ export default {
if (!updatedData) return;
Object.assign(this.quickcommandInfo, _.cloneDeep(updatedData));
let newQuickcommandInfo = _.cloneDeep(this.quickcommandInfo);
this.$utools.putDB(
this.$root.utools.putDB(
newQuickcommandInfo,
this.$utools.DBPRE.QC + this.quickcommandInfo.features.code
this.$root.utools.DBPRE.QC + this.quickcommandInfo.features.code
);
this.$emit("editorEvent", {
type: "save",

View File

@@ -106,9 +106,10 @@ export default {
!outPlugin && this.showRunResult(stdout, true, action);
});
} else {
let option = this.$programmings[currentCommand.program];
if (currentCommand.program === "custom")
option = currentCommand.customOptions;
let option =
currentCommand.program === "custom"
? currentCommand.customOptions
: this.$root.programs[currentCommand.program];
option.scptarg = currentCommand.scptarg;
option.charset = currentCommand.charset;
window.runCodeFile(

View File

@@ -331,7 +331,8 @@ export default {
},
setIcon(language) {
this.currentCommand.features.icon?.slice(0, 10) === "data:image" ||
(this.currentCommand.features.icon = this.$programmings[language].icon);
(this.currentCommand.features.icon =
this.$root.programs[language].icon);
},
getCommandType() {
let data = { type: "key", match: [] };

View File

@@ -32,20 +32,20 @@
input-class="text-center"
style="width: 280px"
autofocus
v-model="quickFeatures.favFile.tag"
v-model="$root.profile.quickFeatures.favFile.tag"
type="text"
>
<template v-slot:append>
<q-toggle
@click="toggleFeature('favFile')"
v-model="quickFeatures.favFile.enable"
v-model="$root.profile.quickFeatures.favFile.enable"
checked-icon="check"
color="primary"
/>
</template>
<q-tooltip
>启用后选中文件可以通过超级面板快速将文件收藏到{{
quickFeatures.favFile.tag
$root.profile.quickFeatures.favFile.tag
}}标签
</q-tooltip>
</q-input>
@@ -61,20 +61,20 @@
outlined
input-class="text-center"
style="width: 280px"
v-model="quickFeatures.favUrl.tag"
v-model="$root.profile.quickFeatures.favUrl.tag"
type="text"
>
<template v-slot:append>
<q-toggle
@click="toggleFeature('favUrl')"
v-model="quickFeatures.favUrl.enable"
v-model="$root.profile.quickFeatures.favUrl.enable"
checked-icon="check"
color="primary"
/>
</template>
<q-tooltip
>启用后在浏览器界面可以通过超级面板快速将网址收藏到{{
quickFeatures.favUrl.tag
$root.profile.quickFeatures.favUrl.tag
}}标签
</q-tooltip>
</q-input>
@@ -91,13 +91,13 @@
input-class="text-center"
style="width: 280px"
autofocus
v-model="quickFeatures.pluNickName.tag"
v-model="$root.profile.quickFeatures.pluNickName.tag"
type="text"
>
<template v-slot:append>
<q-toggle
@click="toggleFeature('pluNickName')"
v-model="quickFeatures.pluNickName.enable"
v-model="$root.profile.quickFeatures.pluNickName.enable"
checked-icon="check"
color="primary"
/>
@@ -105,7 +105,7 @@
<q-tooltip
>启用后在主输入框输入插件别名可以快速设置插件别名<br />
并将所有设置的别名保存至{{
quickFeatures.pluNickName.tag
$root.profile.quickFeatures.pluNickName.tag
}}标签
</q-tooltip>
</q-input>
@@ -119,7 +119,7 @@
prefix="开启快捷命令服务"
suffix="端口"
outlined
v-model="quickFeatures.apiServer.port"
v-model="$root.profile.quickFeatures.apiServer.port"
input-class="text-center"
style="width: 280px"
type="text"
@@ -127,7 +127,7 @@
<template v-slot:append>
<q-toggle
@click="toggleFeature('apiServer')"
v-model="quickFeatures.apiServer.enable"
v-model="$root.profile.quickFeatures.apiServer.enable"
checked-icon="check"
color="primary"
/>
@@ -135,7 +135,7 @@
<q-tooltip
>启用后在主输入框输入快捷命令服务可以进入配置一个后台服务<br />
通过本地监听{{
quickFeatures.apiServer.port
$root.profile.quickFeatures.apiServer.port
}}端口的形式接收用户传送过来的参数然后根据参数执行不同的操作
<br />
本功能的意义在于 utools
@@ -233,7 +233,7 @@
no-header
no-footer
@change="setPrimaryColor"
v-model="primaryColor"
v-model="$root.profile.primaryColor"
/>
<q-btn
color="primary"
@@ -343,7 +343,6 @@ export default {
selectFile: ref(null),
showAbout: false,
showPanelConf: false,
quickFeatures: this.$profile.quickFeatures,
features: features,
};
},
@@ -391,21 +390,21 @@ export default {
},
// 设置主题色
setPrimaryColor() {
this.setCssVar("primary", this.$profile.primaryColor);
this.setCssVar("primary", this.$root.profile.primaryColor);
},
// 重置主题色
resetPrimary() {
this.$profile.primaryColor = this.$profile.defaultPrimaryColor;
this.$root.profile.primaryColor = this.$root.profile.defaultPrimaryColor;
this.setPrimaryColor();
},
// 修改面板视图背景
changeBackground(reset = false) {
this.$profile.backgroundImg = reset ? null : this.selectFile.path;
this.$root.profile.backgroundImg = reset ? null : this.selectFile.path;
this.configurationPage.$forceUpdate();
},
// 取消收藏
unMarkTag() {
this.$utools.whole.removeFeature(
this.$root.utools.whole.removeFeature(
`panel_${window.hexEncode(this.currentTag)}`
);
_.pull(this.$root.$refs.view.activatedQuickPanels, this.currentTag);
@@ -413,8 +412,8 @@ export default {
},
// 实用功能
toggleFeature(type) {
this.$utools.whole.removeFeature(this.features[type].code) ||
this.$utools.whole.setFeature(_.cloneDeep(this.features[type]));
this.$root.utools.whole.removeFeature(this.features[type].code) ||
this.$root.utools.whole.setFeature(_.cloneDeep(this.features[type]));
},
},
};

View File

@@ -54,7 +54,7 @@
flat
color="negative"
icon="alarm_off"
v-if="cronStatus"
v-if="!!cronExp"
@click="delCrontab"
label="禁用"
/>
@@ -71,22 +71,24 @@
</template>
<script>
import Cron from "croner";
export default {
data() {
return {
cronDetail: {
default: {
min: { label: "分钟", value: "" },
hour: { label: "小时", value: "" },
day: { label: "天", value: "*" },
month: { label: "月", value: "*" },
week: { label: "星期", value: "*" },
},
cronDetail: {},
intervalId: null,
nextLeftTime: null,
};
},
props: {
cronStatus: Boolean,
cronExp: String,
},
computed: {
@@ -97,7 +99,7 @@ export default {
},
cronJob() {
try {
return this.$Cron(this.cronConverted);
return Cron(this.cronConverted);
} catch (error) {
return null;
}
@@ -127,6 +129,7 @@ export default {
window.showHelpPage("#Q0e7s");
},
initValue() {
this.cronDetail = _.cloneDeep(this.default);
if (!this.cronExp) return;
let splited = this.cronExp.split(" ");
Object.keys(this.cronDetail).forEach((key, index) => {
@@ -146,6 +149,7 @@ export default {
},
delCrontab() {
this.$emit("delCrontab");
this.cronDetail = _.cloneDeep(this.default);
quickcommand.showMessageBox("禁用成功");
},
},

View File

@@ -71,7 +71,7 @@ export default {
},
methods: {
markTag() {
this.$utools.whole.setFeature(_.cloneDeep(this.features));
this.$root.utools.whole.setFeature(_.cloneDeep(this.features));
this.$root.$refs.view.activatedQuickPanels.push(this.currentTag);
quickcommand.showMessageBox(
`主输入框输入『${this.features.cmds.join("、")}』即可直接进入『${

View File

@@ -6,8 +6,8 @@
ref="editor"
@typing="
(val) => {
if ($profile.quickFeatures.apiServer.cmd !== val) {
$profile.quickFeatures.apiServer.cmd = val;
if ($root.profile.quickFeatures.apiServer.cmd !== val) {
$root.profile.quickFeatures.apiServer.cmd = val;
}
restartServer();
}
@@ -33,7 +33,7 @@
<q-badge color="primary" dense square>POST</q-badge
><q-badge color="primary" dense square>GET</q-badge>
<span>
http://127.0.0.1:{{ $profile.quickFeatures.apiServer.port }}
http://127.0.0.1:{{ $root.profile.quickFeatures.apiServer.port }}
</span>
<span>的参数均会作为本脚本里的变量 </span>
</div>
@@ -44,7 +44,9 @@
flat
color="negative"
icon="stop"
v-if="serverStatus && !restartTimer"
v-if="
$root.profile.quickFeatures.apiServer.serverStatus && !restartTimer
"
@click="stopServer"
label="停止服务"
/>
@@ -52,7 +54,9 @@
flat
color="warning"
icon="restart_alt"
v-else-if="serverStatus && !!restartTimer"
v-else-if="
$root.profile.quickFeatures.apiServer.serverStatus && !!restartTimer
"
@click="restartServer"
label="正在重载"
/>
@@ -78,12 +82,13 @@ export default {
data() {
return {
bottomHeight: 40,
serverStatus: this.$profile.quickFeatures.apiServer.serverStatus,
restartTimer: null,
};
},
mounted() {
this.$refs.editor.setEditorValue(this.$profile.quickFeatures.apiServer.cmd);
this.$refs.editor.setEditorValue(
this.$root.profile.quickFeatures.apiServer.cmd
);
this.$refs.editor.setEditorLanguage("javascript");
this.restartTimer = null;
},
@@ -96,33 +101,31 @@ export default {
)
.then((ok) => {
if (!ok) return;
this.$profile.quickFeatures.apiServer.serverStatus =
this.serverStatus = true;
this.$root.profile.quickFeatures.apiServer.serverStatus = true;
window
.quickcommandHttpServer()
.run(
this.$profile.quickFeatures.apiServer.cmd,
this.$profile.quickFeatures.apiServer.port
this.$root.profile.quickFeatures.apiServer.cmd,
this.$root.profile.quickFeatures.apiServer.port
);
quickcommand.showMessageBox("启动服务成功!");
});
},
stopServer() {
window.quickcommandHttpServer().stop();
this.$profile.quickFeatures.apiServer.serverStatus =
this.serverStatus = false;
this.$root.profile.quickFeatures.apiServer.serverStatus = false;
quickcommand.showMessageBox("关闭服务成功!");
},
restartServer() {
if (!this.serverStatus) return;
if (!this.$root.profile.quickFeatures.apiServer.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.$root.profile.quickFeatures.apiServer.cmd,
this.$root.profile.quickFeatures.apiServer.port
);
this.restartTimer = null;
}, 1000);

View File

@@ -21,7 +21,7 @@ export default {
program: "quickcommand",
cmd: `open(\"${file.path.replace(/\\/g, "\\\\")}\")`,
output: "ignore",
tags: [this.$profile.quickFeatures.favFile.tag],
tags: [this.$root.profile.quickFeatures.favFile.tag],
};
this.importCommand(command);
});

View File

@@ -47,7 +47,7 @@ export default {
program: "quickcommand",
cmd: `visit(\"${url}\")\n`,
output: "ignore",
tags: [this.$profile.quickFeatures.favUrl.tag],
tags: [this.$root.profile.quickFeatures.favUrl.tag],
};
try {
let res = await quickcommand.downloadFile(iconUrl, iconPath);

View File

@@ -127,7 +127,7 @@ export default {
program: "quickcommand",
cmd: `utools.redirect("${this.feature.cmd}");utools.showMainWindow()`,
output: "ignore",
tags: [this.$profile.quickFeatures.pluNickName.tag],
tags: [this.$root.profile.quickFeatures.pluNickName.tag],
};
this.importCommand(command);
this.nickName = [];