Skip to content

Commit ad19b26

Browse files
committed
fix
1 parent 74b5802 commit ad19b26

File tree

2 files changed

+76
-35
lines changed

2 files changed

+76
-35
lines changed

web/src/components/charts/EChartsPie.vue

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div style="position:relative;width:100%;height:280px">
33
<div ref="el" style="position:absolute;inset:0;width:100%;height:100%;background:#fafafa;border:1px dashed #ddd;border-radius:8px"></div>
4-
<div v-if="noData" style="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;color:#9CA3AF;font-size:14px;pointer-events:none">暂无数据</div>
4+
<div v-if="noData && !loading" style="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;color:#9CA3AF;font-size:14px;pointer-events:none">暂无数据</div>
55
</div>
66
</template>
77

@@ -11,9 +11,11 @@ import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
1111
const props = defineProps({ data: { type: Array, default: () => [] }, colors: { type: Array, default: () => [] } })
1212
1313
const el = ref(null)
14+
const loading = ref(true)
1415
let chart = null
1516
let echartsMod = null
1617
let ro = null
18+
let initPromise = null
1719
1820
const noData = computed(()=> {
1921
const arr = (props.data||[]).map(d=> Number(d?.value||0))
@@ -53,44 +55,68 @@ const buildOption = ()=> {
5355
}
5456
}
5557
56-
onMounted(async () => {
57-
console.log('=== [EChartsPie] Mounted ===')
58-
console.log('[EChartsPie] props.data:', props.data)
59-
await nextTick()
60-
console.log('[EChartsPie] el.value:', el.value)
61-
if (!el.value) { console.warn('[EChartsPie] el.value is null'); return }
62-
const w = el.value?.clientWidth || 0, h = el.value?.clientHeight || 0
63-
console.log('[EChartsPie] mounted size:', w, h)
64-
try {
65-
const mod = await import('echarts')
66-
echartsMod = mod.default || mod
67-
console.log('[EChartsPie] ECharts loaded')
68-
} catch (err) {
69-
console.error('[EChartsPie] ECharts load error:', err)
70-
return
71-
}
72-
try {
73-
chart = echartsMod.init(el.value, null, { renderer: 'svg' })
74-
console.log('[EChartsPie] chart initialized')
75-
} catch (e) {
76-
console.error('[EChartsPie] chart init error:', e)
77-
return
78-
}
58+
async function initChart() {
59+
if (initPromise) return initPromise
60+
initPromise = (async () => {
61+
console.log('=== [EChartsPie] Initializing ===')
62+
await nextTick()
63+
if (!el.value) { console.warn('[EChartsPie] el.value is null'); return false }
64+
const w = el.value?.clientWidth || 0, h = el.value?.clientHeight || 0
65+
console.log('[EChartsPie] size:', w, h)
66+
if (w === 0 || h === 0) {
67+
console.warn('[EChartsPie] Container has zero size, retrying...')
68+
await new Promise(r => setTimeout(r, 100))
69+
await nextTick()
70+
}
71+
try {
72+
if (!echartsMod) {
73+
const mod = await import('echarts')
74+
echartsMod = mod.default || mod
75+
console.log('[EChartsPie] ECharts loaded')
76+
}
77+
} catch (err) {
78+
console.error('[EChartsPie] ECharts load error:', err)
79+
return false
80+
}
81+
try {
82+
if (!chart) {
83+
chart = echartsMod.init(el.value, null, { renderer: 'svg' })
84+
console.log('[EChartsPie] chart initialized')
85+
ro = new ResizeObserver(() => { try { chart && chart.resize() } catch {} })
86+
ro.observe(el.value)
87+
}
88+
} catch (e) {
89+
console.error('[EChartsPie] chart init error:', e)
90+
return false
91+
}
92+
return true
93+
})()
94+
return initPromise
95+
}
96+
97+
async function updateChart() {
98+
const ok = await initChart()
99+
if (!ok || !chart) return
79100
const option = buildOption()
80-
console.log('[EChartsPie] init series length:', option?.series?.[0]?.data?.length)
101+
console.log('[EChartsPie] update series length:', option?.series?.[0]?.data?.length)
81102
chart.setOption(option, true)
82103
chart.resize()
83104
setTimeout(() => { try { chart && chart.resize() } catch {} }, 120)
84-
ro = new ResizeObserver(() => { try { chart && chart.resize() } catch {} })
85-
ro.observe(el.value)
105+
}
106+
107+
onMounted(async () => {
108+
console.log('=== [EChartsPie] Mounted ===')
109+
console.log('[EChartsPie] props.data:', props.data)
110+
loading.value = true
111+
await updateChart()
112+
loading.value = false
86113
})
87114
88-
watch(()=> props.data, (val) => {
115+
watch(()=> props.data, async (val) => {
89116
console.log('[EChartsPie] data changed:', val)
90-
if (!chart) return
91-
const option = buildOption()
92-
chart.setOption(option, true)
93-
chart.resize()
117+
loading.value = true
118+
await updateChart()
119+
loading.value = false
94120
}, { deep: true })
95121
96122
onUnmounted(()=> { try { ro && ro.disconnect() } catch {} ro = null; try { chart && chart.dispose() } catch {} chart = null })

web/src/pages/HomePage.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,12 @@ export default {
412412
return { ...it, id, code, shortUrl, longUrl, createdAt }
413413
})
414414
} catch (err) {
415-
alert('获取历史记录失败,请稍后重试')
415+
const status = err?.response?.status
416+
if (status === 401 || status === 403) {
417+
alert('未登录用户无法查看历史记录,请先登录')
418+
} else {
419+
alert('获取历史记录失败,请稍后重试')
420+
}
416421
console.error('History refresh error:', err)
417422
} finally {
418423
this.refreshing = false
@@ -454,7 +459,12 @@ export default {
454459
this.history = (this.history || []).map(x => x.id === id ? updated : x)
455460
this.cancelEdit()
456461
} catch (err) {
457-
alert('更新失败,请稍后重试')
462+
const status = err?.response?.status
463+
if (status === 401 || status === 403) {
464+
alert('未登录用户无法编辑短链,请先登录')
465+
} else {
466+
alert('更新失败,请稍后重试')
467+
}
458468
console.error('Update short url error:', err)
459469
} finally {
460470
this.updatingIds.delete(id)
@@ -471,7 +481,12 @@ export default {
471481
this.history = (this.history || []).filter(x => this.extractCode(x) !== code)
472482
}
473483
} catch (err) {
474-
alert('删除失败,请稍后重试')
484+
const status = err?.response?.status
485+
if (status === 401 || status === 403) {
486+
alert('未登录用户无法删除短链,请先登录')
487+
} else {
488+
alert('删除失败,请稍后重试')
489+
}
475490
console.error('History delete error:', err)
476491
} finally {
477492
if (id) this.deletingIds.delete(id)

0 commit comments

Comments
 (0)