mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-18 01:44:36 +08:00
新增用户变量
This commit is contained in:
@@ -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
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user