默认命令处理优化

This commit is contained in:
fofolee 2022-05-16 10:52:57 +08:00
parent 4151e1ac89
commit 384f52eb4c
2 changed files with 15 additions and 25 deletions

View File

@ -171,9 +171,7 @@ export default defineComponent({
}); });
this.utools.putDB(statisticsData, "cfg_statisticsData"); this.utools.putDB(statisticsData, "cfg_statisticsData");
// //
this.utools this.utools.delAll("qc_default");
.getDocs("qc_default")
.forEach((x) => this.utools.delDB(x._id));
this.utools.setStorage("st_v300Inited", true); this.utools.setStorage("st_v300Inited", true);
}, },
}, },

View File

@ -205,7 +205,6 @@ import ConfigurationMenu from "components/ConfigurationMenu.vue";
import CommandRunResult from "components/CommandRunResult.vue"; import CommandRunResult from "components/CommandRunResult.vue";
import importAll from "../js/common/importAll.js"; import importAll from "../js/common/importAll.js";
import pinyinMatch from "pinyin-match"; import pinyinMatch from "pinyin-match";
import defaultProfile from "../js/options/defaultProfile.js";
import CommandEditor from "components/CommandEditor"; import CommandEditor from "components/CommandEditor";
// //
@ -322,12 +321,6 @@ export default {
setTimeout(this.getActivatedFeatures, 0); setTimeout(this.getActivatedFeatures, 0);
setTimeout(this.getAllQuickCommands, 0); setTimeout(this.getAllQuickCommands, 0);
}, },
importDefaultCommands() {
this.allQuickCommands = Object.assign(
_.cloneDeep(defaultCommands),
this.allQuickCommands
);
},
// features // features
getActivatedFeatures() { getActivatedFeatures() {
let features = utools.getFeatures(); let features = utools.getFeatures();
@ -344,11 +337,10 @@ export default {
}, },
// //
getAllQuickCommands() { getAllQuickCommands() {
this.allQuickCommands = {}; this.allQuickCommands = _.cloneDeep(defaultCommands);
this.$root.utools this.$root.utools
.getDocs("qc_") .getAll("qc_")
.forEach((x) => (this.allQuickCommands[x.data.features.code] = x.data)); .forEach((x) => (this.allQuickCommands[x.data.features.code] = x.data));
this.importDefaultCommands();
}, },
// //
commandChanged(event) { commandChanged(event) {
@ -426,6 +418,10 @@ export default {
importCommandFromClipboard() { importCommandFromClipboard() {
return window.clipboardReadText(); return window.clipboardReadText();
}, },
//
isDefaultCommand(code) {
return code.slice(0, 8) === "default_";
},
// //
importCommand(fromFile = true) { importCommand(fromFile = true) {
let quickCommandInfo = fromFile let quickCommandInfo = fromFile
@ -438,12 +434,15 @@ export default {
// //
let dataToPushed = {}; let dataToPushed = {};
if (parsedData.single) { if (parsedData.single) {
if (this.isDefaultCommand(parsedData.qc.features.code))
return quickcommand.showMessageBox("默认命令不能导入!", "error");
dataToPushed[parsedData.qc.features.code] = parsedData.qc; dataToPushed[parsedData.qc.features.code] = parsedData.qc;
// //
} else { } else {
dataToPushed = parsedData.qc; dataToPushed = parsedData.qc;
} }
for (var code of Object.keys(dataToPushed)) { for (var code of Object.keys(dataToPushed)) {
if (this.isDefaultCommand(code)) continue;
this.$root.utools.putDB(dataToPushed[code], "qc_" + code); this.$root.utools.putDB(dataToPushed[code], "qc_" + code);
} }
Object.assign(this.allQuickCommands, dataToPushed); Object.assign(this.allQuickCommands, dataToPushed);
@ -481,9 +480,8 @@ export default {
}; };
let commandsToExport = _.cloneDeep(this.allQuickCommands); let commandsToExport = _.cloneDeep(this.allQuickCommands);
// //
if (!utools.isDev())
Object.keys(commandsToExport).forEach((code) => { Object.keys(commandsToExport).forEach((code) => {
if (code.includes("default_")) delete commandsToExport[code]; if (this.isDefaultCommand(code)) delete commandsToExport[code];
}); });
let stringifyCommands = JSON.stringify(commandsToExport); let stringifyCommands = JSON.stringify(commandsToExport);
if (saveAsFile) { if (saveAsFile) {
@ -501,15 +499,9 @@ export default {
if (!isConfirmed) if (!isConfirmed)
return quickcommand.showMessageBox("取消操作", "info"); return quickcommand.showMessageBox("取消操作", "info");
this.exportAllCommands(false); this.exportAllCommands(false);
this.$root.utools this.$root.utools.delAll("qc_");
.getDocs("qc_")
.map((x) => x._id)
.forEach((y) => this.$root.utools.delDB(y));
this.clearAllFeatures(); this.clearAllFeatures();
Object.keys(this.allQuickCommands).forEach((featureCode) => { this.allQuickCommands = _.cloneDeep(defaultCommands);
delete this.allQuickCommands[featureCode];
});
this.importDefaultCommands();
this.currentTag = "默认"; this.currentTag = "默认";
quickcommand.showMessageBox( quickcommand.showMessageBox(
"清空完毕,为防止误操作,已将所有命令复制到剪贴板,可通过导入命令恢复" "清空完毕,为防止误操作,已将所有命令复制到剪贴板,可通过导入命令恢复"