mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 22:51:25 +08:00
新增用户变量
This commit is contained in:
parent
31f5d3c94c
commit
9b1a4a883b
@ -151,12 +151,13 @@ export default {
|
|||||||
},
|
},
|
||||||
// 特殊变量赋值
|
// 特殊变量赋值
|
||||||
assignSpecialVars(cmd) {
|
assignSpecialVars(cmd) {
|
||||||
|
let userData = this.$root.utools.userData.all();
|
||||||
let spVars = _.filter(specialVars, (sp) => sp.repl);
|
let spVars = _.filter(specialVars, (sp) => sp.repl);
|
||||||
_.forIn(spVars, (val, key) => {
|
_.forIn(spVars, (val, key) => {
|
||||||
if (cmd.includes(val.label.slice(0, -2))) {
|
let label = val.label.slice(0, -2);
|
||||||
cmd = cmd.replace(val.match, (x) =>
|
if (cmd.includes(label)) {
|
||||||
val.repl(x, this.$root.enterData)
|
let replData = label === "{{usr:" ? userData : this.$root.enterData;
|
||||||
);
|
cmd = cmd.replace(val.match, (x) => val.repl(x, replData));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return cmd;
|
return cmd;
|
||||||
|
@ -155,7 +155,12 @@
|
|||||||
transition-show="jump-down"
|
transition-show="jump-down"
|
||||||
transition-hide="jump-up"
|
transition-hide="jump-up"
|
||||||
borderless
|
borderless
|
||||||
@update:model-value="(val) => insertSpecialVar(val.label)"
|
@popup-hide="
|
||||||
|
() => {
|
||||||
|
if (specialVar.label === '{{usr:}}') showUserData = true;
|
||||||
|
else insertSpecialVar(specialVar.label);
|
||||||
|
}
|
||||||
|
"
|
||||||
square
|
square
|
||||||
:options="specialVarsOptions"
|
:options="specialVarsOptions"
|
||||||
v-model="specialVar"
|
v-model="specialVar"
|
||||||
@ -263,6 +268,9 @@
|
|||||||
ref="icon"
|
ref="icon"
|
||||||
/>
|
/>
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
|
<q-dialog v-model="showUserData">
|
||||||
|
<UserData @insertText="insertSpecialVar" />
|
||||||
|
</q-dialog>
|
||||||
</q-scroll-area>
|
</q-scroll-area>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -272,10 +280,11 @@ import outputTypes from "../js/options/outputTypes.js";
|
|||||||
import specialVars from "../js/options/specialVars.js";
|
import specialVars from "../js/options/specialVars.js";
|
||||||
import platformTypes from "../js/options/platformTypes.js";
|
import platformTypes from "../js/options/platformTypes.js";
|
||||||
import iconPicker from "components/popup/IconPicker.vue";
|
import iconPicker from "components/popup/IconPicker.vue";
|
||||||
|
import UserData from "components/popup/UserData.vue";
|
||||||
let commandTypesOptions = Object.values(commandTypes);
|
let commandTypesOptions = Object.values(commandTypes);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { iconPicker },
|
components: { iconPicker, UserData },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
currentCommand: {
|
currentCommand: {
|
||||||
@ -298,6 +307,7 @@ export default {
|
|||||||
specialVar: "{{}}",
|
specialVar: "{{}}",
|
||||||
allQuickCommandTags: this.$parent.allQuickCommandTags,
|
allQuickCommandTags: this.$parent.allQuickCommandTags,
|
||||||
showIconPicker: false,
|
showIconPicker: false,
|
||||||
|
showUserData: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
90
src/components/popup/UserData.vue
Normal file
90
src/components/popup/UserData.vue
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<template>
|
||||||
|
<q-card style="min-width: 500px">
|
||||||
|
<q-card-section>
|
||||||
|
<div
|
||||||
|
class="text-grey text-h6 text-italic full-width"
|
||||||
|
v-if="!allUserData.length"
|
||||||
|
>
|
||||||
|
还未添加用户变量
|
||||||
|
</div>
|
||||||
|
<q-input
|
||||||
|
v-for="item in allUserData"
|
||||||
|
:key="item.id"
|
||||||
|
v-model="item.value"
|
||||||
|
class="full-width q-ma-md"
|
||||||
|
type="text"
|
||||||
|
:prefix="`${item.id}`"
|
||||||
|
suffix="仅本机"
|
||||||
|
outlined
|
||||||
|
>
|
||||||
|
<template v-slot:append>
|
||||||
|
<q-toggle v-model="item.isNative" color="primary" />
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
color="primary"
|
||||||
|
icon="send"
|
||||||
|
@click="insertText(`{{usr:${item.id}}}`)" />
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
color="negative"
|
||||||
|
icon="close"
|
||||||
|
@click="delUserData(item.id)" /></template
|
||||||
|
></q-input>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section class="flex justify-end q-gutter-sm">
|
||||||
|
<q-btn flat color="grey" label="退出" v-close-popup />
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
color="deep-orange"
|
||||||
|
:disable="!allUserData.length"
|
||||||
|
label="更新"
|
||||||
|
@click="saveUserData"
|
||||||
|
/>
|
||||||
|
<q-btn flat color="primary" label="添加" @click="addUserData" />
|
||||||
|
</q-card-section>
|
||||||
|
</q-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
allUserData: [],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.allUserData = this.$root.utools.userData.all();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
saveUserData() {
|
||||||
|
this.allUserData.forEach((item) => {
|
||||||
|
this.$root.utools.userData.put(item.value, item.id, item.isNative);
|
||||||
|
});
|
||||||
|
quickcommand.showMessageBox("更新完毕!");
|
||||||
|
},
|
||||||
|
delUserData(id) {
|
||||||
|
quickcommand.showConfirmBox("删除后不可恢复").then(() => {
|
||||||
|
this.$root.utools.userData.del(id);
|
||||||
|
this.allUserData = this.allUserData.filter((item) => item.id !== id);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
insertText(text) {
|
||||||
|
this.$emit("insertText", text);
|
||||||
|
},
|
||||||
|
addUserData() {
|
||||||
|
quickcommand.showInputBox(["变量名称", "变量值"]).then(([id, value]) => {
|
||||||
|
if (!/\w+/.test(id))
|
||||||
|
return quickcommand.showMessageBox("变量名请使用全英文字母", "error");
|
||||||
|
if (this.allUserData.map((x) => x.id).includes(id))
|
||||||
|
return quickcommand.showMessageBox("变量名重复", "error");
|
||||||
|
this.allUserData.push({
|
||||||
|
id,
|
||||||
|
value,
|
||||||
|
isNative: true,
|
||||||
|
});
|
||||||
|
this.$root.utools.userData.put(value, id, true);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
@ -144,7 +144,19 @@ const specialVars = {
|
|||||||
type: "command",
|
type: "command",
|
||||||
match: /{{py:(.*?)}}/mg,
|
match: /{{py:(.*?)}}/mg,
|
||||||
repl: py => window.runPythonCommand(py.slice(5, -2))
|
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
|
@ -8,10 +8,11 @@ let whole = window.utools
|
|||||||
|
|
||||||
// 数据库前缀
|
// 数据库前缀
|
||||||
const DBPRE = {
|
const DBPRE = {
|
||||||
QC: 'qc_',
|
QC: 'qc_', // 快捷命令
|
||||||
CFG: 'cfg_',
|
CFG: 'cfg_', // 配置
|
||||||
PAN: 'pan_',
|
PAN: 'pan_', // 面板视图
|
||||||
STATUS: 'st_'
|
STATUS: 'st_', // 状态变量
|
||||||
|
USR: 'usr_' // 用户数据
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据库函数封装
|
// 数据库函数封装
|
||||||
@ -41,11 +42,44 @@ let getDocs = key => {
|
|||||||
return whole.db.allDocs(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 {
|
export default {
|
||||||
whole,
|
whole,
|
||||||
getDB,
|
getDB,
|
||||||
putDB,
|
putDB,
|
||||||
delDB,
|
delDB,
|
||||||
getDocs,
|
getDocs,
|
||||||
|
userData,
|
||||||
DBPRE,
|
DBPRE,
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user