将用户配置分为通用和本机

This commit is contained in:
fofolee 2022-05-07 00:53:31 +08:00
parent 91c4e48888
commit f3a2ad4a62
12 changed files with 66 additions and 93 deletions

View File

@ -21,7 +21,8 @@ export default defineComponent({
return {
setCssVar: setCssVar,
programs: programmings,
profile: defaultProfile,
profile: defaultProfile.common,
nativeProfile: defaultProfile.native,
utools: UTOOLS,
cronJobs: {},
enterData: {},
@ -60,12 +61,14 @@ export default defineComponent({
//
this.v2DataHandler();
//
let userProfile = this.utools.getDB(
this.utools.DBPRE.CFG + "preferences"
let commonProfile = this.utools.getDB("cfg_profile");
let nativeProfile = this.utools.getDB(
"cfg_" + utools.getNativeId() + "_profile"
);
this.profile = _.merge(
_.cloneDeep(defaultProfile),
_.cloneDeep(userProfile)
this.profile = Object.assign(_.cloneDeep(this.profile), commonProfile);
this.nativeProfile = Object.assign(
_.cloneDeep(this.nativeProfile),
nativeProfile
);
//
this.setCssVar("primary", this.profile.primaryColor);
@ -76,17 +79,12 @@ export default defineComponent({
if (window.multiProcessDetection())
return console.log("multiProcess Detected");
//
_.forIn(this.profile.crontabs, (cronExp, featureCode) => {
_.forIn(this.nativeProfile.crontabs, (cronExp, featureCode) => {
this.runCronTask(featureCode, cronExp);
});
//
if (this.profile.quickFeatures.apiServer.serverStatus) {
window
.quickcommandHttpServer()
.run(
this.profile.quickFeatures.apiServer.cmd,
this.profile.apiServerPort
);
if (this.nativeProfile.apiServerStatus) {
window.quickcommandHttpServer().run(this.profile.apiServerPort);
console.log("Server Start...");
}
},
@ -98,9 +96,10 @@ export default defineComponent({
this.$router.push(enter.code);
},
outPlugin() {
this.utools.putDB(_.cloneDeep(this.profile), "cfg_profile");
this.utools.putDB(
_.cloneDeep(this.profile),
this.utools.DBPRE.CFG + "preferences"
_.cloneDeep(this.nativeProfile),
"cfg_" + utools.getNativeId() + "_profile"
);
this.$refs.view.$refs?.commandEditor?.saveCodeHistory();
this.$router.push("/");
@ -111,7 +110,7 @@ export default defineComponent({
});
},
runCommandSilently(featureCode) {
let command = this.utools.getDB(this.utools.DBPRE.QC + featureCode);
let command = this.utools.getDB("qc_" + featureCode);
if (command.program === "quickcommand") {
window.runCodeInSandbox(command.cmd, () => {});
} else {
@ -125,9 +124,7 @@ export default defineComponent({
}
},
usageStatistics(featureCode, runTime) {
let statisticsData = this.utools.getDB(
this.utools.DBPRE.CFG + "statisticsData"
);
let statisticsData = this.utools.getDB("cfg_statisticsData");
let thisYear = runTime.year;
if (!statisticsData[thisYear]) statisticsData[thisYear] = [];
statisticsData[thisYear].push({
@ -139,10 +136,7 @@ export default defineComponent({
minute: runTime.minute,
},
});
this.utools.putDB(
statisticsData,
this.utools.DBPRE.CFG + "statisticsData"
);
this.utools.putDB(statisticsData, "cfg_statisticsData");
},
parseDate: (dateString) => {
return {
@ -155,14 +149,10 @@ export default defineComponent({
};
},
v2DataHandler() {
let v2DataHandled = this.utools.getStorage(
this.utools.DBPRE.STATUS + "v2DataHandled"
);
let v2DataHandled = this.utools.getStorage("st_v2DataHandled");
if (v2DataHandled) return;
//
let statisticsData = this.utools.getDB(
this.utools.DBPRE.CFG + "statisticsData"
);
let statisticsData = this.utools.getDB("cfg_statisticsData");
_.forIn(statisticsData, (data, year) => {
statisticsData[year] = data.map((x) => {
let code =
@ -173,13 +163,10 @@ export default defineComponent({
};
});
});
this.utools.putDB(
statisticsData,
this.utools.DBPRE.CFG + "statisticsData"
);
this.utools.putDB(statisticsData, "cfg_statisticsData");
//
// ...
this.utools.setStorage(this.utools.DBPRE.STATUS + "v2DataHandled", true);
this.utools.setStorage("st_v2DataHandled", true);
},
},
});

View File

@ -320,7 +320,7 @@ export default {
return this.commandInfo.features.code;
},
cronExp() {
return this.$root.profile.crontabs[this.featureCode];
return this.$root.nativeProfile.crontabs[this.featureCode];
},
},
props: {
@ -363,11 +363,11 @@ export default {
this.$emit("commandChanged", event);
},
addCrontab(cronExp) {
this.$root.profile.crontabs[this.featureCode] = cronExp;
this.$root.nativeProfile.crontabs[this.featureCode] = cronExp;
this.$root.runCronTask(this.featureCode, cronExp);
},
delCrontab() {
delete this.$root.profile.crontabs[this.featureCode];
delete this.$root.nativeProfile.crontabs[this.featureCode];
this.$root.cronJobs[this.featureCode].stop();
},
// /

View File

@ -301,7 +301,7 @@ export default {
init() {
let quickCommandInfo =
this.action.type === "run"
? this.$root.utools.getDB(this.$root.utools.DBPRE.CFG + "codeHistory")
? this.$root.utools.getDB("cfg_codeHistory")
: this.action.data;
quickCommandInfo?.program &&
Object.assign(this.quickcommandInfo, _.cloneDeep(quickCommandInfo));
@ -360,7 +360,7 @@ export default {
let newQuickcommandInfo = _.cloneDeep(this.quickcommandInfo);
this.$root.utools.putDB(
newQuickcommandInfo,
this.$root.utools.DBPRE.QC + this.quickcommandInfo.features.code
"qc_" + this.quickcommandInfo.features.code
);
this.$emit("editorEvent", {
type: "save",
@ -380,10 +380,7 @@ export default {
if (this.action.type !== "run") return;
let command = _.cloneDeep(this.quickcommandInfo);
command.cursorPosition = this.$refs.editor.getCursorPosition();
this.$root.utools.putDB(
command,
this.$root.utools.DBPRE.CFG + "codeHistory"
);
this.$root.utools.putDB(command, "cfg_codeHistory");
},
monacoKeyStroke(event) {
switch (event) {

View File

@ -457,7 +457,7 @@ export default {
this.$root.utools.whole.setFeature(_.cloneDeep(this.features[type]));
if (type === "apiServer" && !this.$root.profile.apiServerEnable) {
window.quickcommandHttpServer().stop();
this.$root.profile.quickFeatures.apiServer.serverStatus = false;
this.$root.nativeProfile.apiServerStatus = false;
}
},
},

View File

@ -155,7 +155,7 @@ export default {
}
},
showHelp() {
window.showUb.help('#rWU2i')
window.showUb.help("#rWU2i");
},
joinRepo() {
quickcommand
@ -167,13 +167,10 @@ export default {
});
},
loadYuQueInfo() {
return this.$root.utools.getDB(this.$root.utools.DBPRE.CFG + "extraInfo");
return this.$root.utools.getDB("cfg_extraInfo");
},
saveYuQueInfo() {
this.$root.utools.putDB(
_.cloneDeep(this.yuQueInfo),
this.$root.utools.DBPRE.CFG + "extraInfo"
);
this.$root.utools.putDB(_.cloneDeep(this.yuQueInfo), "cfg_extraInfo");
},
},
};

View File

@ -170,9 +170,7 @@ export default {
methods: {
getUserInfo() {
Object.assign(this.userInfo, this.$root.utools.whole.getUser());
let statisticsData = this.$root.utools.getDB(
this.$root.utools.DBPRE.CFG + "statisticsData"
);
let statisticsData = this.$root.utools.getDB("cfg_statisticsData");
this.userInfo.exp = Object.values(statisticsData)
.map((x) => x.length)
.reduce((x, y) => x + y);

View File

@ -51,7 +51,7 @@
flat
color="negative"
icon="stop"
v-if="$root.profile.quickFeatures.apiServer.serverStatus"
v-if="$root.nativeProfile.apiServerStatus"
@click="stopServer"
label="停止服务"
/>
@ -97,14 +97,14 @@ export default {
"FBI WARNING"
)
.then(() => {
this.$root.profile.quickFeatures.apiServer.serverStatus = true;
this.$root.nativeProfile.apiServerStatus = true;
window.quickcommandHttpServer().run(this.$root.profile.apiServerPort);
quickcommand.showMessageBox("启动服务成功!");
});
},
stopServer() {
window.quickcommandHttpServer().stop();
this.$root.profile.quickFeatures.apiServer.serverStatus = false;
this.$root.nativeProfile.apiServerStatus = false;
quickcommand.showMessageBox("关闭服务成功!");
},
saveCode() {

View File

@ -1,16 +1,22 @@
export default {
commandCardStyle: "normal",
primaryColor: "#009688",
defaultPrimaryColor: "#009688",
backgroundImg: null,
autofocusSearch: false,
denseTagBar: false,
quickFileEnable: false,
quickFileTag: "文件",
quickUrlEnable: false,
quickUrlTag: "网址",
pluNickNameEnable: false,
pluNickNameTag: "别名",
apiServerEnable: false,
apiServerPort: 33442,
common: {
commandCardStyle: "normal",
primaryColor: "#009688",
defaultPrimaryColor: "#009688",
backgroundImg: null,
autofocusSearch: false,
denseTagBar: false,
quickFileEnable: false,
quickFileTag: "文件",
quickUrlEnable: false,
quickUrlTag: "网址",
pluNickNameEnable: false,
pluNickNameTag: "别名",
apiServerEnable: false,
apiServerPort: 33442,
},
native: {
crontabs: {},
apiServerStatus: false
}
}

View File

@ -10,7 +10,7 @@ let whole = window.utools
const DBPRE = {
QC: 'qc_', // 快捷命令
CFG: 'cfg_', // 配置
PAN: 'pan_', // 面板视图
PAN: 'panel_', // 面板视图
STATUS: 'st_', // 状态变量
USR: 'usr_' // 用户数据
}
@ -85,5 +85,5 @@ export default {
setStorage,
getStorage,
userData,
DBPRE,
getDocs,
}

View File

@ -339,10 +339,7 @@ export default {
},
importDefaultCommands() {
for (var code of Object.keys(defaultCommands)) {
this.$root.utools.putDB(
defaultCommands[code],
this.$root.utools.DBPRE.QC + code
);
this.$root.utools.putDB(defaultCommands[code], "qc_" + code);
}
Object.assign(this.allQuickCommands, defaultCommands);
},
@ -365,7 +362,7 @@ export default {
getAllQuickCommands() {
let allQcs = {};
this.$root.utools
.getDocs(this.$root.utools.DBPRE.QC)
.getDocs("qc_")
.forEach((x) => (allQcs[x.data.features.code] = x.data));
return allQcs;
},
@ -413,7 +410,7 @@ export default {
removeCommand(code) {
utools.copyText(JSON.stringify(this.allQuickCommands[code], null, 4));
delete this.allQuickCommands[code];
this.$root.utools.delDB(this.$root.utools.DBPRE.QC + code);
this.$root.utools.delDB("qc_" + code);
this.disableCommand(code);
if (!this.allQuickCommandTags.includes(this.currentTag))
this.currentTag = "默认";
@ -463,10 +460,7 @@ export default {
dataToPushed = parsedData.qc;
}
for (var code of Object.keys(dataToPushed)) {
this.$root.utools.putDB(
dataToPushed[code],
this.$root.utools.DBPRE.QC + code
);
this.$root.utools.putDB(dataToPushed[code], "qc_" + code);
}
Object.assign(this.allQuickCommands, dataToPushed);
quickcommand.showMessageBox("导入成功!");
@ -524,7 +518,7 @@ export default {
return quickcommand.showMessageBox("取消操作", "info");
this.exportAllCommands(false);
this.$root.utools
.getDocs(this.$root.utools.DBPRE.QC)
.getDocs("qc_")
.map((x) => x._id)
.forEach((y) => this.$root.utools.delDB(y));
this.importDefaultCommands();

View File

@ -192,10 +192,7 @@ export default {
this.installedCodes.push(code);
let pushData = _.cloneDeep(command);
pushData.fromShare = true;
this.$root.utools.putDB(
_.cloneDeep(pushData),
this.$root.utools.DBPRE.QC + code
);
this.$root.utools.putDB(_.cloneDeep(pushData), "qc_" + code);
// 访
utools.ubrowser
.goto(`https://www.yuque.com/${this.releaseRepo}/${code}`)
@ -242,7 +239,7 @@ export default {
checkCommands() {
let installed = [];
let needUpdate = [];
this.$root.utools.getDocs(this.$root.utools.DBPRE.QC).forEach((item) => {
this.$root.utools.getDocs("qc_").forEach((item) => {
if (!item.data.fromShare) return;
let code = item._id.slice(3);
let remote = this.remoteCommands.filter((cmd) => cmd.slug === code)[0];

View File

@ -24,10 +24,7 @@ export default {
methods: {
importCommand(command) {
command = _.cloneDeep(command);
this.$root.utools.putDB(
command,
this.$root.utools.DBPRE.QC + command.features.code
);
this.$root.utools.putDB(command, "qc_" + command.features.code);
this.$root.utools.whole.setFeature(command.features);
},
getUid() {