From 9b1a4a883b53941e68e681fe63395f0320053ee4 Mon Sep 17 00:00:00 2001 From: fofolee Date: Tue, 26 Apr 2022 00:26:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandRunResult.vue | 9 +-- src/components/CommandSideBar.vue | 14 ++++- src/components/popup/UserData.vue | 90 +++++++++++++++++++++++++++++ src/js/options/specialVars.js | 14 ++++- src/js/utools.js | 44 ++++++++++++-- 5 files changed, 159 insertions(+), 12 deletions(-) create mode 100644 src/components/popup/UserData.vue diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index 92a8f10..bafca2e 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -151,12 +151,13 @@ export default { }, // 特殊变量赋值 assignSpecialVars(cmd) { + let userData = this.$root.utools.userData.all(); let spVars = _.filter(specialVars, (sp) => sp.repl); _.forIn(spVars, (val, key) => { - if (cmd.includes(val.label.slice(0, -2))) { - cmd = cmd.replace(val.match, (x) => - val.repl(x, this.$root.enterData) - ); + let label = val.label.slice(0, -2); + if (cmd.includes(label)) { + let replData = label === "{{usr:" ? userData : this.$root.enterData; + cmd = cmd.replace(val.match, (x) => val.repl(x, replData)); } }); return cmd; diff --git a/src/components/CommandSideBar.vue b/src/components/CommandSideBar.vue index b65b293..6bc6a0f 100644 --- a/src/components/CommandSideBar.vue +++ b/src/components/CommandSideBar.vue @@ -155,7 +155,12 @@ transition-show="jump-down" transition-hide="jump-up" borderless - @update:model-value="(val) => insertSpecialVar(val.label)" + @popup-hide=" + () => { + if (specialVar.label === '{{usr:}}') showUserData = true; + else insertSpecialVar(specialVar.label); + } + " square :options="specialVarsOptions" v-model="specialVar" @@ -263,6 +268,9 @@ ref="icon" /> + + + @@ -272,10 +280,11 @@ import outputTypes from "../js/options/outputTypes.js"; import specialVars from "../js/options/specialVars.js"; import platformTypes from "../js/options/platformTypes.js"; import iconPicker from "components/popup/IconPicker.vue"; +import UserData from "components/popup/UserData.vue"; let commandTypesOptions = Object.values(commandTypes); export default { - components: { iconPicker }, + components: { iconPicker, UserData }, data() { return { currentCommand: { @@ -298,6 +307,7 @@ export default { specialVar: "{{}}", allQuickCommandTags: this.$parent.allQuickCommandTags, showIconPicker: false, + showUserData: false, }; }, props: { diff --git a/src/components/popup/UserData.vue b/src/components/popup/UserData.vue new file mode 100644 index 0000000..806286e --- /dev/null +++ b/src/components/popup/UserData.vue @@ -0,0 +1,90 @@ + + + diff --git a/src/js/options/specialVars.js b/src/js/options/specialVars.js index 303b29d..bf4d0c8 100644 --- a/src/js/options/specialVars.js +++ b/src/js/options/specialVars.js @@ -144,7 +144,19 @@ const specialVars = { type: "command", match: /{{py:(.*?)}}/mg, repl: py => window.runPythonCommand(py.slice(5, -2)) + }, + userData: { + name: "userData", + label: "{{usr:}}", + desc: "用户设置的变量", + match: /{{usr:(.*?)}}/mg, + repl: (text, userData) => { + console.log(userData); + let filterd = userData.filter(x => x.id === text.slice(6, -2)) + return filterd.length ? filterd[0].value : '' + }, + tooltip: "仅本机可用时,该变量值只在本机有效,否则,所有电脑有效", } } -export default specialVars +export default specialVars \ No newline at end of file diff --git a/src/js/utools.js b/src/js/utools.js index eda7580..2dde177 100644 --- a/src/js/utools.js +++ b/src/js/utools.js @@ -8,10 +8,11 @@ let whole = window.utools // 数据库前缀 const DBPRE = { - QC: 'qc_', - CFG: 'cfg_', - PAN: 'pan_', - STATUS: 'st_' + QC: 'qc_', // 快捷命令 + CFG: 'cfg_', // 配置 + PAN: 'pan_', // 面板视图 + STATUS: 'st_', // 状态变量 + USR: 'usr_' // 用户数据 } // 数据库函数封装 @@ -41,11 +42,44 @@ let getDocs = key => { return whole.db.allDocs(key) } +const nativeId = utools.getNativeId() + +let userData = { + put: function(value, id, isNative = true) { + let userData = getDB(DBPRE.USR + id) + if (isNative) { + userData[nativeId] = value; + } else { + userData.common = value; + delete userData[nativeId]; + } + putDB(userData, DBPRE.USR + id); + }, + get: function(id) { + let userData = getDB(DBPRE.USR + id) + return userData[nativeId] ? userData[nativeId] : userData.common + }, + del: function(id) { + delDB(DBPRE.USR + id) + }, + all: function() { + return getDocs(DBPRE.USR).map((item) => { + let isNative = !!item.data[nativeId]; + return { + id: item._id.replace(DBPRE.USR, ""), + value: isNative ? item.data[nativeId] : item.data.common, + isNative: isNative, + }; + }) + } +} + export default { whole, getDB, putDB, delDB, getDocs, + userData, DBPRE, -} +} \ No newline at end of file