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() })