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

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

View File

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

View File

@ -457,7 +457,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.profile.quickFeatures.apiServer.serverStatus = false; this.$root.nativeProfile.apiServerStatus = false;
} }
}, },
}, },

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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