弃用lodash

This commit is contained in:
fofolee
2024-12-30 20:41:54 +08:00
parent 7a79d3a443
commit 1d3aa3c9ae
30 changed files with 597 additions and 152 deletions

View File

@@ -32,7 +32,7 @@ const getUtoolsPlugins = () => {
return true; return true;
}); });
}); });
if (!_.isEmpty(keyWordFeatures)) { if (!window.lodashM.isEmpty(keyWordFeatures)) {
pluginInfo["keyWordFeatures"] = keyWordFeatures; pluginInfo["keyWordFeatures"] = keyWordFeatures;
plugins[pluginInfo.pluginName] = pluginInfo; plugins[pluginInfo.pluginName] = pluginInfo;
} }

352
plugin/lib/lodashMini.js Normal file
View File

@@ -0,0 +1,352 @@
// 主要函数实现
const lodashMini = {
/**
* 创建一个新数组将array与任何数组或值连接在一起
* @param {Array} array - 要连接的第一个数组
* @param {...*} values - 要连接的其他值
* @returns {Array} 返回连接后的新数组
* @example
* concat([1], 2, [3], [[4]]) => [1, 2, 3, [4]]
*/
concat: function (array, ...values) {
return [].concat(array || [], ...values);
},
/**
* 深拷贝一个值,支持大多数内置类型
* @param {*} value - 要深拷贝的值
* @returns {*} 返回深拷贝后的值
* @example
* cloneDeep([{ a: [1] }]) => [{ a: [1] }]
*/
cloneDeep: function (value) {
if (!this.isObject(value)) {
return value;
}
if (this.isArray(value)) {
return value.map((item) => this.cloneDeep(item));
}
if (this.isBuffer(value)) {
const result = Buffer.allocUnsafe(value.length);
value.copy(result);
return result;
}
if (value instanceof Date) return new Date(value);
if (value instanceof RegExp) return new RegExp(value.source, value.flags);
if (value instanceof Set) {
return new Set([...value].map((item) => this.cloneDeep(item)));
}
if (value instanceof Map) {
return new Map(
[...value].map(([k, v]) => [this.cloneDeep(k), this.cloneDeep(v)])
);
}
if (typeof value === "function") {
return value;
}
const result = {};
for (const key in value) {
if (Object.prototype.hasOwnProperty.call(value, key)) {
result[key] = this.cloneDeep(value[key]);
}
}
return result;
},
/**
* 遍历集合中的元素,返回所有通过断言检查的元素组成的数组
* @param {Array|Object} collection - 要遍历的集合
* @param {Function|String|Array|Object} predicate - 每次迭代调用的断言函数
* @returns {Array} 返回过滤后的新数组
* @example
* filter([1, 2, 3], n => n > 1) => [2, 3]
* filter([{ a: 1 }, { a: 2 }], 'a') => [{ a: 1 }, { a: 2 }]
* filter([{ a: 1 }, { a: 2 }], ['a', 1]) => [{ a: 1 }]
*/
filter: function (collection, predicate) {
if (collection == null) return [];
const iteratee =
typeof predicate === "function"
? predicate
: function (obj) {
if (this.isArray(predicate)) {
return predicate.length
? obj[predicate[0]] === predicate[1]
: true;
}
if (typeof predicate === "object" && !this.isArray(predicate)) {
for (const key in predicate) {
if (!(key in obj) || obj[key] !== predicate[key]) {
return false;
}
}
return true;
}
return obj[predicate];
}.bind(this);
return Array.isArray(collection)
? collection.filter((value, index) => iteratee(value, index, collection))
: Object.entries(Object(collection))
.filter(([key, value]) => iteratee(value, key, collection))
.map(([_, value]) => value);
},
/**
* 遍历对象的自身和继承的可枚举属性
* @param {Object} object - 要遍历的对象
* @param {Function} iteratee - 每次迭代调用的函数
* @returns {Object} 返回对象本身
* @example
* forIn({ a: 1 }, (value, key) => console.log(key)) => 输出 'a'
*/
forIn: function (object, iteratee) {
if (object == null) return object;
object = Object(object);
for (const key in object) {
if (iteratee(object[key], key, object) === false) {
break;
}
}
return object;
},
/**
* 检查值是否为 Array 对象
* @param {*} value - 要检查的值
* @returns {boolean} 如果值为数组返回 true否则返回 false
* @example
* isArray([1, 2, 3]) => true
* isArray('abc') => false
*/
isArray: function (value) {
return Array.isArray(value);
},
/**
* 检查值是否为 Buffer 对象
* @param {*} value - 要检查的值
* @returns {boolean} 如果值为 Buffer 返回 true否则返回 false
* @example
* isBuffer(new Buffer(2)) => true
* isBuffer(new Uint8Array(2)) => false
*/
isBuffer: function (value) {
return value instanceof Buffer;
},
/**
* 检查值是否为空
* @param {*} value - 要检查的值
* @returns {boolean} 如果值为空返回 true否则返回 false
* @example
* isEmpty(null) => true
* isEmpty([1, 2, 3]) => false
* isEmpty('') => true
*/
isEmpty: function (value) {
if (value == null) return true;
if (
this.isArray(value) ||
typeof value === "string" ||
this.isBuffer(value) ||
value instanceof ArrayBuffer ||
(typeof value === "object" && "length" in value)
) {
return !value.length;
}
if (value instanceof Map || value instanceof Set) {
return !value.size;
}
if (value instanceof ArrayBuffer) {
return !value.byteLength;
}
if (typeof value === "object") {
return !Object.keys(Object(value)).length;
}
return true;
},
/**
* 检查值是否为 null 或 undefined
* @param {*} value - 要检查的值
* @returns {boolean} 如果值为 null 或 undefined 返回 true否则返回 false
* @example
* isNil(null) => true
* isNil(undefined) => true
* isNil(0) => false
*/
isNil: function (value) {
return value == null;
},
/**
* 检查值是否为对象
* @param {*} value - 要检查的值
* @returns {boolean} 如果值为对象返回 true否则返回 false
* @example
* isObject({}) => true
* isObject([1, 2, 3]) => true
* isObject(null) => false
*/
isObject: function (value) {
return value != null && typeof value === "object";
},
/**
* 创建一个对象,过滤掉不满足断言检查的属性
* @param {Object} object - 来源对象
* @param {Function} predicate - 断言函数,调用时传入 (value, key)
* @returns {Object} 返回过滤后的新对象
* @example
* omitBy({ a: 1, b: '2' }, value => typeof value === 'number') => { b: '2' }
*/
omitBy: function (object, predicate) {
if (object == null) return {};
object = Object(object);
const result = {};
for (const key in object) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
const value = object[key];
if (!predicate(value, key)) {
result[key] = value;
}
}
}
return result;
},
/**
* 从对象中选取指定的属性
* @param {Object} object - 来源对象
* @param {...(string|string[])} paths - 要获取的属性路径
* @returns {Object} 返回新对象
* @example
* pick({ a: 1, b: '2', c: 3 }, ['a', 'c']) => { a: 1, c: 3 }
*/
pick: function (object, ...paths) {
if (object == null) return {};
object = Object(object);
return (Array.isArray(paths[0]) ? paths[0] : paths).reduce(
(result, path) => {
if (path != null && object[path] !== undefined) {
result[path] = object[path];
}
return result;
},
{}
);
},
/**
* 移除数组中所有给定值
* @param {Array} array - 要修改的数组
* @param {...*} values - 要移除的值
* @returns {Array} 返回数组本身
* @example
* pull([1, 2, 3, 1, 2, 3], 2, 3) => [1, 1]
*/
pull: function (array, ...values) {
if (!array || !array.length || !values.length) return array;
let i = 0;
while (i < array.length) {
if (values.includes(array[i])) {
array.splice(i, 1);
} else {
i++;
}
}
return array;
},
/**
* 截断字符串
* @param {string} [string=''] - 要截断的字符串
* @param {Object} [options={}] - 选项对象
* @param {number} [options.length=30] - 允许的最大长度
* @param {string} [options.omission='...'] - 省略符号
* @param {RegExp|string} [options.separator] - 截断点
* @returns {string} 返回截断后的字符串
* @example
* truncate('hi-diddly-ho there, neighborino') => 'hi-diddly-ho there, neighbo...'
*/
truncate: function (string = "", options = {}) {
const { length = 30, omission = "...", separator } = options;
if (string.length <= length) return string;
const strLength = length - omission.length;
if (strLength < 1) return omission;
let result = string.slice(0, strLength);
if (separator) {
const lastIndex =
typeof separator === "string"
? result.lastIndexOf(separator)
: result.split("").reverse().join("").search(separator);
if (lastIndex > -1) {
result = result.slice(0, lastIndex);
}
}
return result + omission;
},
/**
* 创建一个去重后的数组
* @param {...Array} arrays - 要合并的数组
* @returns {Array} 返回新的去重数组
* @example
* union([2], [1, 2]) => [2, 1]
*/
union: function (...arrays) {
return [
...new Set(
arrays.reduce((result, arr) => {
if (Array.isArray(arr)) {
result.push(...arr);
}
return result;
}, [])
),
];
},
/**
* 获取对象的所有值
* @param {Object} object - 要获取值的对象
* @returns {Array} 返回对象值的数组
* @example
* values({ a: 1, b: 2 }) => [1, 2]
*/
values: function (object) {
if (object == null) return [];
return Object.values(Object(object));
},
/**
* 创建一个不包含指定值的数组
* @param {Array} array - 要检查的数组
* @param {...*} values - 要排除的值
* @returns {Array} 返回过滤后的新数组
* @example
* without([2, 1, 2, 3], 1, 2) => [3]
*/
without: function (array, ...values) {
return array == null
? []
: array.filter((value) => !values.includes(value));
},
};
module.exports = lodashMini;

