增加参数推荐逻辑

dev
RogerWork 3 months ago
parent a928823497
commit 3ad2bc10a3
  1. 10
      src/apis/ec_api.js
  2. 34
      src/components/ec_api/TabArea.vue

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

@ -3,10 +3,10 @@ import {ref, reactive, onBeforeMount, onMounted, onUnmounted, watch, watchEffect
import Sortable from "sortablejs"; import Sortable from "sortablejs";
import {useStore, mapState} from "vuex"; import {useStore, mapState} from "vuex";
import JsonEditorVue from "json-editor-vue3"; 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 {Refresh} from "@element-plus/icons-vue";
import "@/VueAceEditor/aceConfig" import "@/VueAceEditor/aceConfig"
import { VAceEditor } from "vue3-ace-editor"; import {VAceEditor} from "vue3-ace-editor";
import {ElMessage} from "element-plus"; import {ElMessage} from "element-plus";
@ -196,10 +196,10 @@ function handle_request_url() {
// api // api
function send_request() { 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"}' 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 = '<root></root>' UserApiData.value.api[activeTab.value].response = '<root></root>'
} }
const data = handle_request_data() 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) UserApiData.value.api[activeTab.value].response = JSON.stringify(JSON.parse(res.data), null, 2)
} }
if (res.format === 'xml') { 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(); const serializer = new XMLSerializer();
UserApiData.value.api[activeTab.value].response = serializer.serializeToString(xmlDoc); 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() { function test() {
console.log('store.state.ecApiModule.ec_api_data', store.state.ecApiModule.ec_api_data) 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 // activeTab
watch(activeTab, () => { watch(activeTab, () => {
markIsChecked() markIsChecked()
get_suggest()
handle_request_url() handle_request_url()
}) })
@ -357,7 +379,7 @@ const ace_options = {
</el-col> </el-col>
</el-row> </el-row>
<v-ace-editor v-model:value="UserApiData.api[api['id']].response" :lang="UserApiData.api[api['id']]['format']" <v-ace-editor v-model:value="UserApiData.api[api['id']].response" :lang="UserApiData.api[api['id']]['format']"
theme="chrome" :options="ace_options" class="vue-ace-editor" :wrap="true" style="width: 1200px"/> theme="chrome" :options="ace_options" class="vue-ace-editor" :wrap="true" style="width: 1200px"/>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</template> </template>

Loading…
Cancel
Save