From 15ad67a753e7ee00f6f59c7ed5785bacf2119e64 Mon Sep 17 00:00:00 2001 From: fofolee Date: Thu, 2 Jan 2025 11:48:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Axios=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=8F=8A=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../composer/http/AxiosConfigEditor.vue | 462 +++++++++++------- .../composer/ubrowser/UBrowserBasic.vue | 2 +- .../operations/UBrowserDeviceName.vue | 2 +- .../{httpHeaders.js => httpOptions.js} | 12 + 4 files changed, 291 insertions(+), 187 deletions(-) rename src/js/options/{httpHeaders.js => httpOptions.js} (95%) diff --git a/src/components/composer/http/AxiosConfigEditor.vue b/src/components/composer/http/AxiosConfigEditor.vue index 5bcad79..a7cd30d 100644 --- a/src/components/composer/http/AxiosConfigEditor.vue +++ b/src/components/composer/http/AxiosConfigEditor.vue @@ -6,15 +6,7 @@
-
-
- - - -
-
- + + + + + + + + + + +
+
+ + + +
+ +
+ +
+
+ + + + + {{ ua.label }} + + + + +
+ +
+ +
+
+
+ + + + -
-
- + + + -
-
-
+ - - - - - - -
-
- -
-
- - - - - {{ ua.label }} - - - - -
-
- - -
- - - -
- - -
- - - -
- - -
- - - -
- - -
- -
-
- -
-
- -
-
-
-
- - -
- -
-
- -
-
- -
-
- -
-
- -
-
-
+ + +
@@ -225,15 +164,19 @@ import { defineComponent } from "vue"; import VariableInput from "components/composer/ui/VariableInput.vue"; import DictEditor from "components/composer/ui/DictEditor.vue"; import { formatJsonVariables } from "js/composer/formatString"; -import { userAgent, commonHeaders, contentTypes } from "js/options/httpHeaders"; -import BorderLabel from "components/composer/ui/BorderLabel.vue"; +import { + userAgent, + commonHeaders, + contentTypes, + methods, + responseTypes, +} from "js/options/httpOptions"; export default defineComponent({ name: "AxiosConfigEditor", components: { VariableInput, DictEditor, - BorderLabel, }, props: { modelValue: { @@ -267,7 +210,8 @@ export default defineComponent({ url: "", method: "GET", headers: { - "Content-Type": "application/x-www-form-urlencoded", + "User-Agent": userAgent[0].value, + "Content-Type": contentTypes[0].value, }, params: {}, data: {}, @@ -288,12 +232,147 @@ export default defineComponent({ }, ...initialConfig, }, + methods, userAgentOptions: userAgent, contentTypes, commonHeaderOptions: commonHeaders .filter((h) => !["User-Agent", "Content-Type"].includes(h.value)) .map((h) => h.value), otherHeaders: {}, + activeTab: "headers", + commonPanels: [ + { + name: "response", + fields: [ + { + key: "responseType", + component: "q-select", + props: { + label: "响应类型", + filled: true, + dense: true, + "emit-value": true, + "map-options": true, + options: responseTypes, + "prepend-icon": "data_object", + }, + }, + { + key: "maxRedirects", + component: "VariableInput", + props: { + label: "最大重定向次数", + command: { icon: "repeat", inputType: "number" }, + }, + }, + { + key: "timeout", + component: "VariableInput", + props: { + label: "超时时间(ms)", + command: { icon: "timer", inputType: "number" }, + }, + }, + ], + }, + { + name: "auth", + fields: [ + { + key: "auth.username", + component: "VariableInput", + colClass: "col-6", + props: { + label: "用户名", + command: { icon: "person" }, + }, + }, + { + key: "auth.password", + component: "VariableInput", + colClass: "col-6", + props: { + label: "密码", + command: { icon: "password" }, + }, + }, + ], + }, + { + name: "proxy", + fields: [ + { + key: "proxy.host", + component: "VariableInput", + colClass: "col-6", + props: { + label: "主机", + command: { icon: "dns" }, + }, + }, + { + key: "proxy.port", + component: "VariableInput", + colClass: "col-6", + props: { + label: "端口", + command: { icon: "router", inputType: "number" }, + }, + }, + { + key: "proxy.auth.username", + component: "VariableInput", + colClass: "col-6", + props: { + label: "用户名", + command: { icon: "person" }, + }, + }, + { + key: "proxy.auth.password", + component: "VariableInput", + colClass: "col-6", + props: { + label: "密码", + command: { icon: "password" }, + }, + }, + ], + }, + ], + tabs: [ + { + name: "headers", + icon: "list_alt", + label: "请求头", + }, + { + name: "data", + icon: "data_object", + label: "请求体", + condition: () => this.hasRequestData, + }, + { + name: "params", + icon: "link", + label: "URL参数", + }, + { + name: "response", + icon: "settings", + label: "响应", + }, + { + name: "auth", + icon: "security", + label: "认证", + }, + { + name: "proxy", + icon: "dns", + label: "代理", + }, + ], }; }, created() { @@ -306,6 +385,9 @@ export default defineComponent({ hasRequestData() { return ["PUT", "POST", "PATCH"].includes(this.localConfig.method); }, + visibleTabs() { + return this.tabs.filter((tab) => !tab.condition || tab.condition()); + }, }, methods: { updateConfig() { @@ -341,6 +423,16 @@ export default defineComponent({ this.localConfig.headers["User-Agent"] = value; this.updateConfig(); }, + getFieldValue(path) { + return path.split(".").reduce((obj, key) => obj?.[key], this.localConfig); + }, + setFieldValue(path, value) { + const keys = path.split("."); + const lastKey = keys.pop(); + const target = keys.reduce((obj, key) => obj[key], this.localConfig); + target[lastKey] = value; + this.updateConfig(); + }, }, watch: { modelValue: { diff --git a/src/components/composer/ubrowser/UBrowserBasic.vue b/src/components/composer/ubrowser/UBrowserBasic.vue index 30efd7b..fcdf6b7 100644 --- a/src/components/composer/ubrowser/UBrowserBasic.vue +++ b/src/components/composer/ubrowser/UBrowserBasic.vue @@ -67,7 +67,7 @@