View File

@@ -1,27 +1,36 @@
const getuToolsLite = () => { const getuToolsLite = () => {
var utoolsLite = Object.assign({}, _.cloneDeep(utools)) var utoolsLite = Object.assign({}, window.lodashM.cloneDeep(utools));
// if (utools.isDev()) return utoolsLite // if (utools.isDev()) return utoolsLite
const dbBlackList = [ const dbBlackList = [
"db", "db",
"dbStorage", "dbStorage",
"dbCryptoStorage", "dbCryptoStorage",
"removeFeature", "removeFeature",
"setFeature", "setFeature",
"onDbPull", "onDbPull",
]; ];
const payBlackList = ['fetchUserServerTemporaryToken', 'isPurchasedUser', 'openPurchase', 'getUserServerTemporaryToken', 'openPayment', 'fetchUserPayments'] const payBlackList = [
const etcBlackList = [ "fetchUserServerTemporaryToken",
"onPluginEnter", "isPurchasedUser",
"onPluginOut", "openPurchase",
"onMainPush", "getUserServerTemporaryToken",
"createBrowserWindow", "openPayment",
"team", "fetchUserPayments",
]; ];
_.concat(dbBlackList, payBlackList, etcBlackList).forEach(item => { const etcBlackList = [
delete utoolsLite[item] "onPluginEnter",
}) "onPluginOut",
Object.freeze(utoolsLite) "onMainPush",
return utoolsLite "createBrowserWindow",
} "team",
];
window.lodashM
.concat(dbBlackList, payBlackList, etcBlackList)
.forEach((item) => {
delete utoolsLite[item];
});
Object.freeze(utoolsLite);
return utoolsLite;
};
module.exports = getuToolsLite module.exports = getuToolsLite;

View File

