mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 15:04:06 +08:00
添加quickcomman.userData接口 ,可以增、删、改、查用户数据
This commit is contained in:
parent
a905e4d981
commit
fefdf9578c
@ -1,13 +1,30 @@
|
|||||||
<template>
|
<template>
|
||||||
<q-dialog v-model="showDialog" :maximized="maximized" :transition-show="maximized ? 'fade' : 'scale'"
|
<q-dialog
|
||||||
:transition-hide="maximized ? 'fade' : 'scale'">
|
v-model="showDialog"
|
||||||
<component ref="ui" :is="currentUI" :options="options" @clickOK="clickOK" @hide="showDialog = false" />
|
:maximized="maximized"
|
||||||
|
:transition-show="maximized ? 'fade' : 'scale'"
|
||||||
|
:transition-hide="maximized ? 'fade' : 'scale'"
|
||||||
|
>
|
||||||
|
<component
|
||||||
|
ref="ui"
|
||||||
|
:is="currentUI"
|
||||||
|
:options="options"
|
||||||
|
@clickOK="clickOK"
|
||||||
|
@hide="showDialog = false"
|
||||||
|
/>
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
<!-- waitButton 单独一个 -->
|
<!-- waitButton 单独一个 -->
|
||||||
<q-btn class="fixed-top-right" style="z-index: 9999" v-if="showWb" color="primary" :label="wbLabel" @click="
|
<q-btn
|
||||||
|
class="fixed-top-right"
|
||||||
|
style="z-index: 9999"
|
||||||
|
v-if="showWb"
|
||||||
|
color="primary"
|
||||||
|
:label="wbLabel"
|
||||||
|
@click="
|
||||||
showWb = false;
|
showWb = false;
|
||||||
wbEvent();
|
wbEvent();
|
||||||
" />
|
"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -64,7 +81,12 @@ export default {
|
|||||||
|
|
||||||
showConfirmBox: (message = "", title = "提示", isHtml = false, width) =>
|
showConfirmBox: (message = "", title = "提示", isHtml = false, width) =>
|
||||||
new Promise((reslove, reject) => {
|
new Promise((reslove, reject) => {
|
||||||
this.showUI(ConfirmBox, { message, title, isHtml, width }, false, reslove);
|
this.showUI(
|
||||||
|
ConfirmBox,
|
||||||
|
{ message, title, isHtml, width },
|
||||||
|
false,
|
||||||
|
reslove
|
||||||
|
);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
showMessageBox: (message, icon = "success", time) => {
|
showMessageBox: (message, icon = "success", time) => {
|
||||||
@ -140,11 +162,12 @@ export default {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
Object.assign(window.quickcommand, quickcommandUI);
|
Object.assign(window.quickcommand, quickcommandUI);
|
||||||
|
window.quickcommand.userData = this.$root.utools.userData;
|
||||||
Object.freeze(quickcommand);
|
Object.freeze(quickcommand);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
clickOK() { },
|
clickOK() {},
|
||||||
wbEvent() { },
|
wbEvent() {},
|
||||||
showUI(uiComponent, options, maximized, reslove) {
|
showUI(uiComponent, options, maximized, reslove) {
|
||||||
this.showDialog = true;
|
this.showDialog = true;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
@ -4,72 +4,76 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// 禁用危险函数
|
// 禁用危险函数
|
||||||
let whole = window.utools
|
let whole = window.utools;
|
||||||
|
|
||||||
// 数据库前缀
|
// 数据库前缀
|
||||||
const DBPRE = {
|
const DBPRE = {
|
||||||
QC: 'qc_', // 快捷命令
|
QC: "qc_", // 快捷命令
|
||||||
CFG: 'cfg_', // 配置
|
CFG: "cfg_", // 配置
|
||||||
PAN: 'panel_', // 面板视图
|
PAN: "panel_", // 面板视图
|
||||||
STATUS: 'st_', // 状态变量
|
STATUS: "st_", // 状态变量
|
||||||
USR: 'usr_' // 用户数据
|
USR: "usr_", // 用户数据
|
||||||
}
|
};
|
||||||
|
|
||||||
// 数据库函数封装
|
// 数据库函数封装
|
||||||
let getDB = id => {
|
let getDB = (id) => {
|
||||||
let db = whole.db.get(id)
|
let db = whole.db.get(id);
|
||||||
return db ? db.data : {}
|
return db ? db.data : {};
|
||||||
}
|
};
|
||||||
|
|
||||||
let putDB = (value, id) => {
|
let putDB = (value, id) => {
|
||||||
let db = whole.db.get(id);
|
let db = whole.db.get(id);
|
||||||
if (db) whole.db.put({
|
return db
|
||||||
|
? whole.db.put({
|
||||||
_id: id,
|
_id: id,
|
||||||
data: value,
|
data: value,
|
||||||
_rev: db._rev
|
_rev: db._rev,
|
||||||
})
|
})
|
||||||
else whole.db.put({
|
: whole.db.put({
|
||||||
_id: id,
|
_id: id,
|
||||||
data: value
|
data: value,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
let delDB = id => {
|
let delDB = (id) => {
|
||||||
return whole.db.remove(id)
|
return whole.db.remove(id);
|
||||||
}
|
};
|
||||||
|
|
||||||
let getAll = key => {
|
let getAll = (key) => {
|
||||||
return whole.db.allDocs(key)
|
return whole.db.allDocs(key);
|
||||||
}
|
};
|
||||||
|
|
||||||
let delAll = key => {
|
let delAll = (key) => {
|
||||||
return getAll(key).forEach(x => delDB(x._id))
|
return getAll(key).forEach((x) => delDB(x._id));
|
||||||
}
|
};
|
||||||
|
|
||||||
let setStorage = whole.dbStorage.setItem
|
let setStorage = whole.dbStorage.setItem;
|
||||||
let getStorage = whole.dbStorage.getItem
|
let getStorage = whole.dbStorage.getItem;
|
||||||
|
|
||||||
const nativeId = utools.getNativeId()
|
const nativeId = utools.getNativeId();
|
||||||
|
|
||||||
let userData = {
|
let userData = {
|
||||||
put: function(value, id, isNative = true) {
|
put: function (value, id, isNative = true) {
|
||||||
let userData = getDB(DBPRE.USR + id)
|
let userData = getDB(DBPRE.USR + id);
|
||||||
if (isNative) {
|
if (isNative) {
|
||||||
userData[nativeId] = value;
|
userData[nativeId] = value;
|
||||||
} else {
|
} else {
|
||||||
userData.common = value;
|
userData.common = value;
|
||||||
delete userData[nativeId];
|
delete userData[nativeId];
|
||||||
}
|
}
|
||||||
putDB(userData, DBPRE.USR + id);
|
let { ok } = putDB(userData, DBPRE.USR + id);
|
||||||
|
return ok;
|
||||||
},
|
},
|
||||||
get: function(id) {
|
get: function (id) {
|
||||||
let userData = getDB(DBPRE.USR + id)
|
let userData = getDB(DBPRE.USR + id);
|
||||||
return userData[nativeId] ? userData[nativeId] : userData.common
|
let nativeData = userData[nativeId];
|
||||||
|
return nativeData ? nativeData : userData.common;
|
||||||
},
|
},
|
||||||
del: function(id) {
|
del: function (id) {
|
||||||
delDB(DBPRE.USR + id)
|
let { ok } = delDB(DBPRE.USR + id);
|
||||||
|
return ok;
|
||||||
},
|
},
|
||||||
all: function() {
|
all: function () {
|
||||||
return getAll(DBPRE.USR).map((item) => {
|
return getAll(DBPRE.USR).map((item) => {
|
||||||
let isNative = !!item.data[nativeId];
|
let isNative = !!item.data[nativeId];
|
||||||
return {
|
return {
|
||||||
@ -77,9 +81,9 @@ let userData = {
|
|||||||
value: isNative ? item.data[nativeId] : item.data.common,
|
value: isNative ? item.data[nativeId] : item.data.common,
|
||||||
isNative: isNative,
|
isNative: isNative,
|
||||||
};
|
};
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
whole,
|
whole,
|
||||||
@ -90,5 +94,5 @@ export default {
|
|||||||
getStorage,
|
getStorage,
|
||||||
userData,
|
userData,
|
||||||
getAll,
|
getAll,
|
||||||
delAll
|
delAll,
|
||||||
}
|
};
|
||||||
|
55
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
55
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
@ -364,13 +364,13 @@ interface quickcommandApi {
|
|||||||
runInTerminal(command: string);
|
runInTerminal(command: string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对应 utools.onPluginEnter 的 code type 和 payload
|
* 对应 utools.onPluginEnter 的 `code` `type` 和 `payload`
|
||||||
*
|
*
|
||||||
* code: 唯一标识
|
* `code`: 唯一标识
|
||||||
*
|
*
|
||||||
* type: 匹配模式,可以为 text | img | files | regex | over | window
|
* `type`: 匹配模式,可以为 text | img | files | regex | over | window
|
||||||
*
|
*
|
||||||
* payload: 当匹配模式为关键字时,返回进入插件的关键字;为正则时,返回匹配的文本;为窗口时,返回匹配的窗口信息;为文件时,返回匹配的文件信息
|
* `payload`: 当匹配模式为关键字时,返回进入插件的关键字;为正则时,返回匹配的文本;为窗口时,返回匹配的窗口信息;为文件时,返回匹配的文件信息
|
||||||
*
|
*
|
||||||
* ```js
|
* ```js
|
||||||
* if (quickcommand.enterData.type == 'regex'){
|
* if (quickcommand.enterData.type == 'regex'){
|
||||||
@ -412,6 +412,53 @@ interface quickcommandApi {
|
|||||||
* @param txt 要写入的文本
|
* @param txt 要写入的文本
|
||||||
*/
|
*/
|
||||||
writeClipboard(txt: string);
|
writeClipboard(txt: string);
|
||||||
|
|
||||||
|
userData: {
|
||||||
|
/**
|
||||||
|
* 创建/更新用户数据,返回是否成功
|
||||||
|
*
|
||||||
|
* 菜单-环境配置-用户特殊变量中的对应数据也会同步变更
|
||||||
|
*
|
||||||
|
* @param value: 要写入的数据
|
||||||
|
*
|
||||||
|
* @param id: 数据标识
|
||||||
|
*
|
||||||
|
* @param isNative: 是否仅本机有效,默认为 true
|
||||||
|
*
|
||||||
|
*```js
|
||||||
|
* // 仅本机有效时,不同设备可以分别设置 filePath 的值而不冲突
|
||||||
|
* quickcommand.userData.put('D:/xx.json' ,'filePath')
|
||||||
|
*
|
||||||
|
* // 非仅本机有效,则类似设置了一个缺省值,所有未设置仅本机有效的 filePath 值都为 D:/xx.json
|
||||||
|
* quickcommand.userData.put('D:/xx.json' ,'filePath', false)
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
put(value: string, id: string, isNative?: boolean): boolean;
|
||||||
|
/**
|
||||||
|
* 获取用户数据
|
||||||
|
*
|
||||||
|
* @param id: 数据标识
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* // 等效于特殊变量 {{usr:filePath}}
|
||||||
|
* quickcommand.userData.get('filePath')
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
get(id: string): string;
|
||||||
|
/**
|
||||||
|
* 删除用户数据,返回是否成功
|
||||||
|
*
|
||||||
|
* @param id: 数据标识
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
del(id: string): boolean;
|
||||||
|
/**
|
||||||
|
* 获取所有用户数据
|
||||||
|
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
all(): Array<{ id: string; value: string; isNative: boolean }>;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
declare var quickcommand: quickcommandApi;
|
declare var quickcommand: quickcommandApi;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user