默认命令处理优化

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