优化重新获取推荐值的逻辑,优化发送按键的处理逻辑

dev
RogerWork 3 months ago
parent 73825303c9
commit aa4d107806
  1. 35
      src/components/ec_api/TabArea.vue

@ -88,6 +88,7 @@ function initApiData() {
'handled': '', 'handled': '',
'sig': '', 'sig': '',
'format': 'json', 'format': 'json',
'reload': true,
'params': store.state.ecApiModule.ec_api_data.api_params[item.id] 'params': store.state.ecApiModule.ec_api_data.api_params[item.id]
} }
} }
@ -135,7 +136,8 @@ function addNewParams() {
// //
function loadDefault(param) { function loadDefault(param) {
console.log(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 req_loading.value = false
send_btn.value = '发送' send_btn.value = '发送'
} }
) ).catch(err => {
req_loading.value = false
send_btn.value = '发送'
ElMessage.error('获取请求结果失败!')
})
} }
async function get_suggest(force) { async function get_suggest() {
if (UserApiData.value.api[activeTab.value].reload === true) {
const api_type = UserApiData.value.api[activeTab.value].type const api_type = UserApiData.value.api[activeTab.value].type
const api = UserApiData.value.api[activeTab.value].path const api = UserApiData.value.api[activeTab.value].path
await ec_api_get_suggest(api_type, api).then( await ec_api_get_suggest(api_type, api).then(
(res) => { (res) => {
console.log('get_suggest', api, res) console.log('get_suggest', api, res)
let result = true
if (res.length === 0) {
result = true
}
res.forEach((suggest) => { res.forEach((suggest) => {
UserApiData.value.api[activeTab.value].params.forEach((param) => { UserApiData.value.api[activeTab.value].params.forEach((param) => {
if (force) { if (suggest.result === false) {
console.log('get_suggest force') result = false
if (param.param === suggest.param) {
param['value'] = suggest['value']
param['default'] = suggest['value']
param['is_checked'] = suggest['is_checked']
} }
} else { if (param.param === suggest.param) {
console.log('get_suggest else')
if (param.param === suggest.param && param['default'] === null) {
param['value'] = suggest['value'] param['value'] = suggest['value']
param['default'] = suggest['value'] param['default'] = suggest['value']
param['is_checked'] = suggest['is_checked'] param['is_checked'] = suggest['is_checked']
} }
}
}) })
}) })
UserApiData.value.api[activeTab.value].reload = !result
} }
).catch((err) => { ).catch((err) => {
console.log(err) console.log(err)
}) })
}
} }
// //
@ -298,10 +304,11 @@ watch(() => store.state.ecApiModule.ec_api_data.api, (oldValue, newValue) => {
} }
}, {deep: true}) }, {deep: true})
// activeTab // activeTab
watch(activeTab, () => { watch(activeTab, () => {
markIsChecked() markIsChecked()
get_suggest(false) get_suggest()
handle_request_url() handle_request_url()
}) })

Loading…
Cancel
Save