From aa4d10780658379db6bdaf76048c9973c380bf03 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Thu, 22 Aug 2024 13:41:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E6=96=B0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=8E=A8=E8=8D=90=E5=80=BC=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E5=8F=91=E9=80=81=E6=8C=89=E9=94=AE?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ec_api/TabArea.vue | 59 +++++++++++++++++-------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/components/ec_api/TabArea.vue b/src/components/ec_api/TabArea.vue index c7ea257..2781a0d 100644 --- a/src/components/ec_api/TabArea.vue +++ b/src/components/ec_api/TabArea.vue @@ -88,6 +88,7 @@ function initApiData() { 'handled': '', 'sig': '', 'format': 'json', + 'reload': true, 'params': store.state.ecApiModule.ec_api_data.api_params[item.id] } } @@ -135,7 +136,8 @@ function addNewParams() { // 读取参数默认值 function loadDefault(param) { console.log(param) - get_suggest(true) + UserApiData.value.api[activeTab.value].reload = true + get_suggest() } // 切换返回数据格式 @@ -223,39 +225,43 @@ function send_request() { req_loading.value = false send_btn.value = '发送' } - ) + ).catch(err => { + req_loading.value = false + send_btn.value = '发送' + ElMessage.error('获取请求结果失败!') + }) } -async function get_suggest(force) { - 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 (force) { - console.log('get_suggest force') - if (param.param === suggest.param) { - param['value'] = suggest['value'] - param['default'] = suggest['value'] - param['is_checked'] = suggest['is_checked'] +async function get_suggest() { + if (UserApiData.value.api[activeTab.value].reload === true) { + 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) + let result = true + if (res.length === 0) { + result = true + } + res.forEach((suggest) => { + UserApiData.value.api[activeTab.value].params.forEach((param) => { + if (suggest.result === false) { + result = false } - } else { - console.log('get_suggest else') - if (param.param === suggest.param && param['default'] === null) { + if (param.param === suggest.param) { param['value'] = suggest['value'] param['default'] = suggest['value'] param['is_checked'] = suggest['is_checked'] } - } + }) }) - }) - } - ).catch((err) => { - console.log(err) - }) + UserApiData.value.api[activeTab.value].reload = !result + } + ).catch((err) => { + console.log(err) + }) + } } // 用于测试,可以添加到需要的方法中 @@ -298,10 +304,11 @@ watch(() => store.state.ecApiModule.ec_api_data.api, (oldValue, newValue) => { } }, {deep: true}) + // 监测activeTab, 如果切换标签页,则执行自动勾选的函数 watch(activeTab, () => { markIsChecked() - get_suggest(false) + get_suggest() handle_request_url() })