规范utools引用

This commit is contained in:
fofolee 2025-02-13 01:14:37 +08:00
parent dcac385dbd
commit 05e5223ef3
18 changed files with 107 additions and 119 deletions

View File

@ -10,7 +10,7 @@
<script>
import { defineComponent } from "vue";
import { setCssVar } from "quasar";
import UTOOLS from "./js/utools.js";
import { utoolsFull, dbManager } from "./js/utools.js";
import programmings from "./js/options/programs.js";
import defaultProfile from "./js/options/defaultProfile.js";
import Cron from "croner";
@ -27,7 +27,7 @@ export default defineComponent({
isRunningCommand: false,
profile: defaultProfile.common,
nativeProfile: defaultProfile.native,
utools: UTOOLS,
utools: utoolsFull,
cronJobs: {},
enterData: {},
subInputEvent: null,
@ -60,11 +60,11 @@ export default defineComponent({
startUp() {
this.loadProfile();
this.startUpOnce();
this.utools.whole.onPluginEnter((enter) => {
this.utools.onPluginEnter((enter) => {
this.enterPlugin(enter);
});
window.isAppVersion4() &&
this.utools.whole.onMainPush(
this.utools.onMainPush(
async ({ code, type, payload }) => {
let result = await this.runCommand(code, payload, 5000);
return result.map((x) => {
@ -78,13 +78,13 @@ export default defineComponent({
window.utools.showNotification("已复制");
}
);
this.utools.whole.onPluginOut(() => {
this.utools.onPluginOut(() => {
this.outPlugin();
});
},
loadProfile() {
let commonProfile = this.utools.getDB("cfg_profile");
let nativeProfile = this.utools.getDB(
let commonProfile = dbManager.getDB("cfg_profile");
let nativeProfile = dbManager.getDB(
"cfg_" + utools.getNativeId() + "_profile"
);
this.profile = Object.assign(
@ -97,8 +97,11 @@ export default defineComponent({
);
},
saveProfile() {
this.utools.putDB(window.lodashM.cloneDeep(this.profile), "cfg_profile");
this.utools.putDB(
dbManager.putDB(
window.lodashM.cloneDeep(this.profile),
"cfg_profile"
);
dbManager.putDB(
window.lodashM.cloneDeep(this.nativeProfile),
"cfg_" + utools.getNativeId() + "_profile"
);
@ -148,7 +151,7 @@ export default defineComponent({
setTimeout(() => {
reslove([`超过${timeout}ms未响应`]);
}, timeout);
let command = this.utools.getDB("qc_" + featureCode);
let command = dbManager.getDB("qc_" + featureCode);
let commandCode = command.cmd;
if (mainInput)
commandCode = commandCode.replace(/\{\{input\}\}/g, mainInput);
@ -180,39 +183,24 @@ export default defineComponent({
runCommandSilently(featureCode) {
this.runCommand(featureCode);
},
// usageStatistics(featureCode, runTime) {
// let statisticsData = this.utools.getDB("cfg_statisticsData");
// let thisYear = runTime.year;
// if (!statisticsData[thisYear]) statisticsData[thisYear] = [];
// statisticsData[thisYear].push({
// code: featureCode,
// time: {
// month: runTime.month,
// day: runTime.day,
// hour: runTime.hour,
// minute: runTime.minute,
// },
// });
// this.utools.putDB(statisticsData, "cfg_statisticsData");
// },
updateExp() {
let exp = this.utools.getDB("cfg_exp");
let exp = dbManager.getDB("cfg_exp");
if (typeof exp !== "object") {
exp += 1;
this.utools.putDB(exp, "cfg_exp");
dbManager.putDB(exp, "cfg_exp");
return;
}
try {
let statisticsData = this.utools.getDB("cfg_statisticsData");
let statisticsData = dbManager.getDB("cfg_statisticsData");
exp = Object.values(statisticsData)
.map((x) => x.length)
.reduce((x, y) => x + y);
// BUG
this.utools.delDB("cfg_statisticsData");
dbManager.delDB("cfg_statisticsData");
} catch (error) {
exp = 0;
}
this.utools.putDB(exp, "cfg_exp");
dbManager.putDB(exp, "cfg_exp");
},
parseDate: (dateString) => {
return {
@ -225,25 +213,11 @@ export default defineComponent({
};
},
firstRun() {
if (this.utools.getStorage("st_v300Inited")) return;
if (dbManager.getStorage("st_v300Inited")) return;
window.showUb.help();
//
// let statisticsData = this.utools.getDB("cfg_statisticsData");
// window.lodashM.forIn(statisticsData, (data, year) => {
// statisticsData[year] = data.map((x) => {
// if (!x.command) return x;
// let code =
// x.command.code === "options" ? "configuration" : x.command.code;
// return {
// code: code,
// time: x.time,
// };
// });
// });
// this.utools.putDB(statisticsData, "cfg_statisticsData");
//
this.utools.delAll("qc_default");
this.utools.setStorage("st_v300Inited", true);
dbManager.delAll("qc_default");
dbManager.setStorage("st_v300Inited", true);
},
getOpacityColor(color, percent) {
return (

View File

@ -83,6 +83,7 @@ import EditorTools from "components/editor/EditorTools";
import CommandRunResult from "components/CommandRunResult";
import CommandComposer from "components/composer/CommandComposer.vue";
import programs from "js/options/programs.js";
import { dbManager } from "js/utools.js";
// MonacoEditor
const MonacoEditorPromise = import("components/editor/MonacoEditor");
@ -169,7 +170,7 @@ export default {
//
commandInit() {
let quickCommandInfo = this.isRunCodePage
? this.$root.utools.getDB("cfg_codeHistory")
? dbManager.getDB("cfg_codeHistory")
: this.action.data;
quickCommandInfo?.program &&
Object.assign(
@ -233,7 +234,7 @@ export default {
case "apply":
return this.replaceText(actionData);
case "close":
return this.showComposer = false;
return (this.showComposer = false);
}
},
//
@ -245,7 +246,7 @@ export default {
window.lodashM.cloneDeep(updatedData)
);
let newQuickcommandInfo = window.lodashM.cloneDeep(this.quickcommandInfo);
this.$root.utools.putDB(
dbManager.putDB(
newQuickcommandInfo,
"qc_" + this.quickcommandInfo.features.code
);
@ -272,7 +273,7 @@ export default {
if (this.action.type !== "run") return;
let command = window.lodashM.cloneDeep(this.quickcommandInfo);
command.cursorPosition = this.$refs.editor.getCursorPosition();
this.$root.utools.putDB(command, "cfg_codeHistory");
dbManager.putDB(command, "cfg_codeHistory");
},
monacoTyping(val) {
this.quickcommandInfo.cmd = val;

View File

@ -77,6 +77,7 @@ import ResultArea from "components/ResultArea.vue";
import ResultMenu from "components/popup/ResultMenu.vue";
import { generateFlowsCode } from "js/composer/generateCode";
import { getValidCommand } from "js/commandManager";
import { dbManager } from "js/utools.js";
export default {
components: { ResultArea, ResultMenu },
@ -225,7 +226,7 @@ export default {
},
//
assignSpecialVars(cmd) {
let userData = this.$root.utools.userData.all();
let userData = dbManager.userData.all();
let spVars = window.lodashM.filter(specialVars, (sp) => sp.repl);
window.lodashM.forIn(spVars, (val, key) => {
let label = val.label.slice(0, -2);

View File

@ -59,6 +59,7 @@
<script>
import draggable from "vuedraggable";
import { dbManager } from "js/utools.js";
const FIXED_TAGS = ["未分类", "默认", "搜索结果"];
const TAG_ORDER_KEY = "cfg_tagOrder";
@ -98,7 +99,7 @@ export default {
},
created() {
//
this.savedTagOrder = this.$root.utools.getDB(TAG_ORDER_KEY);
this.savedTagOrder = dbManager.getDB(TAG_ORDER_KEY);
if (!this.savedTagOrder.length) {
this.savedTagOrder = this.allQuickCommandTags;
}
@ -145,7 +146,7 @@ export default {
//
this.savedTagOrder = value;
//
this.$root.utools.putDB(value, TAG_ORDER_KEY);
dbManager.putDB(value, TAG_ORDER_KEY);
//
this.$emit("tags-reordered", value);
},
@ -158,7 +159,7 @@ export default {
//
this.savedTagOrder = newOrder;
//
this.$root.utools.putDB(newOrder, TAG_ORDER_KEY);
dbManager.putDB(newOrder, TAG_ORDER_KEY);
//
this.$emit("tags-reordered", newOrder);
}

View File

@ -142,16 +142,22 @@
<script>
import features from "js/options/quickFeatures.js";
import { utoolsFull } from "js/utools.js";
export default {
name: "UtilityFeaturesMenu",
data() {
return {
utools: utoolsFull,
};
},
methods: {
toggleFeature(type, enable) {
enable
? this.$root.utools.whole.setFeature(
? this.utools.setFeature(
window.lodashM.cloneDeep(features[type])
)
: this.$root.utools.whole.removeFeature(features[type].code);
: this.utools.removeFeature(features[type].code);
},
},
};

View File

@ -103,6 +103,7 @@ import UtilityFeaturesMenu from "./UtilityFeaturesMenu.vue";
import EnvConfigMenu from "./EnvConfigMenu.vue";
import PersonalizeMenu from "./PersonalizeMenu.vue";
import UserData from "../popup/UserData.vue";
import { utoolsFull } from "js/utools.js";
export default {
name: "ConfigurationMenu",
@ -121,6 +122,7 @@ export default {
showAbout: false,
showPanelConf: false,
showUserData: false,
utools: utoolsFull,
};
},
props: {
@ -140,7 +142,7 @@ export default {
},
methods: {
unMarkTag() {
this.$root.utools.whole.removeFeature(
this.utools.removeFeature(
`panel_${window.hexEncode(this.currentTag)}`
);
window.lodashM.pull(

View File

@ -51,11 +51,13 @@
<script>
import IconPicker from "components/popup/IconPicker";
import { utoolsFull } from "js/utools.js";
export default {
components: { IconPicker },
data() {
return {
utools: utoolsFull,
features: {
explain: `进入${this.currentTag}的面板视图`,
icon: "logo/quickcommand.png",
@ -71,9 +73,7 @@ export default {
},
methods: {
markTag() {
this.$root.utools.whole.setFeature(
window.lodashM.cloneDeep(this.features)
);
this.utools.setFeature(window.lodashM.cloneDeep(this.features));
this.$root.$refs.view.activatedQuickPanels.push(this.currentTag);
quickcommand.showMessageBox(
`主输入框输入『${this.features.cmds.join("、")}』即可直接进入『${

View File

@ -62,7 +62,7 @@ const joinLink = [
"https://www.yuque.com/g/fofolee/qcshares4/collaborator/join?token=DXb4XAVatwn2OoGK#",
"https://www.yuque.com/g/fofolee/qcshares5/collaborator/join?token=tw1kyfD2T4jjsQHc#",
];
import { dbManager } from "js/utools.js";
export default {
data() {
return {
@ -167,10 +167,10 @@ export default {
});
},
loadYuQueInfo() {
return this.$root.utools.getDB("cfg_extraInfo");
return dbManager.getDB("cfg_extraInfo");
},
saveYuQueInfo() {
this.$root.utools.putDB(
dbManager.putDB(
window.lodashM.cloneDeep(this.yuQueInfo),
"cfg_extraInfo"
);

View File

@ -58,6 +58,7 @@
</template>
<script>
import { dbManager } from "js/utools.js";
export default {
data() {
return {
@ -68,18 +69,18 @@ export default {
showInsertBtn: Boolean,
},
mounted() {
this.allUserData = this.$root.utools.userData.all();
this.allUserData = dbManager.userData.all();
},
methods: {
saveUserData() {
this.allUserData.forEach((item) => {
this.$root.utools.userData.put(item.value, item.id, item.isNative);
dbManager.userData.put(item.value, item.id, item.isNative);
});
quickcommand.showMessageBox("更新完毕!");
},
delUserData(id) {
quickcommand.showConfirmBox("删除后不可恢复").then(() => {
this.$root.utools.userData.del(id);
dbManager.userData.del(id);
this.allUserData = this.allUserData.filter((item) => item.id !== id);
});
},
@ -97,7 +98,7 @@ export default {
value,
isNative: true,
});
this.$root.utools.userData.put(value, id, true);
dbManager.userData.put(value, id, true);
});
},
},

View File

@ -130,10 +130,12 @@
<script>
import levelDetail from "js/options/levelDetail.js";
import { dbManager, utoolsFull } from "js/utools.js";
export default {
data() {
return {
utools: utoolsFull,
userInfo: {
exp: 0,
level: 1,
@ -160,8 +162,8 @@ export default {
},
methods: {
async getUserInfo() {
Object.assign(this.userInfo, this.$root.utools.whole.getUser());
this.userInfo.exp = this.$root.utools.getDB("cfg_exp");
Object.assign(this.userInfo, this.utools.getUser());
this.userInfo.exp = dbManager.getDB("cfg_exp");
this.userInfo.level = this.levelDetail
.filter((x) => this.userInfo.exp > x.minExp)
.pop().lv;
@ -174,8 +176,7 @@ export default {
).toFixed(2)
)
: 1;
let ret = await this.$root.utools.whole.fetchUserPayments();
console.log("PayInfo:", ret);
let ret = await this.utools.fetchUserPayments();
this.isPluginVIP = ret.find((x) => x.goods_id === this.goodsId);
this.isUtoolsVIP = this.userInfo.type === "member";
@ -189,7 +190,7 @@ export default {
}, 3000);
},
payForMember() {
this.$root.utools.whole.openPayment({ goodsId: this.goodsId }, () => {
this.utools.openPayment({ goodsId: this.goodsId }, () => {
this.isPluginVIP = true;
this.showPayPage = false;
});

View File

@ -37,6 +37,7 @@ import ConfirmBox from "components/quickcommandUI/ConfirmBox";
import TextArea from "components/quickcommandUI/TextArea";
import SelectList from "components/quickcommandUI/SelectList";
import programs from "js/options/programs";
import { dbManager } from "js/utools.js";
export default {
components: {
@ -264,7 +265,7 @@ export default {
Object.assign(window.quickcommand, quickcommandUI);
//
window.quickcommand.userData = this.$root.utools.userData;
window.quickcommand.userData = dbManager.userData;
/**
* 执行代码

View File

@ -1,7 +1,7 @@
import { reactive } from "vue";
import quickcommandParser from "js/common/quickcommandParser.js";
import importAll from "js/common/importAll.js";
import utoolsFull from "js/utools.js";
import { utoolsFull, dbManager } from "js/utools.js";
import { getUniqueId } from "js/common/uuid.js";
import outputTypes from "js/options/outputTypes.js";
@ -66,7 +66,7 @@ export const getValidCommand = (command) => {
export function useCommandManager() {
// 获取已启用的命令
const getActivatedFeatures = () => {
let features = utoolsFull.whole.getFeatures();
let features = utoolsFull.getFeatures();
let currentFts = [];
let quickpanels = [];
features.forEach((x) =>
@ -79,16 +79,16 @@ export function useCommandManager() {
};
// 清除所有命令
const clearAllFeatures = () => {
for (var feature of utoolsFull.whole.getFeatures()) {
for (var feature of utoolsFull.getFeatures()) {
if (feature.code.slice(0, 8) === "feature_") continue;
utoolsFull.whole.removeFeature(feature.code);
utoolsFull.removeFeature(feature.code);
}
state.activatedQuickCommandFeatureCodes = [];
};
// 获取所有的命令
const getAllQuickCommands = () => {
state.allQuickCommands = window.lodashM.cloneDeep(defaultCommands);
utoolsFull.getAll("qc_").forEach((x) => {
dbManager.getAll("qc_").forEach((x) => {
if (x.data.features.code.includes("default_")) return;
state.allQuickCommands[x.data.features.code] = x.data;
});
@ -117,11 +117,11 @@ export function useCommandManager() {
state.activatedQuickCommandFeatureCodes.push(code);
}
utoolsFull.whole.removeFeature(code);
utoolsFull.whole.setFeature(command.features);
utoolsFull.removeFeature(code);
utoolsFull.setFeature(command.features);
if (!isDefaultCommand(code)) {
utoolsFull.putDB(command, "qc_" + code);
dbManager.putDB(command, "qc_" + code);
}
getAllQuickCommandTags();
@ -130,11 +130,11 @@ export function useCommandManager() {
// 删除命令
const removeCommand = (code) => {
utoolsFull.whole.copyText(
utoolsFull.copyText(
JSON.stringify(state.allQuickCommands[code], null, 4)
);
delete state.allQuickCommands[code];
utoolsFull.delDB("qc_" + code);
dbManager.delDB("qc_" + code);
removeCommandFromHistory(code);
disableCommand(code);
getAllQuickCommandTags();
@ -158,7 +158,7 @@ export function useCommandManager() {
// 启用命令
const enableCommand = (code) => {
utoolsFull.whole.setFeature(
utoolsFull.setFeature(
window.lodashM.cloneDeep(state.allQuickCommands[code].features)
);
state.activatedQuickCommandFeatureCodes.push(code);
@ -166,7 +166,7 @@ export function useCommandManager() {
// 禁用命令
const disableCommand = (code) => {
utoolsFull.whole.removeFeature(code);
utoolsFull.removeFeature(code);
state.activatedQuickCommandFeatureCodes =
state.activatedQuickCommandFeatureCodes.filter((x) => x !== code);
};
@ -197,7 +197,7 @@ export function useCommandManager() {
for (var code of Object.keys(dataToPushed)) {
if (isDefaultCommand(code)) continue;
utoolsFull.putDB(dataToPushed[code], "qc_" + code);
dbManager.putDB(dataToPushed[code], "qc_" + code);
}
Object.assign(state.allQuickCommands, dataToPushed);
@ -228,7 +228,7 @@ export function useCommandManager() {
if (saveAsFile) {
return window.saveFile(stringifyCommands, options);
} else {
utoolsFull.whole.copyText(stringifyCommands);
utoolsFull.copyText(stringifyCommands);
return true;
}
};
@ -236,7 +236,7 @@ export function useCommandManager() {
// 清空所有命令
const clearAllCommands = () => {
exportAllCommands(false);
utoolsFull.delAll("qc_");
dbManager.delAll("qc_");
clearAllFeatures();
getAllQuickCommands();
};

View File

@ -4,7 +4,7 @@
*/
// 禁用危险函数
let whole = window.utools;
export const utoolsFull = window.utools;
// 数据库前缀
const DBPRE = {
@ -17,40 +17,40 @@ const DBPRE = {
// 数据库函数封装
let getDB = (id) => {
let db = whole.db.get(id);
let db = utoolsFull.db.get(id);
return db ? db.data : {};
};
let putDB = (value, id) => {
let db = whole.db.get(id);
let db = utoolsFull.db.get(id);
return db
? whole.db.put({
? utoolsFull.db.put({
_id: id,
data: value,
_rev: db._rev,
})
: whole.db.put({
: utoolsFull.db.put({
_id: id,
data: value,
});
};
let delDB = (id) => {
return whole.db.remove(id);
return utoolsFull.db.remove(id);
};
let getAll = (key) => {
return whole.db.allDocs(key);
return utoolsFull.db.allDocs(key);
};
let delAll = (key) => {
return getAll(key).forEach((x) => delDB(x._id));
};
let setStorage = whole.dbStorage.setItem;
let getStorage = whole.dbStorage.getItem;
let setStorage = utoolsFull.dbStorage.setItem;
let getStorage = utoolsFull.dbStorage.getItem;
const nativeId = utools.getNativeId();
const nativeId = utoolsFull.getNativeId();
let userData = {
put: function (value, id, isNative = true) {
@ -85,8 +85,7 @@ let userData = {
},
};
export default {
whole,
export const dbManager = {
getDB,
putDB,
delDB,

View File

@ -6,11 +6,13 @@
<script>
import CommandRunResult from "components/CommandRunResult";
import { utoolsFull } from "js/utools.js";
export default {
components: { CommandRunResult },
data() {
return {
utools: utoolsFull,
action: {
type: "input",
data: {},
@ -22,7 +24,7 @@ export default {
let command =
this.featureCode.slice(0, 8) === "default_"
? require(`../json/${this.featureCode}.json`)
: this.$root.utools.whole.db.get("qc_" + this.featureCode).data;
: this.utools.db.get("qc_" + this.featureCode).data;
this.runCurrentCommand(command);
},
methods: {

View File

@ -58,6 +58,7 @@
import { defineAsyncComponent } from "vue";
import { useCommandManager } from "js/commandManager.js";
import changeLog from "js/options/changeLog.js";
import { utoolsFull, dbManager } from "js/utools.js";
import pinyinMatch from "pinyin-match";
import CommandEditor from "components/CommandEditor";
import ComposerEditor from "components/ComposerEditor";
@ -86,6 +87,7 @@ export default {
},
data() {
return {
utools: utoolsFull,
currentTag: "",
lastTag: "",
commandSearchKeyword: "",
@ -367,7 +369,7 @@ export default {
showChangeLog() {
let lastNeedLogEvent = changeLog[changeLog.length - 1];
let loggedVersion =
this.$root.utools.whole.dbStorage.getItem("cfg_loggedVersion") ||
this.utools.dbStorage.getItem("cfg_loggedVersion") ||
"0.0.0";
if (loggedVersion < lastNeedLogEvent.version) {
quickcommand.showConfirmBox(
@ -378,7 +380,7 @@ export default {
true,
700
);
this.$root.utools.whole.dbStorage.setItem(
this.utools.dbStorage.setItem(
"cfg_loggedVersion",
lastNeedLogEvent.version
);
@ -407,7 +409,7 @@ export default {
//
Object.entries(tagCommands).forEach(([code, command]) => {
if (!this.isDefaultCommand(code)) {
this.$root.utools.putDB(
dbManager.putDB(
window.lodashM.cloneDeep(command),
"qc_" + code
);

View File

@ -7,6 +7,7 @@ import PluginNickName from "components/quickFeatures/PluginNickName";
import FavFile from "components/quickFeatures/FavFile";
import FavUrl from "components/quickFeatures/FavUrl";
import { markRaw } from "vue";
import { utoolsFull, dbManager } from "js/utools.js";
export default {
components: {
@ -16,14 +17,15 @@ export default {
},
data() {
return {
utools: utoolsFull,
currentComponent: this.$route.params.featuretype,
};
},
methods: {
importCommand(command) {
command = window.lodashM.cloneDeep(command);
this.$root.utools.putDB(command, "qc_" + command.features.code);
this.$root.utools.whole.setFeature(command.features);
dbManager.putDB(command, "qc_" + command.features.code);
this.utools.setFeature(command.features);
},
getUid() {
return Number(

View File

@ -16,14 +16,7 @@
}"
/>
<div
class="
absolute-bottom
flex
items-center
justify-between
q-px-md
shadow-10
"
class="absolute-bottom flex items-center justify-between q-px-md shadow-10"
:style="{
height: bottomHeight + 'px',
}"
@ -81,6 +74,7 @@
<script>
import MonacoEditor from "components/editor/MonacoEditor";
import { dbManager } from "js/utools.js";
export default {
components: { MonacoEditor },
@ -92,7 +86,7 @@ export default {
};
},
mounted() {
this.cmd = this.$root.utools.getStorage("cfg_serverCode") || "";
this.cmd = dbManager.getStorage("cfg_serverCode") || "";
this.$refs.editor.setEditorValue(this.cmd);
this.$refs.editor.setEditorLanguage("javascript");
},
@ -132,7 +126,7 @@ export default {
saveCode() {
clearTimeout(this.saveCodeTimer);
this.saveCodeTimer = setTimeout(() => {
this.$root.utools.setStorage("cfg_serverCode", this.cmd);
dbManager.setStorage("cfg_serverCode", this.cmd);
this.saveCodeTimer = null;
}, 1000);
},

View File

@ -126,6 +126,7 @@
<script>
import commandTypes from "js/options/commandTypes.js";
import { dbManager } from "js/utools.js";
export default {
data() {
@ -197,7 +198,7 @@ export default {
this.installedCodes.push(code);
let pushData = window.lodashM.cloneDeep(command);
pushData.fromShare = true;
this.$root.utools.putDB(window.lodashM.cloneDeep(pushData), "qc_" + code);
dbManager.putDB(window.lodashM.cloneDeep(pushData), "qc_" + code);
// 访
utools.ubrowser
.goto(`https://www.yuque.com/${this.releaseRepo}/${code}`)
@ -256,7 +257,7 @@ export default {
checkCommands() {
let installed = [];
let needUpdate = [];
this.$root.utools.getAll("qc_").forEach((item) => {
dbManager.getAll("qc_").forEach((item) => {
if (!item.data.fromShare) return;
let code = item._id.slice(3);
let remote = this.remoteCommands.filter((cmd) => cmd.slug === code)[0];