@@ -8,7 +8,6 @@
"axios": "^1.7.9", "axios": "^1.7.9",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"lodash": "^4.17.21",
"node-forge": "^1.3.1", "node-forge": "^1.3.1",
"ses": "^1.10.0", "ses": "^1.10.0",
"sm-crypto": "^0.3.13", "sm-crypto": "^0.3.13",
@@ -116,11 +115,6 @@
"integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/mime-db": { "node_modules/mime-db": {
"version": "1.52.0", "version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
@@ -256,11 +250,6 @@
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",
"integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==" "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A=="
}, },
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"mime-db": { "mime-db": {
"version": "1.52.0", "version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",

View File

@@ -3,7 +3,6 @@
"axios": "^1.7.9", "axios": "^1.7.9",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"lodash": "^4.17.21",
"node-forge": "^1.3.1", "node-forge": "^1.3.1",
"ses": "^1.10.0", "ses": "^1.10.0",
"sm-crypto": "^0.3.13", "sm-crypto": "^0.3.13",

View File

@@ -15,7 +15,7 @@ const md5 = (input) => {
return crypto.createHash("md5").update(input, "utf8").digest("hex"); return crypto.createHash("md5").update(input, "utf8").digest("hex");
}; };
window._ = require("lodash"); window.lodashM = require("./lib/lodashMini");
const getCommandToLaunchTerminal = require("./lib/getCommandToLaunchTerminal"); const getCommandToLaunchTerminal = require("./lib/getCommandToLaunchTerminal");
const shortCodes = require("./lib/shortCodes"); const shortCodes = require("./lib/shortCodes");
@@ -113,7 +113,6 @@ let getSandboxFuns = () => {
electron, electron,
axios, axios,
Audio, Audio,
_,
AbortController, AbortController,
AbortSignal, AbortSignal,
Buffer, Buffer,
@@ -142,7 +141,7 @@ let liteErr = (e) => {
// vm 模块将无法在渲染进程中使用,改用 ses 来执行代码 // vm 模块将无法在渲染进程中使用,改用 ses 来执行代码
window.evalCodeInSandbox = (code, addVars = {}) => { window.evalCodeInSandbox = (code, addVars = {}) => {
let sandboxWithAD = Object.assign(addVars, getSandboxFuns()); let sandboxWithAD = Object.assign(addVars, getSandboxFuns());
sandboxWithAD.quickcommand = _.cloneDeep(quickcommand); sandboxWithAD.quickcommand = window.lodashM.cloneDeep(quickcommand);
try { try {
return new Compartment(sandboxWithAD).evaluate(code); return new Compartment(sandboxWithAD).evaluate(code);
} catch (error) { } catch (error) {
@@ -163,7 +162,7 @@ window.runCodeInSandbox = (code, callback, addVars = {}) => {
}, },
}; };
let sandboxWithAD = Object.assign(addVars, sandbox); let sandboxWithAD = Object.assign(addVars, sandbox);
sandboxWithAD.quickcommand = _.cloneDeep(quickcommand); sandboxWithAD.quickcommand = window.lodashM.cloneDeep(quickcommand);
if (addVars.enterData) { if (addVars.enterData) {
sandboxWithAD.quickcommand.enterData = addVars.enterData; sandboxWithAD.quickcommand.enterData = addVars.enterData;
sandboxWithAD.quickcommand.payload = addVars.enterData.payload; sandboxWithAD.quickcommand.payload = addVars.enterData.payload;
@@ -229,7 +228,7 @@ window.runCodeFile = (cmd, option, terminal, callback, realTime = true) => {
} else { } else {
cmdline = `${bin} ${argv} "${script}" ${scptarg}`; cmdline = `${bin} ${argv} "${script}" ${scptarg}`;
} }
let processEnv = _.cloneDeep(process.env); let processEnv = window.lodashM.cloneDeep(process.env);
if (envPath) processEnv.PATH = envPath; if (envPath) processEnv.PATH = envPath;
if (alias) cmdline = alias + "\n" + cmdline; if (alias) cmdline = alias + "\n" + cmdline;
// 在终端中输出 // 在终端中输出
@@ -293,7 +292,9 @@ window.quickcommandHttpServer = () => {
httpServer = http.createServer(); httpServer = http.createServer();
httpServer.on("request", (req, res) => { httpServer.on("request", (req, res) => {
if (req.method === "GET") { if (req.method === "GET") {
let parsedParams = _.cloneDeep(url.parse(req.url, true).query); let parsedParams = window.lodashM.cloneDeep(
url.parse(req.url, true).query
);
runUserCode(res, parsedParams); runUserCode(res, parsedParams);
} else if (req.method === "POST") { } else if (req.method === "POST") {
let data = []; let data = [];
@@ -307,7 +308,9 @@ window.quickcommandHttpServer = () => {
try { try {
parsedParams = JSON.parse(params); parsedParams = JSON.parse(params);
} catch (error) { } catch (error) {
parsedParams = _.cloneDeep(url.parse("?" + params, true).query); parsedParams = window.lodashM.cloneDeep(
url.parse("?" + params, true).query
);
} }
runUserCode(res, parsedParams); runUserCode(res, parsedParams);
}); });

View File

@@ -85,16 +85,19 @@ export default defineComponent({
let nativeProfile = this.utools.getDB( let nativeProfile = this.utools.getDB(
"cfg_" + utools.getNativeId() + "_profile" "cfg_" + utools.getNativeId() + "_profile"
); );
this.profile = Object.assign(_.cloneDeep(this.profile), commonProfile); this.profile = Object.assign(
window.lodashM.cloneDeep(this.profile),
commonProfile
);
this.nativeProfile = Object.assign( this.nativeProfile = Object.assign(
_.cloneDeep(this.nativeProfile), window.lodashM.cloneDeep(this.nativeProfile),
nativeProfile nativeProfile
); );
}, },
saveProfile() { saveProfile() {
this.utools.putDB(_.cloneDeep(this.profile), "cfg_profile"); this.utools.putDB(window.lodashM.cloneDeep(this.profile), "cfg_profile");
this.utools.putDB( this.utools.putDB(
_.cloneDeep(this.nativeProfile), window.lodashM.cloneDeep(this.nativeProfile),
"cfg_" + utools.getNativeId() + "_profile" "cfg_" + utools.getNativeId() + "_profile"
); );
}, },
@@ -103,9 +106,12 @@ export default defineComponent({
if (window.multiProcessDetection()) if (window.multiProcessDetection())
return console.log("multiProcess Detected"); return console.log("multiProcess Detected");
// 计划任务 // 计划任务
_.forIn(this.nativeProfile.crontabs, (cronExp, featureCode) => { window.lodashM.forIn(
this.runCronTask(featureCode, cronExp); this.nativeProfile.crontabs,
}); (cronExp, featureCode) => {
this.runCronTask(featureCode, cronExp);
}
);
// 快捷命令服务 // 快捷命令服务
if (this.nativeProfile.serverStatus) { if (this.nativeProfile.serverStatus) {
window.quickcommandHttpServer().run(this.nativeProfile.serverPort); window.quickcommandHttpServer().run(this.nativeProfile.serverPort);
@@ -221,7 +227,7 @@ export default defineComponent({
window.showUb.help(); window.showUb.help();
// 处理统计数据 // 处理统计数据
// let statisticsData = this.utools.getDB("cfg_statisticsData"); // let statisticsData = this.utools.getDB("cfg_statisticsData");
// _.forIn(statisticsData, (data, year) => { // window.lodashM.forIn(statisticsData, (data, year) => {
// statisticsData[year] = data.map((x) => { // statisticsData[year] = data.map((x) => {
// if (!x.command) return x; // if (!x.command) return x;
// let code = // let code =
@@ -238,7 +244,12 @@ export default defineComponent({
this.utools.setStorage("st_v300Inited", true); this.utools.setStorage("st_v300Inited", true);
}, },
getOpacityColor(color, percent) { getOpacityColor(color, percent) {
return color + parseInt(0xff * percent).toString(16).padStart(2, "0"); return (
color +
parseInt(0xff * percent)
.toString(16)
.padStart(2, "0")
);
}, },
}, },
watch: { watch: {

View File

@@ -49,7 +49,8 @@ export default {
computed: { computed: {
isPlatformSupported() { isPlatformSupported() {
let { platform } = this.commandInfo.features; let { platform } = this.commandInfo.features;
return !_.isEmpty(platform) && !platform.includes(window.processPlatform) return !window.lodashM.isEmpty(platform) &&
!platform.includes(window.processPlatform)
? false ? false
: true; : true;
}, },

View File

@@ -167,7 +167,10 @@ export default {
? this.$root.utools.getDB("cfg_codeHistory") ? this.$root.utools.getDB("cfg_codeHistory")
: this.action.data; : this.action.data;
quickCommandInfo?.program && quickCommandInfo?.program &&
Object.assign(this.quickcommandInfo, _.cloneDeep(quickCommandInfo)); Object.assign(
this.quickcommandInfo,
window.lodashM.cloneDeep(quickCommandInfo)
);
// 默认命令不可编辑 // 默认命令不可编辑
if (this.quickcommandInfo.tags?.includes("默认") && !utools.isDev()) { if (this.quickcommandInfo.tags?.includes("默认") && !utools.isDev()) {
this.canCommandSave = false; this.canCommandSave = false;
@@ -230,8 +233,11 @@ export default {
saveCurrentCommand(message = "保存成功") { saveCurrentCommand(message = "保存成功") {
let updatedData = this.$refs.sidebar?.SaveMenuData(); let updatedData = this.$refs.sidebar?.SaveMenuData();
if (!updatedData) return; if (!updatedData) return;
Object.assign(this.quickcommandInfo, _.cloneDeep(updatedData)); Object.assign(
let newQuickcommandInfo = _.cloneDeep(this.quickcommandInfo); this.quickcommandInfo,
window.lodashM.cloneDeep(updatedData)
);
let newQuickcommandInfo = window.lodashM.cloneDeep(this.quickcommandInfo);
this.$root.utools.putDB( this.$root.utools.putDB(
newQuickcommandInfo, newQuickcommandInfo,
"qc_" + this.quickcommandInfo.features.code "qc_" + this.quickcommandInfo.features.code
@@ -247,7 +253,7 @@ export default {
// 运行 // 运行
runCurrentCommand(cmd) { runCurrentCommand(cmd) {
this.saveToHistory(); // 运行时不保存但记录历史 this.saveToHistory(); // 运行时不保存但记录历史
let command = _.cloneDeep(this.quickcommandInfo); let command = window.lodashM.cloneDeep(this.quickcommandInfo);
if (cmd) command.cmd = cmd; if (cmd) command.cmd = cmd;
command.output = command.output =
this.$refs.sidebar?.currentCommand.output || this.$refs.sidebar?.currentCommand.output ||
@@ -257,7 +263,7 @@ export default {
}, },
saveCodeHistory() { saveCodeHistory() {
if (this.action.type !== "run") return; if (this.action.type !== "run") return;
let command = _.cloneDeep(this.quickcommandInfo); let command = window.lodashM.cloneDeep(this.quickcommandInfo);
command.cursorPosition = this.$refs.editor.getCursorPosition(); command.cursorPosition = this.$refs.editor.getCursorPosition();
this.$root.utools.putDB(command, "cfg_codeHistory"); this.$root.utools.putDB(command, "cfg_codeHistory");
}, },

View File

@@ -1,31 +1,63 @@
<template> <template>
<div> <div>
<q-dialog v-model="isResultShow" :position="fromUtools ? 'top' : 'bottom'" @hide="stopRun" :maximized="fromUtools" <q-dialog
:transition-duration="fromUtools ? 0 : 200"> v-model="isResultShow"
<q-card :style="{ :position="fromUtools ? 'top' : 'bottom'"
maxWidth: fromUtools ? '100%' : '700px', @hide="stopRun"
width: fromUtools ? '100%' : '700px', :maximized="fromUtools"
overflow: 'hidden', :transition-duration="fromUtools ? 0 : 200"
}"> >
<div v-if="!(enableHtml && fromUtools)" :style="{ <q-card
height: headerHeight + 'px', :style="{
}" class="flex items-center justify-between"> maxWidth: fromUtools ? '100%' : '700px',
width: fromUtools ? '100%' : '700px',
overflow: 'hidden',
}"
>
<div
v-if="!(enableHtml && fromUtools)"
:style="{
height: headerHeight + 'px',
}"
class="flex items-center justify-between"
>
<div> <div>
<q-avatar :size="`${headerHeight}`"> <q-avatar :size="`${headerHeight}`">
<q-icon :class="runResultStatus ? 'text-green' : 'text-red'" <q-icon
:name="runResultStatus ? 'task_alt' : 'error'" size="sm"></q-icon> :class="runResultStatus ? 'text-green' : 'text-red'"
:name="runResultStatus ? 'task_alt' : 'error'"
size="sm"
></q-icon>
</q-avatar> </q-avatar>
<span class="text-weight-bold text-h7">运行结果</span> <span class="text-weight-bold text-h7">运行结果</span>
</div> </div>
<ResultMenu class="no-shadow q-pa-sm" :stretch="true" :content="runResult.join('')" :closebtn="!fromUtools" <ResultMenu
:textbtn="!enableHtml" :imagebtn="!enableHtml && isDataUrl" @showImg="showBase64Img" :style="{ class="no-shadow q-pa-sm"
height: headerHeight + 'px', :stretch="true"
}" /> :content="runResult.join('')"
:closebtn="!fromUtools"
:textbtn="!enableHtml"
:imagebtn="!enableHtml && isDataUrl"
@showImg="showBase64Img"
:style="{
height: headerHeight + 'px',
}"
/>
</div> </div>
<div :style="{ maxHeight: maxHeight - headerHeight + 'px' }" class="scroll"> <div
<ResultArea v-if="isResultShow" @frameLoad="frameLoad" :frameInitHeight="frameInitHeight" :style="{ maxHeight: maxHeight - headerHeight + 'px' }"
:enableHtml="enableHtml" :runResultStatus="runResultStatus" :runResult="runResult" :key="timeStamp" class="scroll"
@mouseup="selectHandler" /> >
<ResultArea
v-if="isResultShow"
@frameLoad="frameLoad"
:frameInitHeight="frameInitHeight"
:enableHtml="enableHtml"
:runResultStatus="runResultStatus"
:runResult="runResult"
:key="timeStamp"
@mouseup="selectHandler"
/>
<q-resize-observer @resize="autoHeight" debounce="0" /> <q-resize-observer @resize="autoHeight" debounce="0" />
</div> </div>
<q-menu v-if="selectText" touch-position @before-hide="clearSelect"> <q-menu v-if="selectText" touch-position @before-hide="clearSelect">
@@ -36,7 +68,6 @@
</div> </div>
</template> </template>
<script> <script>
import outputTypes from "js/options/outputTypes.js"; import outputTypes from "js/options/outputTypes.js";
import specialVars from "js/options/specialVars.js"; import specialVars from "js/options/specialVars.js";
@@ -158,14 +189,14 @@ export default {
}, },
escapeItem(item) { escapeItem(item) {
// 无论什么类型先转为String // 无论什么类型先转为String
if (typeof item === 'object') { if (typeof item === "object") {
try { try {
item = JSON.stringify(item) item = JSON.stringify(item);
} catch (_) { } catch (_) {
item = item.toString() item = item.toString();
} }
} else { } else {
item = item.toString() item = item.toString();
} }
// 通过JSON.stringify将所有特殊字符转义输出为一个带双引号的字符串 // 通过JSON.stringify将所有特殊字符转义输出为一个带双引号的字符串
item = JSON.stringify(item) item = JSON.stringify(item)
@@ -174,19 +205,21 @@ export default {
// 单独转义单引号、反引号 // 单独转义单引号、反引号
.replace(/`|'/g, "\\$&") .replace(/`|'/g, "\\$&")
// 转义双括号 // 转义双括号
.replace(/\{\{/g, "\\{\\{") .replace(/\{\{/g, "\\{\\{");
// .replace("$", '$$$') // .replace("$", '$$$')
return item return item;
}, },
// 特殊变量赋值 // 特殊变量赋值
assignSpecialVars(cmd) { assignSpecialVars(cmd) {
let userData = this.$root.utools.userData.all(); let userData = this.$root.utools.userData.all();
let spVars = _.filter(specialVars, (sp) => sp.repl); let spVars = window.lodashM.filter(specialVars, (sp) => sp.repl);
_.forIn(spVars, (val, key) => { window.lodashM.forIn(spVars, (val, key) => {
let label = val.label.slice(0, -2); let label = val.label.slice(0, -2);
if (cmd.includes(label)) { if (cmd.includes(label)) {
let replData = label === "{{usr:" ? userData : this.$root.enterData; let replData = label === "{{usr:" ? userData : this.$root.enterData;
cmd = cmd.replace(val.match, (x) => this.escapeItem(val.repl(x, replData))); cmd = cmd.replace(val.match, (x) =>
this.escapeItem(val.repl(x, replData))
);
} }
}); });
return cmd; return cmd;
@@ -200,7 +233,7 @@ export default {
this.subInputValue = text; this.subInputValue = text;
}, placeholder); }, placeholder);
let querySubInput = () => { let querySubInput = () => {
let command = _.cloneDeep(currentCommand); let command = window.lodashM.cloneDeep(currentCommand);
command.cmd = currentCommand.cmd.replace( command.cmd = currentCommand.cmd.replace(
specialVars.subinput.match, specialVars.subinput.match,
this.subInputValue this.subInputValue
@@ -270,7 +303,7 @@ export default {
this.autoScroll(); this.autoScroll();
}, },
async handleContent(content) { async handleContent(content) {
if (!_.isArray(content)) content = [content]; if (!window.lodashM.isArray(content)) content = [content];
if (this.enableHtml) content = await this.cacheScript(content); if (this.enableHtml) content = await this.cacheScript(content);
return content; return content;
}, },

View File

@@ -81,7 +81,7 @@ export default {
}, },
mounted() { mounted() {
this.frameInit(); this.frameInit();
URL.revokeObjectURL(this.src) URL.revokeObjectURL(this.src);
}, },
methods: { methods: {
frameInit() { frameInit() {
@@ -109,8 +109,8 @@ export default {
quickcommand.showMessageBox(args.join(" "), "success", 0); quickcommand.showMessageBox(args.join(" "), "success", 0);
}; };
return { return {
quickcommand: _.cloneDeep(quickcommand), quickcommand: window.lodashM.cloneDeep(quickcommand),
utools: _.cloneDeep(utools), utools: window.lodashM.cloneDeep(utools),
parent: undefined, parent: undefined,
console: { console: {
log: showLog, log: showLog,

View File

@@ -176,7 +176,7 @@ export default {
}); });
}, },
getRawCommand() { getRawCommand() {
let command = _.cloneDeep(this.commandInfo); let command = window.lodashM.cloneDeep(this.commandInfo);
command.features.explain = window.removeHtmlTags( command.features.explain = window.removeHtmlTags(
command.features.explain command.features.explain
); );

View File

@@ -437,7 +437,7 @@ export default {
if (this.currentCommand.features.mainPush) return ["text"]; if (this.currentCommand.features.mainPush) return ["text"];
switch (this.$parent.quickcommandInfo.program) { switch (this.$parent.quickcommandInfo.program) {
case "quickcommand": case "quickcommand":
return _.without(this.outputTypesOptions, "terminal"); return window.lodashM.without(this.outputTypesOptions, "terminal");
case "html": case "html":
return ["html"]; return ["html"];
default: default:
@@ -476,7 +476,14 @@ export default {
this.cmdMatch = currentQuickCommandCmds.match; this.cmdMatch = currentQuickCommandCmds.match;
Object.assign( Object.assign(
this.currentCommand, this.currentCommand,
_.cloneDeep(_.pick(this.quickcommandInfo, "tags", "output", "features")) window.lodashM.cloneDeep(
window.lodashM.pick(
this.quickcommandInfo,
"tags",
"output",
"features"
)
)
); );
this.setIcon(this.quickcommandInfo.program); this.setIcon(this.quickcommandInfo.program);
this.platformVerify(); this.platformVerify();

View File

@@ -103,18 +103,18 @@ export default defineComponent({
}, },
created() { created() {
// 初始化本地配置 // 初始化本地配置
this.localConfigs = _.cloneDeep(this.configs); this.localConfigs = window.lodashM.cloneDeep(this.configs);
}, },
methods: { methods: {
updateConfigs() { updateConfigs() {
this.$emit("update:configs", _.cloneDeep(this.localConfigs)); this.$emit("update:configs", window.lodashM.cloneDeep(this.localConfigs));
}, },
}, },
watch: { watch: {
configs: { configs: {
deep: true, deep: true,
handler(newConfigs) { handler(newConfigs) {
this.localConfigs = _.cloneDeep(newConfigs); this.localConfigs = window.lodashM.cloneDeep(newConfigs);
}, },
}, },
selectedUA(value) { selectedUA(value) {

View File

@@ -87,7 +87,7 @@ export default defineComponent({
return { return {
step: 1, step: 1,
selectedActions: [], selectedActions: [],
configs: _.cloneDeep(defaultUBrowserConfigs), configs: window.lodashM.cloneDeep(defaultUBrowserConfigs),
}; };
}, },
methods: { methods: {

View File

@@ -181,20 +181,20 @@ export default defineComponent({
emits: ["update:configs"], emits: ["update:configs"],
data() { data() {
return { return {
localConfigs: _.cloneDeep(this.configs), localConfigs: window.lodashM.cloneDeep(this.configs),
}; };
}, },
methods: { methods: {
updateConfig(key, value) { updateConfig(key, value) {
this.localConfigs.run[key] = value; this.localConfigs.run[key] = value;
this.$emit("update:configs", _.cloneDeep(this.localConfigs)); this.$emit("update:configs", window.lodashM.cloneDeep(this.localConfigs));
}, },
}, },
watch: { watch: {
configs: { configs: {
deep: true, deep: true,
handler(newConfigs) { handler(newConfigs) {
this.localConfigs = _.cloneDeep(newConfigs); this.localConfigs = window.lodashM.cloneDeep(newConfigs);
}, },
}, },
}, },

View File

@@ -14,7 +14,9 @@
style="width: 280px" style="width: 280px"
autofocus autofocus
v-model="$root.profile.quickFileTag" v-model="$root.profile.quickFileTag"
@blur="$root.profile.quickFileTag || ($root.profile.quickFileTag = '文件')" @blur="
$root.profile.quickFileTag || ($root.profile.quickFileTag = '文件')
"
type="text" type="text"
> >
<template v-slot:append> <template v-slot:append>
@@ -25,7 +27,11 @@
color="primary" color="primary"
/> />
</template> </template>
<q-tooltip>启用后,选中文件可以通过超级面板快速将文件收藏到「{{ $root.profile.quickFileTag }}」标签</q-tooltip> <q-tooltip
>启用后,选中文件可以通过超级面板快速将文件收藏到「{{
$root.profile.quickFileTag
}}」标签</q-tooltip
>
</q-input> </q-input>
</q-item> </q-item>
<q-item> <q-item>
@@ -40,7 +46,9 @@
input-class="text-center" input-class="text-center"
style="width: 280px" style="width: 280px"
v-model="$root.profile.quickUrlTag" v-model="$root.profile.quickUrlTag"
@blur="$root.profile.quickUrlTag || ($root.profile.quickUrlTag = '网址')" @blur="
$root.profile.quickUrlTag || ($root.profile.quickUrlTag = '网址')
"
type="text" type="text"
> >
<template v-slot:append> <template v-slot:append>
@@ -51,7 +59,11 @@
color="primary" color="primary"
/> />
</template> </template>
<q-tooltip>启用后,在浏览器界面可以通过超级面板快速将网址收藏到「{{ $root.profile.quickUrlTag }}」标签</q-tooltip> <q-tooltip
>启用后,在浏览器界面可以通过超级面板快速将网址收藏到「{{
$root.profile.quickUrlTag
}}」标签</q-tooltip
>
</q-input> </q-input>
</q-item> </q-item>
<q-item> <q-item>
@@ -89,13 +101,19 @@
</q-item-section> </q-item-section>
<q-field dense outlined style="width: 280px"> <q-field dense outlined style="width: 280px">
<template v-slot:control> <template v-slot:control>
<div class="self-center full-width no-outline" tabindex="0">快捷命令服务</div> <div class="self-center full-width no-outline" tabindex="0">
快捷命令服务
</div>
</template> </template>
<template v-slot:append> <template v-slot:append>
<q-btn flat @click="$router.push('server')" icon="open_in_new" /> <q-btn flat @click="$router.push('server')" icon="open_in_new" />
</template> </template>
<q-tooltip> <q-tooltip>
通过本地监听 {{ $root.nativeProfile.serverPort }} 端口的形式,接收用户传送过来的参数,然后根据参数执行不同的操作 通过本地监听
{{
$root.nativeProfile.serverPort
}}
端口的形式,接收用户传送过来的参数,然后根据参数执行不同的操作
<br />需要配置插件跟随 utools 启动和保留后台<br />也可在主输入框通过关键字「快捷命令服务配置」进入 <br />需要配置插件跟随 utools 启动和保留后台<br />也可在主输入框通过关键字「快捷命令服务配置」进入
</q-tooltip> </q-tooltip>
</q-field> </q-field>
@@ -106,7 +124,9 @@
</q-item-section> </q-item-section>
<q-field dense outlined style="width: 280px"> <q-field dense outlined style="width: 280px">
<template v-slot:control> <template v-slot:control>
<div class="self-center full-width no-outline" tabindex="0">运行代码</div> <div class="self-center full-width no-outline" tabindex="0">
运行代码
</div>
</template> </template>
<template v-slot:append> <template v-slot:append>
<q-btn flat @click="$router.push('code')" icon="open_in_new" /> <q-btn flat @click="$router.push('code')" icon="open_in_new" />
@@ -124,13 +144,15 @@
import features from "js/options/quickFeatures.js"; import features from "js/options/quickFeatures.js";
export default { export default {
name: 'UtilityFeaturesMenu', name: "UtilityFeaturesMenu",
methods: { methods: {
toggleFeature(type, enable) { toggleFeature(type, enable) {
enable enable
? this.$root.utools.whole.setFeature(_.cloneDeep(features[type])) ? this.$root.utools.whole.setFeature(
window.lodashM.cloneDeep(features[type])
)
: this.$root.utools.whole.removeFeature(features[type].code); : this.$root.utools.whole.removeFeature(features[type].code);
} },
} },
}; };
</script> </script>

View File

@@ -144,7 +144,10 @@ export default {
this.$root.utools.whole.removeFeature( this.$root.utools.whole.removeFeature(
`panel_${window.hexEncode(this.currentTag)}` `panel_${window.hexEncode(this.currentTag)}`
); );
_.pull(this.$root.$refs.view.activatedQuickPanels, this.currentTag); window.lodashM.pull(
this.$root.$refs.view.activatedQuickPanels,
this.currentTag
);
quickcommand.showMessageBox("取消收藏成功"); quickcommand.showMessageBox("取消收藏成功");
}, },
}, },

View File

@@ -93,7 +93,8 @@ export default {
}, },
computed: { computed: {
cronConverted() { cronConverted() {
return _.values(this.cronDetail) return window.lodashM
.values(this.cronDetail)
.map((x) => x.value) .map((x) => x.value)
.join(" "); .join(" ");
}, },
@@ -129,7 +130,7 @@ export default {
window.showUb.help("#Q0e7s"); window.showUb.help("#Q0e7s");
}, },
initValue() { initValue() {
this.cronDetail = _.cloneDeep(this.default); this.cronDetail = window.lodashM.cloneDeep(this.default);
if (!this.cronExp) return; if (!this.cronExp) return;
let splited = this.cronExp.split(" "); let splited = this.cronExp.split(" ");
Object.keys(this.cronDetail).forEach((key, index) => { Object.keys(this.cronDetail).forEach((key, index) => {
@@ -149,7 +150,7 @@ export default {
}, },
delCrontab() { delCrontab() {
this.$emit("delCrontab"); this.$emit("delCrontab");
this.cronDetail = _.cloneDeep(this.default); this.cronDetail = window.lodashM.cloneDeep(this.default);
quickcommand.showMessageBox("禁用成功"); quickcommand.showMessageBox("禁用成功");
}, },
}, },

View File

@@ -47,12 +47,12 @@ export default {
if (item === null) return "null"; if (item === null) return "null";
if (typeof item === "undefined") return "undefined"; if (typeof item === "undefined") return "undefined";
if (typeof item === "string") if (typeof item === "string")
return _.truncate(item, { length: maxSize.txt }); return window.lodashM.truncate(item, { length: maxSize.txt });
if (typeof item === "number") return item; if (typeof item === "number") return item;
if (typeof item === "function") if (typeof item === "function")
return `f ${item.name ? item.name + "()" : "anonymous()"}`; return `f ${item.name ? item.name + "()" : "anonymous()"}`;
if (typeof item !== "object") return item.toString(); if (typeof item !== "object") return item.toString();
if (_.isBuffer(item)) { if (window.lodashM.isBuffer(item)) {
var bufferString = `[Buffer ${item var bufferString = `[Buffer ${item
.slice(0, maxSize.buff) .slice(0, maxSize.buff)
.toString("hex") .toString("hex")

View File

@@ -71,7 +71,9 @@ export default {
}, },
methods: { methods: {
markTag() { markTag() {
this.$root.utools.whole.setFeature(_.cloneDeep(this.features)); this.$root.utools.whole.setFeature(
window.lodashM.cloneDeep(this.features)
);
this.$root.$refs.view.activatedQuickPanels.push(this.currentTag); this.$root.$refs.view.activatedQuickPanels.push(this.currentTag);
quickcommand.showMessageBox( quickcommand.showMessageBox(
`主输入框输入『${this.features.cmds.join("、")}』即可直接进入『${ `主输入框输入『${this.features.cmds.join("、")}』即可直接进入『${

View File

@@ -170,7 +170,10 @@ export default {
return this.$root.utools.getDB("cfg_extraInfo"); return this.$root.utools.getDB("cfg_extraInfo");
}, },
saveYuQueInfo() { saveYuQueInfo() {
this.$root.utools.putDB(_.cloneDeep(this.yuQueInfo), "cfg_extraInfo"); this.$root.utools.putDB(
window.lodashM.cloneDeep(this.yuQueInfo),
"cfg_extraInfo"
);
}, },
}, },
}; };

View File

@@ -95,7 +95,7 @@ export default {
}; };
}, },
mounted() { mounted() {
this.plugins = _.values(window.getUtoolsPlugins()); this.plugins = window.lodashM.values(window.getUtoolsPlugins());
this.plugin = this.plugins[0]; this.plugin = this.plugins[0];
this.feature = this.features[0]; this.feature = this.features[0];
}, },

View File

@@ -65,16 +65,16 @@ export default {
hints: [], hints: [],
title: title, title: title,
}; };
if (!_.isObject(options)) if (!window.lodashM.isObject(options))
return reject(new TypeError(`应为 Object, 而非 ${typeof options}`)); return reject(new TypeError(`应为 Object, 而非 ${typeof options}`));
if (_.isArray(options)) props.labels = options; if (window.lodashM.isArray(options)) props.labels = options;
else Object.assign(props, options); else Object.assign(props, options);
this.showUI(InputBox, props, false, reslove); this.showUI(InputBox, props, false, reslove);
}), }),
showButtonBox: (labels = ["确定"], title = "") => showButtonBox: (labels = ["确定"], title = "") =>
new Promise((reslove, reject) => { new Promise((reslove, reject) => {
if (!_.isArray(labels)) if (!window.lodashM.isArray(labels))
return reject(new TypeError(`应为 Array, 而非 ${typeof labels}`)); return reject(new TypeError(`应为 Array, 而非 ${typeof labels}`));
this.showUI(ButtonBox, { labels, title }, false, reslove); this.showUI(ButtonBox, { labels, title }, false, reslove);
}), }),
@@ -90,7 +90,7 @@ export default {
}), }),
showMessageBox: (message, icon = "success", time, position = "top") => { showMessageBox: (message, icon = "success", time, position = "top") => {
message = _.truncate(message, { length: 1200 }); message = window.lodashM.truncate(message, { length: 1200 });
if (icon === "success") icon = "positive"; if (icon === "success") icon = "positive";
if (icon === "error") icon = "negative"; if (icon === "error") icon = "negative";
if (typeof time === "undefined") if (typeof time === "undefined")
@@ -119,7 +119,7 @@ export default {
showSelectList: (initItems, options = {}) => showSelectList: (initItems, options = {}) =>
new Promise((reslove, reject) => { new Promise((reslove, reject) => {
if (!_.isArray(initItems)) if (!window.lodashM.isArray(initItems))
return reject( return reject(
new TypeError(`应为 Array, 而非 ${typeof initItems}`) new TypeError(`应为 Array, 而非 ${typeof initItems}`)
); );

View File

@@ -33,10 +33,10 @@ const isPathMatched = (currentPath, targetPaths) => {
* @returns {Object} 处理后的对象 * @returns {Object} 处理后的对象
*/ */
const removeEmptyValues = (obj) => { const removeEmptyValues = (obj) => {
return _.omitBy(obj, (value) => { return window.lodashM.omitBy(obj, (value) => {
if (_.isNil(value) || value === "") return true; if (window.lodashM.isNil(value) || value === "") return true;
if (typeof value === "object") if (typeof value === "object")
return _.isEmpty(removeEmptyValues(value)); return window.lodashM.isEmpty(removeEmptyValues(value));
return false; return false;
}); });
}; };

View File

@@ -53,7 +53,7 @@ const commandTypes = {
disabledSpecialVars: disabledSpecialVars:
/{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}|{{MatchedFiles.*?}}/g, /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}|{{MatchedFiles.*?}}/g,
matchToCmds: (rules, desc) => rules, matchToCmds: (rules, desc) => rules,
verify: (rules) => !_.isEmpty(rules) || "关键词不能为空", verify: (rules) => !window.lodashM.isEmpty(rules) || "关键词不能为空",
}, },
regex: { regex: {
name: "regex", name: "regex",
@@ -120,7 +120,7 @@ const commandTypes = {
}, },
}, },
], ],
verify: (rules) => !_.isEmpty(rules) || "进程名不能为空", verify: (rules) => !window.lodashM.isEmpty(rules) || "进程名不能为空",
}, },
img: { img: {
name: "img", name: "img",

View File

@@ -27,7 +27,7 @@ export default {
}, },
methods: { methods: {
runCurrentCommand(command) { runCurrentCommand(command) {
this.$refs.result.runCurrentCommand(_.cloneDeep(command)); this.$refs.result.runCurrentCommand(window.lodashM.cloneDeep(command));
}, },
}, },
}; };

View File

@@ -102,7 +102,9 @@ export default {
computed: { computed: {
// 当前标签下的所有快捷命令 // 当前标签下的所有快捷命令
currentTagQuickCommands() { currentTagQuickCommands() {
let commands = Object.values(_.cloneDeep(this.allQuickCommands)); let commands = Object.values(
window.lodashM.cloneDeep(this.allQuickCommands)
);
// 根据 order 排序 // 根据 order 排序
const sortByOrder = (cmds) => { const sortByOrder = (cmds) => {
@@ -197,7 +199,7 @@ export default {
}, },
// 获取所有的命令(导出的格式) // 获取所有的命令(导出的格式)
getAllQuickCommands() { getAllQuickCommands() {
this.allQuickCommands = _.cloneDeep(defaultCommands); this.allQuickCommands = window.lodashM.cloneDeep(defaultCommands);
this.$root.utools.getAll("qc_").forEach((x) => { this.$root.utools.getAll("qc_").forEach((x) => {
if (x.data.features.code.includes("default_")) return; if (x.data.features.code.includes("default_")) return;
this.allQuickCommands[x.data.features.code] = x.data; this.allQuickCommands[x.data.features.code] = x.data;
@@ -206,9 +208,8 @@ export default {
}, },
getAllQuickCommandTags() { getAllQuickCommandTags() {
// 获取所有标签 // 获取所有标签
this.allQuickCommandTags = _.union( this.allQuickCommandTags = window.lodashM
...Object.values(this.allQuickCommands).map((x) => x.tags) .union(...Object.values(this.allQuickCommands).map((x) => x.tags))
)
.concat(["未分类"]) .concat(["未分类"])
.filter((x) => x); .filter((x) => x);
}, },
@@ -236,13 +237,13 @@ export default {
}, },
runCommand(code) { runCommand(code) {
this.$refs.result.runCurrentCommand( this.$refs.result.runCurrentCommand(
_.cloneDeep(this.allQuickCommands[code]) window.lodashM.cloneDeep(this.allQuickCommands[code])
); );
}, },
// 启用命令 // 启用命令
enableCommand(code) { enableCommand(code) {
this.$root.utools.whole.setFeature( this.$root.utools.whole.setFeature(
_.cloneDeep(this.allQuickCommands[code].features) window.lodashM.cloneDeep(this.allQuickCommands[code].features)
); );
this.activatedQuickCommandFeatureCodes.push(code); this.activatedQuickCommandFeatureCodes.push(code);
}, },
@@ -283,7 +284,7 @@ export default {
if (typeof command === "string") command = this.allQuickCommands[command]; if (typeof command === "string") command = this.allQuickCommands[command];
this.commandEditorAction = { this.commandEditorAction = {
type: "edit", type: "edit",
data: _.cloneDeep(command), data: window.lodashM.cloneDeep(command),
}; };
this.isCommandEditorShow = true; this.isCommandEditorShow = true;
}, },
@@ -356,7 +357,7 @@ export default {
}, },
], ],
}; };
let commandsToExport = _.cloneDeep(this.allQuickCommands); let commandsToExport = window.lodashM.cloneDeep(this.allQuickCommands);
// 不导出默认命令 // 不导出默认命令
Object.keys(commandsToExport).forEach((code) => { Object.keys(commandsToExport).forEach((code) => {
if (this.isDefaultCommand(code)) delete commandsToExport[code]; if (this.isDefaultCommand(code)) delete commandsToExport[code];
@@ -379,7 +380,7 @@ export default {
this.exportAllCommands(false); this.exportAllCommands(false);
this.$root.utools.delAll("qc_"); this.$root.utools.delAll("qc_");
this.clearAllFeatures(); this.clearAllFeatures();
this.allQuickCommands = _.cloneDeep(defaultCommands); this.allQuickCommands = window.lodashM.cloneDeep(defaultCommands);
this.getAllQuickCommandTags(); this.getAllQuickCommandTags();
this.changeCurrentTag("默认"); this.changeCurrentTag("默认");
quickcommand.showMessageBox( quickcommand.showMessageBox(
@@ -498,7 +499,10 @@ export default {
// 只保存被修改的命令 // 只保存被修改的命令
Object.entries(tagCommands).forEach(([code, command]) => { Object.entries(tagCommands).forEach(([code, command]) => {
if (!this.isDefaultCommand(code)) { if (!this.isDefaultCommand(code)) {
this.$root.utools.putDB(_.cloneDeep(command), "qc_" + code); this.$root.utools.putDB(
window.lodashM.cloneDeep(command),
"qc_" + code
);
} }
}); });
}, },

View File

@@ -21,7 +21,7 @@ export default {
}, },
methods: { methods: {
importCommand(command) { importCommand(command) {
command = _.cloneDeep(command); command = window.lodashM.cloneDeep(command);
this.$root.utools.putDB(command, "qc_" + command.features.code); this.$root.utools.putDB(command, "qc_" + command.features.code);
this.$root.utools.whole.setFeature(command.features); this.$root.utools.whole.setFeature(command.features);
}, },

View File

@@ -195,9 +195,9 @@ export default {
if (!code) if (!code)
return quickcommand.showMessageBox("该命令格式有误!", "error"); return quickcommand.showMessageBox("该命令格式有误!", "error");
this.installedCodes.push(code); this.installedCodes.push(code);
let pushData = _.cloneDeep(command); let pushData = window.lodashM.cloneDeep(command);
pushData.fromShare = true; pushData.fromShare = true;
this.$root.utools.putDB(_.cloneDeep(pushData), "qc_" + code); this.$root.utools.putDB(window.lodashM.cloneDeep(pushData), "qc_" + code);
// 通过模拟访问页面来统计下载量 // 通过模拟访问页面来统计下载量
utools.ubrowser utools.ubrowser
.goto(`https://www.yuque.com/${this.releaseRepo}/${code}`) .goto(`https://www.yuque.com/${this.releaseRepo}/${code}`)
@@ -249,7 +249,7 @@ export default {
this.compareTime(y.content_updated_at, x.content_updated_at) this.compareTime(y.content_updated_at, x.content_updated_at)
); );
this.checkCommands(); this.checkCommands();
this.matchedCommands = _.cloneDeep(this.remoteCommands); this.matchedCommands = window.lodashM.cloneDeep(this.remoteCommands);
this.fetchCommandDetails(1); this.fetchCommandDetails(1);
}); });
}, },
@@ -265,7 +265,7 @@ export default {
item.data.updateTime || "2022-04-01T00:00:00.000Z"; item.data.updateTime || "2022-04-01T00:00:00.000Z";
if (this.compareTime(remote.content_updated_at, localUpdateTime) > 0) { if (this.compareTime(remote.content_updated_at, localUpdateTime) > 0) {
needUpdate.push(code); needUpdate.push(code);
_.pull(this.remoteCommands, remote); window.lodashM.pull(this.remoteCommands, remote);
this.remoteCommands.unshift(remote); this.remoteCommands.unshift(remote);
} else installed.push(code); } else installed.push(code);
this.installedCodes = installed; this.installedCodes = installed;