From 3ad2bc10a3c61ed054b92e056fe34be43c9d78e7 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Wed, 7 Aug 2024 14:07:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/ec_api.js | 10 +++++++++ src/components/ec_api/TabArea.vue | 34 +++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/apis/ec_api.js b/src/apis/ec_api.js index aca300d..7ff95de 100644 --- a/src/apis/ec_api.js +++ b/src/apis/ec_api.js @@ -89,3 +89,13 @@ export const ec_api_send_request = (req_data) => { }) } +export const ec_api_get_suggest = (api_type, api) => { + return request({ + url: 'ec/get_suggest_params', + method: 'get', + params: { + member_type: api_type, + api: api + } + }) +} diff --git a/src/components/ec_api/TabArea.vue b/src/components/ec_api/TabArea.vue index a90de5f..ca91e57 100644 --- a/src/components/ec_api/TabArea.vue +++ b/src/components/ec_api/TabArea.vue @@ -3,10 +3,10 @@ import {ref, reactive, onBeforeMount, onMounted, onUnmounted, watch, watchEffect import Sortable from "sortablejs"; import {useStore, mapState} from "vuex"; import JsonEditorVue from "json-editor-vue3"; -import {ec_api_send_request, get_ec_api_request_url} from "@/apis/ec_api.js"; +import {ec_api_send_request, get_ec_api_request_url, ec_api_get_suggest} from "@/apis/ec_api.js"; import {Refresh} from "@element-plus/icons-vue"; import "@/VueAceEditor/aceConfig" -import { VAceEditor } from "vue3-ace-editor"; +import {VAceEditor} from "vue3-ace-editor"; import {ElMessage} from "element-plus"; @@ -196,10 +196,10 @@ function handle_request_url() { // 发送api请求 function send_request() { - if (UserApiData.value.api[activeTab.value].format === 'json'){ + if (UserApiData.value.api[activeTab.value].format === 'json') { UserApiData.value.api[activeTab.value].response = '{"root": "root"}' } - if (UserApiData.value.api[activeTab.value].format === 'html' || UserApiData.value.api[activeTab.value].format === 'xml'){ + if (UserApiData.value.api[activeTab.value].format === 'html' || UserApiData.value.api[activeTab.value].format === 'xml') { UserApiData.value.api[activeTab.value].response = '' } const data = handle_request_data() @@ -208,7 +208,7 @@ function send_request() { UserApiData.value.api[activeTab.value].response = JSON.stringify(JSON.parse(res.data), null, 2) } if (res.format === 'xml') { - const xmlDoc = new DOMParser().parseFromString(res.data , 'application/xml'); + const xmlDoc = new DOMParser().parseFromString(res.data, 'application/xml'); const serializer = new XMLSerializer(); UserApiData.value.api[activeTab.value].response = serializer.serializeToString(xmlDoc); } @@ -216,6 +216,27 @@ function send_request() { ) } +async function get_suggest() { + const api_type = UserApiData.value.api[activeTab.value].type + const api = UserApiData.value.api[activeTab.value].path + await ec_api_get_suggest(api_type, api).then( + (res) => { + console.log('get_suggest', api, res) + res.forEach((suggest) => { + UserApiData.value.api[activeTab.value].params.forEach((param) => { + if (param.param === suggest.param) { + param['value'] = suggest['value'] + param['default'] = suggest['value'] + param['is_checked'] = suggest['is_checked'] + } + }) + }) + } + ).catch((err) => { + console.log(err) + }) +} + // 用于测试,可以添加到需要的方法中 function test() { console.log('store.state.ecApiModule.ec_api_data', store.state.ecApiModule.ec_api_data) @@ -238,6 +259,7 @@ watch(() => store.state.ecApiModule.ec_api_data.api, (oldValue, newValue) => { // 监测activeTab, 如果切换标签页,则执行自动勾选的函数 watch(activeTab, () => { markIsChecked() + get_suggest() handle_request_url() }) @@ -357,7 +379,7 @@ const ace_options = { + theme="chrome" :options="ace_options" class="vue-ace-editor" :wrap="true" style="width: 1200px"/>