fix: 修复文章链接域名读取(data是dict格式,用data['key'].value获取)

This commit is contained in:
stefanfeng
2026-04-01 18:03:31 +08:00
parent da4744f333
commit fe9110ca3c

View File

@@ -30,7 +30,9 @@
</el-table-column>
<el-table-column label="文章" min-width="180" show-overflow-tooltip>
<template #default="{ row }">
<el-link :href="getArticleUrl(row.article_id)" target="_blank" type="primary" style="font-size:13px">{{ row.article_title || row.article_id || '--' }}</el-link>
<el-link
:href="row.article_url || '#'"
target="_blank" type="primary" style="font-size:13px">{{ row.article_title || row.article_id || '--' }}</el-link>
</template>
</el-table-column>
<el-table-column label="类型" width="80" align="center">
@@ -83,14 +85,14 @@
</template>
<script setup>
import { ref, reactive, onMounted, onUnmounted } from 'vue'
import { ref, reactive, onMounted, onUnmounted, nextTick, computed } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { getInteractions, retryInteraction, exportInteractions, cancelInteraction , getSystemConfigs } from '@/api'
const records = ref([])
const total = ref(0)
const loading = ref(false)
const articleBaseDomain = ref('https://fat-open.99hui.com') // 默认测试环境
const articleBaseDomain = ref('') // 从系统配置动态读取
const page = ref(1)
const pageSize = ref(20)
const dateRange = ref(null)
@@ -106,30 +108,45 @@ function onDateChange(v) {
}
// 构造文章详情页 URLH5 分享页面)
// 用 computed 确保 articleBaseDomain 变化时响应式更新
const articleUrlBase = computed(() => articleBaseDomain.value)
function getArticleUrl(articleId) {
if (!articleId) return '#'
return `${articleBaseDomain.value}/huihui-h5/#/news/share?id=${articleId}&login=no`
if (!articleId || !articleUrlBase.value) return '#'
return `${articleUrlBase.value}/huihui-h5/#/news/share?id=${articleId}&login=no`
}
// 从系统配置获取业务接口域名,用于拼接文章链接
async function loadArticleDomain() {
try {
const res = await getSystemConfigs()
const cfgs = res.data || []
const bizUrl = cfgs.find(c => c.config_key === 'news_platform_base_url')?.config_value || ''
// data 是 {key: {value, type, desc}} 格式的字典
const cfgData = res.data || {}
const bizUrl = cfgData['news_platform_base_url']?.value || ''
if (bizUrl) {
// 从 https://99hui.com/api/huihuibusiness 提取 https://99hui.com
const parts = bizUrl.split('/')
if (parts.length >= 3) articleBaseDomain.value = parts[0] + '//' + parts[2]
if (parts.length >= 3) {
articleBaseDomain.value = parts[0] + '//' + parts[2]
}
} catch(e) {}
}
} catch(e) { console.error('loadArticleDomain error:', e) }
}
async function load() {
loading.value = true
try {
const res = await getInteractions({ page: page.value, page_size: pageSize.value, ...filters })
records.value = res.data?.items || []
const items = res.data?.items || []
// 直接拼接文章 URL避免响应式追踪问题
items.forEach(item => {
if (item.article_id && articleBaseDomain.value) {
item.article_url = `${articleBaseDomain.value}/huihui-h5/#/news/share?id=${item.article_id}&login=no`
} else {
item.article_url = ''
}
})
records.value = items
total.value = res.data?.total || 0
} finally { loading.value = false }
}
@@ -177,8 +194,8 @@ async function handleExport() {
const a = document.createElement('a'); a.href = url; a.download = 'interactions.xlsx'; a.click()
}
onMounted(() => {
loadArticleDomain()
onMounted(async () => {
await loadArticleDomain() // 先等域名加载完
load()
window.addEventListener('page-refresh', load)
})