From 923fc9e4de1dd44035d685fee15a0facae86a833 Mon Sep 17 00:00:00 2001 From: fofolee Date: Sun, 5 Jan 2025 13:08:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E6=8E=92=E6=B7=BB=E5=8A=A0=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E8=B7=AF=E5=BE=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/lib/quickcomposer.js | 2 +- plugin/lib/quickcomposer/system/exec.js | 10 +- plugin/lib/quickcomposer/system/index.js | 2 + plugin/lib/quickcomposer/system/path.js | 150 ++++++ .../{textProcessor => text}/crypto.js | 0 .../{textProcessor => text}/encoder.js | 0 .../{textProcessor => text}/hash.js | 0 .../{textProcessor => text}/index.js | 0 .../{textProcessor => text}/string.js | 0 .../{textProcessor => text}/utils.js | 0 src/components/composer/system/PathEditor.vue | 472 ++++++++++++++++++ src/components/composer/ui/VariableInput.vue | 20 +- src/js/composer/cardComponents.js | 4 + src/js/composer/commands/index.js | 4 +- src/js/composer/commands/systemCommands.js | 10 + ...xtProcessorCommands.js => textCommands.js} | 44 +- 16 files changed, 684 insertions(+), 34 deletions(-) create mode 100644 plugin/lib/quickcomposer/system/path.js rename plugin/lib/quickcomposer/{textProcessor => text}/crypto.js (100%) rename plugin/lib/quickcomposer/{textProcessor => text}/encoder.js (100%) rename plugin/lib/quickcomposer/{textProcessor => text}/hash.js (100%) rename plugin/lib/quickcomposer/{textProcessor => text}/index.js (100%) rename plugin/lib/quickcomposer/{textProcessor => text}/string.js (100%) rename plugin/lib/quickcomposer/{textProcessor => text}/utils.js (100%) create mode 100644 src/components/composer/system/PathEditor.vue rename src/js/composer/commands/{textProcessorCommands.js => textCommands.js} (67%) diff --git a/plugin/lib/quickcomposer.js b/plugin/lib/quickcomposer.js index 4fb8c88..5b89605 100644 --- a/plugin/lib/quickcomposer.js +++ b/plugin/lib/quickcomposer.js @@ -1,5 +1,5 @@ const quickcomposer = { - textProcessor: require("./quickcomposer/textProcessor"), + text: require("./quickcomposer/text"), simulate: require("./quickcomposer/simulate"), file: require("./quickcomposer/file"), system: require("./quickcomposer/system"), diff --git a/plugin/lib/quickcomposer/system/exec.js b/plugin/lib/quickcomposer/system/exec.js index 399c94f..241b252 100644 --- a/plugin/lib/quickcomposer/system/exec.js +++ b/plugin/lib/quickcomposer/system/exec.js @@ -1,13 +1,17 @@ -const { execSync } = require("child_process"); +const { exec: execAsync } = require("child_process"); const iconv = require("iconv-lite"); const os = require("os"); +const util = require("util"); + +// 将 exec 转换为 Promise 版本 +const execPromise = util.promisify(execAsync); function getSystemEncoding() { // Windows 默认使用 GBK/GB2312,其他系统默认 UTF-8 return os.platform() === "win32" ? "gbk" : "utf8"; } -function exec(command, options = {}) { +async function exec(command, options = {}) { try { const { autoEncoding = true, @@ -17,7 +21,7 @@ function exec(command, options = {}) { } = options; // 执行命令,总是使用 buffer 获取原始输出 - const output = execSync(command, { + const { stdout: output } = await execPromise(command, { ...execOptions, encoding: "buffer", windowsHide, diff --git a/plugin/lib/quickcomposer/system/index.js b/plugin/lib/quickcomposer/system/index.js index faaa178..ee3a93e 100644 --- a/plugin/lib/quickcomposer/system/index.js +++ b/plugin/lib/quickcomposer/system/index.js @@ -1,7 +1,9 @@ const exec = require("./exec"); const os = require("./os"); +const path = require("./path"); module.exports = { exec, os, + path, }; diff --git a/plugin/lib/quickcomposer/system/path.js b/plugin/lib/quickcomposer/system/path.js new file mode 100644 index 0000000..b30a1c6 --- /dev/null +++ b/plugin/lib/quickcomposer/system/path.js @@ -0,0 +1,150 @@ +const path = require("path"); + +/** + * 规范化路径 + * @param {string} p 要规范化的路径 + * @returns {string} 规范化后的路径 + */ +async function normalize(p) { + try { + return path.normalize(p); + } catch (error) { + throw new Error(`路径规范化失败: ${error.message}`); + } +} + +/** + * 连接路径片段 + * @param {...string} paths 路径片段 + * @returns {string} 连接后的路径 + */ +async function join(...paths) { + try { + return path.join(...paths); + } catch (error) { + throw new Error(`路径连接失败: ${error.message}`); + } +} + +/** + * 解析路径 + * @param {string} p 要解析的路径 + * @returns {Object} 解析结果,包含 root, dir, base, ext, name + */ +async function parse(p) { + try { + return path.parse(p); + } catch (error) { + throw new Error(`路径解析失败: ${error.message}`); + } +} + +/** + * 获取路径的目录名 + * @param {string} p 路径 + * @returns {string} 目录名 + */ +async function dirname(p) { + try { + return path.dirname(p); + } catch (error) { + throw new Error(`获取目录名失败: ${error.message}`); + } +} + +/** + * 获取路径的文件名 + * @param {string} p 路径 + * @param {string} [ext] 可选的扩展名,如果提供则从结果中移除 + * @returns {string} 文件名 + */ +async function basename(p, ext) { + try { + return path.basename(p, ext); + } catch (error) { + throw new Error(`获取文件名失败: ${error.message}`); + } +} + +/** + * 获取路径的扩展名 + * @param {string} p 路径 + * @returns {string} 扩展名 + */ +async function extname(p) { + try { + return path.extname(p); + } catch (error) { + throw new Error(`获取扩展名失败: ${error.message}`); + } +} + +/** + * 判断路径是否为绝对路径 + * @param {string} p 路径 + * @returns {boolean} 是否为绝对路径 + */ +async function isAbsolute(p) { + try { + return path.isAbsolute(p); + } catch (error) { + throw new Error(`判断绝对路径失败: ${error.message}`); + } +} + +/** + * 计算相对路径 + * @param {string} from 起始路径 + * @param {string} to 目标路径 + * @returns {string} 相对路径 + */ +async function relative(from, to) { + try { + return path.relative(from, to); + } catch (error) { + throw new Error(`计算相对路径失败: ${error.message}`); + } +} + +/** + * 将路径解析为绝对路径 + * @param {...string} paths 路径片段 + * @returns {string} 解析后的绝对路径 + */ +async function resolve(...paths) { + try { + return path.resolve(...paths); + } catch (error) { + throw new Error(`解析绝对路径失败: ${error.message}`); + } +} + +/** + * 格式化路径对象为路径字符串 + * @param {Object} pathObject 路径对象,包含 dir, root, base, name, ext + * @returns {string} 格式化后的路径 + */ +async function format(pathObject) { + try { + return path.format(pathObject); + } catch (error) { + throw new Error(`格式化路径失败: ${error.message}`); + } +} + +module.exports = { + normalize, + join, + parse, + dirname, + basename, + extname, + isAbsolute, + relative, + resolve, + format, + sep: path.sep, + delimiter: path.delimiter, + win32: path.win32, + posix: path.posix, +}; diff --git a/plugin/lib/quickcomposer/textProcessor/crypto.js b/plugin/lib/quickcomposer/text/crypto.js similarity index 100% rename from plugin/lib/quickcomposer/textProcessor/crypto.js rename to plugin/lib/quickcomposer/text/crypto.js diff --git a/plugin/lib/quickcomposer/textProcessor/encoder.js b/plugin/lib/quickcomposer/text/encoder.js similarity index 100% rename from plugin/lib/quickcomposer/textProcessor/encoder.js rename to plugin/lib/quickcomposer/text/encoder.js diff --git a/plugin/lib/quickcomposer/textProcessor/hash.js b/plugin/lib/quickcomposer/text/hash.js similarity index 100% rename from plugin/lib/quickcomposer/textProcessor/hash.js rename to plugin/lib/quickcomposer/text/hash.js diff --git a/plugin/lib/quickcomposer/textProcessor/index.js b/plugin/lib/quickcomposer/text/index.js similarity index 100% rename from plugin/lib/quickcomposer/textProcessor/index.js rename to plugin/lib/quickcomposer/text/index.js diff --git a/plugin/lib/quickcomposer/textProcessor/string.js b/plugin/lib/quickcomposer/text/string.js similarity index 100% rename from plugin/lib/quickcomposer/textProcessor/string.js rename to plugin/lib/quickcomposer/text/string.js diff --git a/plugin/lib/quickcomposer/textProcessor/utils.js b/plugin/lib/quickcomposer/text/utils.js similarity index 100% rename from plugin/lib/quickcomposer/textProcessor/utils.js rename to plugin/lib/quickcomposer/text/utils.js diff --git a/src/components/composer/system/PathEditor.vue b/src/components/composer/system/PathEditor.vue new file mode 100644 index 0000000..9dfed1f --- /dev/null +++ b/src/components/composer/system/PathEditor.vue @@ -0,0 +1,472 @@ + + + + + diff --git a/src/components/composer/ui/VariableInput.vue b/src/components/composer/ui/VariableInput.vue index 7e58315..2d42739 100644 --- a/src/components/composer/ui/VariableInput.vue +++ b/src/components/composer/ui/VariableInput.vue @@ -48,12 +48,12 @@ v-if="variables.length" > - - + + 选择变量 - +