基本功能,发送请求和展示结果已完成

dev
RogerWork 4 months ago
parent adbe61b2e9
commit 16ac0df5b6
  1. 27
      src/apis/ec_api.js
  2. 8
      src/components/ec_api/BasicConfig.vue
  3. 120
      src/components/ec_api/TabArea.vue

@ -62,3 +62,30 @@ export const get_ec_api_api_group = (api_type) => {
} }
}) })
} }
export const get_ec_api_request_url = (req_data) => {
return request({
url: 'ec/get_url',
method: 'post',
data:{
env: req_data.env,
member_type: req_data.type,
api: req_data.api,
params: req_data.params
}
})
}
export const ec_api_send_request = (req_data) => {
return request({
url: 'ec/send_request',
method: 'post',
data:{
env: req_data.env,
member_type: req_data.type,
api: req_data.api,
params: req_data.params
}
})
}

@ -86,6 +86,10 @@ function type_on_change() {
get_api_params_by_type(SelectType.value) get_api_params_by_type(SelectType.value)
} }
function basic_info_change() {
store_data()
}
// //
async function get_api_by_type(api_type) { async function get_api_by_type(api_type) {
await get_ec_api_api(api_type).then(res => { await get_ec_api_api(api_type).then(res => {
@ -203,7 +207,7 @@ onMounted(() => {
</el-col> </el-col>
<el-col :span="5"> <el-col :span="5">
<label class="name-label">影院</label> <label class="name-label">影院</label>
<el-select v-model="SelectCinema" placeholder="请选择" style="width: 160px" size="default"> <el-select v-model="SelectCinema" placeholder="请选择" style="width: 160px" size="default" @change="basic_info_change">
<el-option <el-option
v-for="item in CinemaByEnv" v-for="item in CinemaByEnv"
:key="item.id" :key="item.id"
@ -228,7 +232,7 @@ onMounted(() => {
</el-col> </el-col>
<el-col :span="5"> <el-col :span="5">
<label class="name-label">渠道</label> <label class="name-label">渠道</label>
<el-select v-model="SelectChannel" placeholder="请选择" style="width: 160px" size="default"> <el-select v-model="SelectChannel" placeholder="请选择" style="width: 160px" size="default" @change="basic_info_change">
<el-option <el-option
v-for="item in ChannelByType" v-for="item in ChannelByType"
:key="item.id" :key="item.id"

@ -1,10 +1,10 @@
<script setup> <script setup>
import {ref, reactive, onBeforeMount, onMounted, onUnmounted, watch} from "vue"; import {ref, reactive, onBeforeMount, onMounted, onUnmounted, watch, watchEffect} from "vue";
import {getCurrentInstance} from 'vue'
import Sortable from "sortablejs"; import Sortable from "sortablejs";
import {useStore, mapState} from "vuex"; import {useStore, mapState} from "vuex";
import {nextTick} from "vue";
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 {Refresh} from "@element-plus/icons-vue";
// store // store
@ -48,6 +48,12 @@ function markIsChecked() {
} }
} }
// url'format', 'pid', '_sig'
function checkboxFilter(row) {
const special_params = ['format', 'pid', '_sig']
return special_params.indexOf(row.param) < 0;
}
// //
function initApiData() { function initApiData() {
// //
@ -69,6 +75,9 @@ function initApiData() {
'description': item.description, 'description': item.description,
'path': item.path, 'path': item.path,
'type': item.type, 'type': item.type,
'url': '',
'response': {},
'sig': '',
'params': store.state.ecApiModule.ec_api_data.api_params[item.id] 'params': store.state.ecApiModule.ec_api_data.api_params[item.id]
} }
} }
@ -79,6 +88,20 @@ function initApiData() {
delete UserApiData.value['api'][api['id']] delete UserApiData.value['api'][api['id']]
} }
}) })
// cidpid
Object.keys(UserApiData.value['api']).forEach(api_id => {
UserApiData.value['api'][api_id]['params'].forEach(
param_item => {
if (param_item['param'] === 'cid') {
param_item['value'] = UserApiData.value['base_info']['cinema']
}
if (param_item['param'] === 'pid') {
param_item['value'] = UserApiData.value['base_info']['channel']
}
}
)
})
// UserApiData // UserApiData
UserApiData.value.tab = api_tab UserApiData.value.tab = api_tab
} }
@ -97,14 +120,58 @@ function addNewParams() {
}) })
} }
// url
function handle_request_data() {
let data = {}
let req_data = {}
UserApiData.value.api[activeTab.value]['params'].forEach(
p => {
if (p['param'] !== '_sig' && p['is_checked'] === true) {
req_data[p['param']] = p['value']
}
}
)
data['env'] = UserApiData.value.base_info['env']
data['type'] = UserApiData.value.api[activeTab.value]['type']
data['api'] = UserApiData.value.api[activeTab.value]['path']
data['params'] = JSON.stringify(req_data)
return data
}
// url
function handle_request_url() {
const data = handle_request_data()
get_ec_api_request_url(data).then(res => {
console.log('handle_update_url', res)
UserApiData.value.api[activeTab.value]['url'] = res['url']
UserApiData.value.api[activeTab.value]['params'].forEach(p => {
if (p['param'] === '_sig') {
p['value'] = res['sig']
}
})
}).catch(err => console.log(err))
}
// api
function send_request() {
const data = handle_request_data()
ec_api_send_request(data).then(res => {
console.log('send_request', res)
UserApiData.value.api[activeTab.value].response = res
}
)
}
//
function test() { function test() {
console.log('store.state.ecApiModule.ec_api_data.api', store.state.ecApiModule.ec_api_data.api) console.log('store.state.ecApiModule.ec_api_data', store.state.ecApiModule.ec_api_data)
console.log('UserApiData.value', UserApiData.value) console.log('UserApiData.value', UserApiData.value)
console.log('activeTab.value', activeTab.value) // console.log('activeTab.value', activeTab.value)
} }
// ec_select_api // ec_select_api
watch(() => store.state.ecApiModule.ec_api_data.api, (oldValue, newValue) => { watch(() => store.state.ecApiModule.ec_api_data.api, (oldValue, newValue) => {
console.log('watch store.state.ecApiModule.ec_api_data.api')
// //
initApiData() initApiData()
// //
@ -117,8 +184,16 @@ watch(() => store.state.ecApiModule.ec_api_data.api, (oldValue, newValue) => {
// activeTab // activeTab
watch(activeTab, () => { watch(activeTab, () => {
markIsChecked() markIsChecked()
handle_request_url()
}) })
// url
watch(UserApiData.value, () => {
console.log('watch UserApiData', UserApiData.value)
handle_request_url()
}, {deep: true, flush: "post"})
/* /*
生命周期逻辑 生命周期逻辑
@ -143,8 +218,6 @@ onMounted(() => {
ghostClass: 'dragging', ghostClass: 'dragging',
draggable: '.el-tabs__item', draggable: '.el-tabs__item',
onEnd: (evt) => { onEnd: (evt) => {
console.log('evt.newIndex, evt.oldIndex', evt.newIndex, evt.oldIndex)
console.log('activeTab.value', activeTab.value)
store.commit('ecApiModule/handle_sort_ec_select_api', {'newIndex': evt.newIndex, 'oldIndex': evt.oldIndex}) store.commit('ecApiModule/handle_sort_ec_select_api', {'newIndex': evt.newIndex, 'oldIndex': evt.oldIndex})
}, },
}); });
@ -165,7 +238,7 @@ onMounted(() => {
@selection-change="handleParamsChange" @selection-change="handleParamsChange"
@select="handleParamsSelect" @select="handleParamsSelect"
> >
<el-table-column type="selection" width="50"/> <el-table-column type="selection" width="50" :selectable="checkboxFilter"/>
<el-table-column label="字段名" width="120"> <el-table-column label="字段名" width="120">
<template v-slot="scope"> <template v-slot="scope">
<span v-if="scope.row.is_preset">{{ scope.row.param }}</span> <span v-if="scope.row.is_preset">{{ scope.row.param }}</span>
@ -179,6 +252,15 @@ onMounted(() => {
<el-input type="textarea" placeholder="输入字段值" v-model="scope.row.value" rows="1" v-else></el-input> <el-input type="textarea" placeholder="输入字段值" v-model="scope.row.value" rows="1" v-else></el-input>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="重置" width="80">
<template v-slot="scope">
<el-button @click="test">
<el-icon>
<Refresh/>
</el-icon>
</el-button>
</template>
</el-table-column>
<el-table-column label="必选" width="80"> <el-table-column label="必选" width="80">
<template v-slot="scope"> <template v-slot="scope">
<span>{{ scope.row.is_request ? '是' : '否' }}</span> <span>{{ scope.row.is_request ? '是' : '否' }}</span>
@ -191,19 +273,20 @@ onMounted(() => {
<el-button type="primary" @click="addNewParams">添加新字段</el-button> <el-button type="primary" @click="addNewParams">添加新字段</el-button>
</el-col> </el-col>
</el-row> </el-row>
<el-row class="BtnRow" style="width: 100%" :gutter="10"> <hr id="break_line"/>
<el-col :span="2"><span>请求地址</span></el-col> <el-row class="BtnRow" style="width: 100%" :gutter="10" align="middle">
<el-col :span="2"><span style="font-weight: bold; color: #909399">请求地址</span></el-col>
<el-col :span="12"> <el-col :span="12">
<el-input type="text"></el-input> <el-input type="text" v-model="UserApiData.api[api['id']].url" :style="{'font-size': '18px'}"></el-input>
</el-col> </el-col>
<el-col :span="2"> <el-col :span="2">
<el-button type="primary" @click="test">发送</el-button> <el-button type="primary" @click="send_request">发送</el-button>
</el-col> </el-col>
<el-col :span="8"> <el-col :span="8">
</el-col> </el-col>
</el-row> </el-row>
<JsonEditorVue class="editor" v-model="json_data" language="zh-CN" @change="handleRunningChange" <JsonEditorVue class="editor" v-model="UserApiData.api[api['id']].response" language="zh-CN"
style="width: 1600px"/> style="width: 1600px; height: 500px"/>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</template> </template>
@ -215,6 +298,15 @@ onMounted(() => {
.editor { .editor {
margin-top: 20px; margin-top: 20px;
margin-bottom: 20px;
}
#break_line {
margin-top: 30px;
margin-bottom: 30px;
background-color: rgba(144, 147, 153, 0.5);
height: 1px;
border: none
} }
</style> </style>

Loading…
Cancel
Save