解决了切换常用场景el-table中ref数据混乱的问题,为组件绑定key后使用v-if来销毁组件,每次切换都换生成新组件

dev
RogerWork 3 months ago
parent b8b50efadc
commit 3111e62014
  1. 15
      src/components/ec_api/ApiLockBuySelector.vue
  2. 20
      src/components/ec_api/BasicConfig.vue
  3. 12
      src/components/ec_api/CheckQuan.vue
  4. 41
      src/components/ec_api/TabArea.vue
  5. 9
      src/store/index.js
  6. 2
      src/views/ec_api/index.vue

@ -1,13 +1,16 @@
<script setup> <script setup>
import {ref, watch} from 'vue' import {ref, watch} from 'vue'
// // props
const selectSaleType = ref('ticket') const props =defineProps(['type'])
const selectPayType = ref('cash')
// emits // emits
const emits = defineEmits(["getSaleType", "getPayType"]) const emits = defineEmits(["getSaleType", "getPayType"])
//
const selectSaleType = props.type === 'goods' ? ref('goods') : ref('ticket')
const selectPayType = ref('cash')
// //
watch( ()=>selectSaleType.value, ()=>{ watch( ()=>selectSaleType.value, ()=>{
emits("getSaleType", selectSaleType.value) emits("getSaleType", selectSaleType.value)
@ -26,9 +29,9 @@ watch( ()=>selectPayType.value, ()=>{
<el-col :span="1" style="font-size: 14px; font-weight: bold; color: #919399;" class="col-right">售卖类型</el-col> <el-col :span="1" style="font-size: 14px; font-weight: bold; color: #919399;" class="col-right">售卖类型</el-col>
<el-col :span="6" class="col-left"> <el-col :span="6" class="col-left">
<el-radio-group v-model="selectSaleType"> <el-radio-group v-model="selectSaleType">
<el-radio label="ticket">单影票</el-radio> <el-radio label="ticket" v-if="props['type'] === 'ticket'">单影票</el-radio>
<el-radio label="goods">单卖品</el-radio> <el-radio label="goods" v-if="props['type'] === 'goods'">单卖品</el-radio>
<el-radio label="all">影票加卖品</el-radio> <el-radio label="all" v-if="props['type'] === 'ticket'">影票加卖品</el-radio>
</el-radio-group> </el-radio-group>
</el-col> </el-col>
</el-row> </el-row>

@ -12,6 +12,7 @@ import {ref, reactive, toRefs} from "vue";
import {onMounted} from "vue"; import {onMounted} from "vue";
import {useStore} from "vuex"; import {useStore} from "vuex";
import {change_cinema_user} from "@/apis/update.js"; import {change_cinema_user} from "@/apis/update.js";
import TabArea from "@/components/ec_api/TabArea.vue";
// store // store
@ -43,7 +44,7 @@ const SelectApi = ref([]) // 存储选择的接口
// //
const ApiGroup = ref({}) const ApiGroup = ref({})
const SelectApiGroup = ref([]) const SelectApiGroup = ref('')
// //
const ApiParams = ref({}) const ApiParams = ref({})
@ -71,7 +72,7 @@ function type_on_change() {
ChannelByType.value = [] ChannelByType.value = []
SelectChannel.value = '' SelectChannel.value = ''
SelectApiId.value = [] SelectApiId.value = []
SelectApiGroup.value = [] SelectApiGroup.value = ''
// //
Channel.value.forEach(data => { Channel.value.forEach(data => {
if (data.type === SelectType.value && data.env === SelectEnv.value) { if (data.type === SelectType.value && data.env === SelectEnv.value) {
@ -140,15 +141,22 @@ async function get_api_params_by_type(api_type) {
// OnChange // OnChange
// //
function api_group_on_change() { function api_group_on_change() {
SelectApiId.value = JSON.parse(String(SelectApiGroup.value)) store.state.ecApiModule.ec_api_data.api = []
store.state.ecApiModule.show_tab_area = false
store.state.ecApiModule.group_api_id = SelectApiGroup.value
ApiGroup.value.forEach(item => {
if (String(item['id']) === SelectApiGroup.value) {
SelectApiId.value = JSON.parse(item['api_id'])
}
})
handle_api_data() handle_api_data()
store_data() store_data()
store.state.ecApiModule.show_tab_area = true
} }
// //
function api_on_change() { function api_on_change() {
SelectApiGroup.value = [] SelectApiGroup.value = ''
handle_api_data() handle_api_data()
store_data() store_data()
} }
@ -281,7 +289,7 @@ onMounted(() => {
v-for="item in ApiGroup" v-for="item in ApiGroup"
:key="item.group_id" :key="item.group_id"
:label="item.name" :label="item.name"
:value="item.api_id" :value="item.group_id"
> >
</el-option> </el-option>
</el-select> </el-select>

@ -26,9 +26,13 @@ const allSelectCardQuan = ref([])
// //
const selectSaleType = ref('ticket') const selectSaleType = ref('ticket')
// loading
const equan_loading = ref(false)
// //
async function get_quan() { async function get_quan() {
console.log('get_quan') console.log('get_quan')
equan_loading.value = true
await get_ec_api_get_quan(props.cid, cardNum.value).then( await get_ec_api_get_quan(props.cid, cardNum.value).then(
res => { res => {
quanArray.value = res.quan quanArray.value = res.quan
@ -44,6 +48,7 @@ async function get_quan() {
console.log(err) console.log(err)
} }
) )
equan_loading.value = false
} }
// //
@ -83,6 +88,10 @@ function clear_card_quan() {
selectCardQuanArray.value = [] selectCardQuanArray.value = []
emits('getQuan', selectQuan.value, allSelectCardQuan.value, quan_type.value) emits('getQuan', selectQuan.value, allSelectCardQuan.value, quan_type.value)
} }
function refreshQuan() {
selectQuan.value = []
get_quan()
}
onBeforeMount(() => { onBeforeMount(() => {
get_quan() get_quan()
@ -148,10 +157,11 @@ function test() {
:max-collapse-tags="2" :max-collapse-tags="2"
style="width: 460px" style="width: 460px"
/> />
<el-button @click="refreshQuan">刷新</el-button>
</el-row> </el-row>
<el-row v-if="quan_type==='equan'" style="margin: 20px 0 30px 100px"> <el-row v-if="quan_type==='equan'" style="margin: 20px 0 30px 100px">
<el-input style="width: 240px; margin-right: 20px" v-model="cardNum"></el-input> <el-input style="width: 240px; margin-right: 20px" v-model="cardNum"></el-input>
<el-button style="margin-right: 20px" @click="get_card_quan">查找</el-button> <el-button style="margin-right: 20px" @click="get_card_quan" :loading="equan_loading">查找</el-button>
<el-select v-model="selectCardQuan" placeholder="选择卡内赠券" <el-select v-model="selectCardQuan" placeholder="选择卡内赠券"
clearable="clearable" style="margin-right: 20px"> clearable="clearable" style="margin-right: 20px">
<el-option v-for="item in cardQuanArray" :key="item['card_quan_order_id']" :label="item['label']" <el-option v-for="item in cardQuanArray" :key="item['card_quan_order_id']" :label="item['label']"

@ -1,5 +1,15 @@
<script setup> <script setup>
import {ref, reactive, onBeforeMount, onMounted, onUnmounted, watch, computed} from "vue"; import {
ref,
reactive,
onBeforeMount,
onMounted,
onBeforeUpdate,
onBeforeUnmount,
onUnmounted,
watch,
computed
} from "vue";
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";
@ -30,7 +40,7 @@ const activeTab = ref(store.state.ecApiModule.first_tab_api_id); // 当前选项
// //
const ApiTableRef = ref(null) // Ref let ApiTableRef = ref(null) // Ref
// const multipleSelection = ref([]) // checkbox // const multipleSelection = ref([]) // checkbox
// //
@ -318,6 +328,7 @@ function check_params(checked, unchecked) {
param.is_checked = false param.is_checked = false
} }
}) })
get_suggest()
} }
// //
@ -412,7 +423,10 @@ function get_pay_type(pay_type) {
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)
console.log('UserApiData.value', UserApiData.value) console.log('UserApiData.value', UserApiData.value)
// console.log('activeTab.value', activeTab.value) console.log('activeTab.value', activeTab.value)
console.log('ApiTableRef.value', ApiTableRef.value)
// store.state.ecApiModule.ec_api_data.api = []
store.state.ecApiModule.show_tab_area = false
} }
// //
@ -521,7 +535,6 @@ const levelList = computed(() => {
// 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()
// //
@ -572,6 +585,7 @@ onMounted(() => {
ghostClass: 'dragging', ghostClass: 'dragging',
draggable: '.el-tabs__item', draggable: '.el-tabs__item',
onEnd: (evt) => { onEnd: (evt) => {
console.log('sortTabs-onEnd')
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})
}, },
}); });
@ -608,12 +622,15 @@ const ace_options = {
<CheckQuan v-if="api['path'] === 'seat/check-coupon'" @getQuan="get_quan_detail" @getSaleType="get_sale_type" <CheckQuan v-if="api['path'] === 'seat/check-coupon'" @getQuan="get_quan_detail" @getSaleType="get_sale_type"
:cid="UserApiData['base_info']['cinema']"></CheckQuan> :cid="UserApiData['base_info']['cinema']"></CheckQuan>
<ApiLockBuySelector v-if="api['path'] === 'seat/lock-buy'" @getSaleType="get_sale_type" <ApiLockBuySelector v-if="api['path'] === 'seat/lock-buy'" @getSaleType="get_sale_type"
@getPayType="get_pay_type"></ApiLockBuySelector> @getPayType="get_pay_type" type="ticket"></ApiLockBuySelector>
<ApiLockBuySelector v-if="api['path'] === 'order/buy-goods'" @getSaleType="get_sale_type"
@getPayType="get_pay_type" type="goods"></ApiLockBuySelector>
<el-table <el-table
ref='ApiTableRef' ref='ApiTableRef'
:data="UserApiData.api[api['id']].params" :data="UserApiData.api[api['id']].params"
@selection-change="handleParamsChange" @selection-change="handleParamsChange"
@select="handleParamsSelect" @select="handleParamsSelect"
:key="api['id']"
> >
<el-table-column type="selection" width="50" :selectable="checkboxFilter"/> <el-table-column type="selection" width="50" :selectable="checkboxFilter"/>
<el-table-column label="字段名" width="200"> <el-table-column label="字段名" width="200">
@ -665,13 +682,17 @@ const ace_options = {
</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"/>
<MovieShow v-if="showList.length > 0" :show="showList" :data="UserApiData.api[activeTab]" :base_info="UserApiData.base_info"/> <MovieShow v-if="showList.length > 0" :show="showList" :data="UserApiData.api[activeTab]"
<SeatStatus v-if="seatList.length > 0" :seat="seatList" :data="UserApiData.api[activeTab]" :base_info="UserApiData.base_info"/> :base_info="UserApiData.base_info"/>
<CinemaGoods v-if="goodsList.length > 0" :goods="goodsList" :data="UserApiData.api[activeTab]" :base_info="UserApiData.base_info"/> <SeatStatus v-if="seatList.length > 0" :seat="seatList" :data="UserApiData.api[activeTab]"
<EcardLevel v-if="levelList.length > 0" :level="levelList" :data="UserApiData.api[activeTab]" :base_info="UserApiData.base_info"/> :base_info="UserApiData.base_info"/>
<CinemaGoods v-if="goodsList.length > 0" :goods="goodsList" :data="UserApiData.api[activeTab]"
:base_info="UserApiData.base_info"/>
<EcardLevel v-if="levelList.length > 0" :level="levelList" :data="UserApiData.api[activeTab]"
:base_info="UserApiData.base_info"/>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
<el-backtop :right="100" :bottom="100" :visibility-height="200"/> <el-backtop :right="300" :bottom="100" :visibility-height="100"/>
</template> </template>
<style scoped> <style scoped>

@ -40,7 +40,9 @@ const ecApiModule = {
state: { state: {
ec_api_data: {api:[]}, // 所有api数据 ec_api_data: {api:[]}, // 所有api数据
// ec_select_api: [], // 默认选中的api // ec_select_api: [], // 默认选中的api
first_tab_api_id: 1 first_tab_api_id: 1,
show_tab_area: true, //是否显示表格区域
group_api_id: 0
}, },
getters: { getters: {
ec_api_data_getter: state => { ec_api_data_getter: state => {
@ -53,6 +55,9 @@ const ecApiModule = {
}) })
return select_api_id return select_api_id
}, },
show_tab_area_getter: state => {
return state.ec_api_data.api.length > 0 && state.show_tab_area
}
}, },
mutations: { mutations: {
change_ec_select_api: (state, payload) => { change_ec_select_api: (state, payload) => {
@ -75,7 +80,7 @@ const ecApiModule = {
state.ec_api_data.api.splice(payload.newIndex-1, 0, movedTab); state.ec_api_data.api.splice(payload.newIndex-1, 0, movedTab);
}, },
add_ec_api_data: (state, payload) => { add_ec_api_data: (state, payload) => {
// console.log('payload', payload) state.ec_api_data = {api:[]}
state.ec_api_data = payload state.ec_api_data = payload
} }

@ -8,7 +8,7 @@ const store = useStore();
<template> <template>
<BasicConfig></BasicConfig> <BasicConfig></BasicConfig>
<TabArea v-if="store.state.ecApiModule.ec_api_data.api.length > 0"></TabArea> <TabArea v-if="store.getters['ecApiModule/show_tab_area_getter']" :key="store.state.ecApiModule.group_api_id"></TabArea>
</template> </template>
<style scoped> <style scoped>

Loading…
Cancel
Save