fix:优化获取联系人方法
This commit is contained in:
@@ -4,7 +4,8 @@
|
|||||||
<channel-list
|
<channel-list
|
||||||
ref="channelListRef"
|
ref="channelListRef"
|
||||||
:activeChannel="activeChannel"
|
:activeChannel="activeChannel"
|
||||||
@selectChannel="selectChannel">
|
@selectChannel="selectChannel"
|
||||||
|
@data-ready="handleChannelDataReady">
|
||||||
</channel-list>
|
</channel-list>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -16,7 +17,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted, nextTick } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import ChannelList from './channel/ChannleList.vue'
|
import ChannelList from './channel/ChannleList.vue'
|
||||||
import ChannelSetting from '@/views/Publish/accurate/channel/ChannelSetting.vue'
|
import ChannelSetting from '@/views/Publish/accurate/channel/ChannelSetting.vue'
|
||||||
@@ -24,39 +25,62 @@ import { getPublishDetail } from '@/api/accurate'
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const channel = ref({})
|
const channel = ref({})
|
||||||
let activeChannel = ref('')
|
const activeChannel = ref('')
|
||||||
const channelListRef = ref(null) // 添加对 ChannelList 组件的引用
|
const channelListRef = ref(null)
|
||||||
|
const channelDataReady = ref(false) // 添加标记来追踪数据是否准备好
|
||||||
|
|
||||||
// 获取详情数据
|
// 获取详情数据
|
||||||
const getDetail = async (surveyPublishId) => {
|
const getDetail = async (surveyPublishId) => {
|
||||||
try {
|
try {
|
||||||
const res = await getPublishDetail({ surveyPublishId })
|
const res = await getPublishDetail({ surveyPublishId })
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
// 先获取基础数据
|
|
||||||
const baseData = res.data
|
const baseData = res.data
|
||||||
activeChannel.value = baseData.appCategory
|
activeChannel.value = baseData.launchChannelId
|
||||||
|
|
||||||
// 从 ChannelList 组件获取补充数据
|
// 等待 ChannelList 组件数据准备就绪
|
||||||
|
await waitForChannelData()
|
||||||
|
|
||||||
|
// 获取补充数据
|
||||||
const supplementData = channelListRef.value?.getChannelSupplementData(baseData.appCategory)
|
const supplementData = channelListRef.value?.getChannelSupplementData(baseData.appCategory)
|
||||||
console.log('supplementData');
|
|
||||||
console.log(supplementData);
|
// 合并数据
|
||||||
// 合并数据,优先使用基础数据,缺失字段使用补充数据
|
|
||||||
channel.value = {
|
channel.value = {
|
||||||
...baseData,
|
...baseData,
|
||||||
contactPerson: baseData.contactPerson || supplementData?.contactPerson,
|
contactPerson: baseData.contactPerson || supplementData?.contactPerson,
|
||||||
contactPersonPhone: baseData.contactPersonPhone || supplementData?.contactPersonPhone
|
contactPersonPhone: baseData.contactPersonPhone || supplementData?.contactPersonPhone
|
||||||
}
|
}
|
||||||
console.log(channel.value.contactPerson);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取详情失败:', error)
|
console.error('获取详情失败:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
// 等待 ChannelList 数据准备就绪
|
||||||
|
const waitForChannelData = async () => {
|
||||||
|
if (!channelDataReady.value) {
|
||||||
|
await new Promise(resolve => {
|
||||||
|
const checkReady = () => {
|
||||||
|
if (channelDataReady.value) {
|
||||||
|
resolve()
|
||||||
|
} else {
|
||||||
|
setTimeout(checkReady, 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkReady()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await nextTick()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听 ChannelList 数据准备就绪
|
||||||
|
const handleChannelDataReady = () => {
|
||||||
|
channelDataReady.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
const {surveyPublishId } = route.query
|
const {surveyPublishId } = route.query
|
||||||
if (surveyPublishId) {
|
if (surveyPublishId) {
|
||||||
getDetail(surveyPublishId)
|
await getDetail(surveyPublishId)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['selectChannel']);
|
const emit = defineEmits(['selectChannel', 'data-ready']);
|
||||||
const active = ref('');
|
const active = ref('');
|
||||||
// const channelList = ref([]);
|
// const channelList = ref([]);
|
||||||
const channelList = ref([])
|
const channelList = ref([])
|
||||||
@@ -59,6 +59,7 @@ const getChannelList = async () => {
|
|||||||
appType:'APPLICATION'
|
appType:'APPLICATION'
|
||||||
});
|
});
|
||||||
channelList.value = res.data
|
channelList.value = res.data
|
||||||
|
emit('data-ready') // 数据准备就绪后发出通知
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取渠道列表失败:', error);
|
console.error('获取渠道列表失败:', error);
|
||||||
}
|
}
|
||||||
@@ -103,6 +104,7 @@ defineExpose({
|
|||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
border: 1px solid #d9d9d9;
|
border: 1px solid #d9d9d9;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
margin-bottom: 5px;
|
||||||
&.disabled {
|
&.disabled {
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
@@ -132,4 +134,20 @@ defineExpose({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 强制显示滚动条(WebKit 内核浏览器,如 Chrome/Safari) */
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 8px; /* 纵向滚动条宽度 */
|
||||||
|
height: 8px; /* 横向滚动条高度 */
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: #c1c1c1; /* 滚动条滑块颜色 */
|
||||||
|
border-radius: 4px; /* 滑块圆角 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 滚动条轨道 */
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: #f1f1f1; /* 轨道颜色 */
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user