From 01183d06e89e74ef6fa35b5f9ee15e2409c32294 Mon Sep 17 00:00:00 2001 From: fofolee Date: Wed, 8 Jan 2025 17:35:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E6=8E=92=E6=96=B0=E5=A2=9EHTML?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E3=80=81=E4=B8=8A=E4=BC=A0=E3=80=81=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/lib/quickcommand.js | 9 +- plugin/lib/quickcomposer/data/htmlParser.js | 14 ++ plugin/lib/quickcomposer/data/index.js | 2 + .../composer/common/ArrayEditor.vue | 160 +++++++------- .../composer/common/BorderLabel.vue | 16 +- src/components/composer/common/DictEditor.vue | 200 ++++++++++-------- src/components/composer/common/ParamInput.vue | 5 + .../composer/system/SystemCommandEditor.vue | 22 +- src/js/composer/commands/dataCommands.js | 38 ++++ src/js/composer/commands/networkCommands.js | 60 ++++++ 10 files changed, 346 insertions(+), 180 deletions(-) create mode 100644 plugin/lib/quickcomposer/data/htmlParser.js diff --git a/plugin/lib/quickcommand.js b/plugin/lib/quickcommand.js index 1bb294d..37c2939 100644 --- a/plugin/lib/quickcommand.js +++ b/plugin/lib/quickcommand.js @@ -4,6 +4,7 @@ const fs = require("fs"); const kill = require("tree-kill"); const iconv = require("iconv-lite"); const path = require("path"); +const axios = require("axios"); const getQuickcommandTempFile = require("./getQuickcommandTempFile"); const getCommandToLaunchTerminal = require("./getCommandToLaunchTerminal"); @@ -72,9 +73,9 @@ const quickcommand = { }, // 下载文件 - downloadFile: function (url, file = {}) { + downloadFile: function (url, file) { return new Promise((reslove, reject) => { - if (file instanceof Object) + if (!file || file instanceof Object) file = window.utools.showSaveDialog(JSON.parse(JSON.stringify(file))); axios({ method: "get", @@ -95,13 +96,13 @@ const quickcommand = { }, // 上传文件 - uploadFile: function (url, file = {}, name = "file", formData = {}) { + uploadFile: function (url, file, name = "file", formData = {}) { return new Promise((reslove, reject) => { var objfile; if (file instanceof File) { objfile = file; } else { - if (file instanceof Object) + if (!file || file instanceof Object) file = window.utools.showOpenDialog( JSON.parse(JSON.stringify(file)) )[0]; diff --git a/plugin/lib/quickcomposer/data/htmlParser.js b/plugin/lib/quickcomposer/data/htmlParser.js new file mode 100644 index 0000000..ba4d2b0 --- /dev/null +++ b/plugin/lib/quickcomposer/data/htmlParser.js @@ -0,0 +1,14 @@ +const htmlParser = (html, selector = "", attr = "") => { + const parser = new DOMParser(); + const doc = parser.parseFromString(html, "text/html"); + if (!selector) return doc; + const elements = doc.querySelectorAll(selector); + if (!attr) return elements; + let result = Array.from(elements).map((element) => element[attr]); + if (result.length === 1) return result[0]; + return result; +}; + +module.exports = { + htmlParser, +}; diff --git a/plugin/lib/quickcomposer/data/index.js b/plugin/lib/quickcomposer/data/index.js index 7349068..6241c92 100644 --- a/plugin/lib/quickcomposer/data/index.js +++ b/plugin/lib/quickcomposer/data/index.js @@ -1,9 +1,11 @@ const string = require("./string"); const buffer = require("./buffer"); const zlib = require("./zlib"); +const htmlParser = require("./htmlParser"); module.exports = { ...string, + ...htmlParser, buffer, zlib, }; diff --git a/src/components/composer/common/ArrayEditor.vue b/src/components/composer/common/ArrayEditor.vue index c5f536e..41af7fc 100644 --- a/src/components/composer/common/ArrayEditor.vue +++ b/src/components/composer/common/ArrayEditor.vue @@ -1,82 +1,89 @@