feat(admin): 改善工作台和账户消耗的等待、异常与移动体验
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<div class="wb-section-body wb-feedback">
|
||||
<p role="status" aria-atomic="true">{{ state === 'error' ? label + '读取失败。' : '正在读取' + label + '…' }}</p>
|
||||
<div v-if="state === 'loading'" class="wb-placeholders" aria-hidden="true"><i/><i/><i/></div>
|
||||
<el-button v-else plain size="small" :aria-label="'重试' + label" @click="$emit('retry')">重新加载</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{ state: 'loading' | 'error'; label: string }>()
|
||||
defineEmits<{ (event: 'retry'): void }>()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.wb-feedback { min-height: 116px; padding: 18px 22px; }
|
||||
.wb-feedback p { margin: 0 0 10px; font-size: 14px; color: var(--zyt-text, var(--el-text-color-regular)); }
|
||||
.wb-placeholders { display: grid; grid-template-columns: 2fr 2fr 3fr; gap: 12px; }
|
||||
.wb-placeholders i { display: block; height: 52px; border-radius: 8px; background: var(--el-fill-color-light); animation: wb-breathe 1.6s ease-in-out infinite alternate; }
|
||||
@keyframes wb-breathe { to { opacity: .55; } }
|
||||
@media (prefers-reduced-motion: reduce) { .wb-placeholders i { animation: none; } }
|
||||
</style>
|
||||
+115
-123
@@ -3,14 +3,14 @@
|
||||
<header class="wb-hero">
|
||||
<div class="wb-hero-text">
|
||||
<h1 class="wb-hero-title">数据工作台</h1>
|
||||
<p class="wb-hero-desc">{{ isLiveReadonly ? '查看订单与诊单统计,仅展示接口返回的实际数据。' : '医助诊单、订单营收与运营趋势一屏掌握' }}</p>
|
||||
<p class="wb-hero-desc">{{ isLiveReadonly ? '查看订单与诊单统计,仅展示接口返回的实际数据。' : '查看订单营收与医助诊单统计。' }}</p>
|
||||
</div>
|
||||
<el-button type="primary" :icon="Refresh" round class="wb-refresh-btn" @click="refreshAll">
|
||||
刷新全部
|
||||
</el-button>
|
||||
</header>
|
||||
<!-- 订单统计 -->
|
||||
<section class="wb-section wb-section--order">
|
||||
<section class="wb-section wb-section--order" :data-state="orderReadState">
|
||||
<div class="wb-section-head">
|
||||
<div class="wb-section-title">
|
||||
<span class="wb-section-icon wb-section-icon--violet">
|
||||
@@ -18,7 +18,7 @@
|
||||
</span>
|
||||
<div>
|
||||
<div class="wb-section-name">订单统计</div>
|
||||
<div v-if="!isLiveReadonly || orderReadState === 'ready'" class="wb-section-sub">{{ orderStatsDateRangeText }} · {{ orderStatsData.order_type_name || '—' }}</div>
|
||||
<div v-if="orderReadState === 'ready'" class="wb-section-sub">{{ orderStatsDateRangeText }} · {{ orderStatsData.order_type_name || '—' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wb-toolbar">
|
||||
@@ -42,21 +42,19 @@
|
||||
<el-button aria-label="刷新订单统计" :icon="Refresh" circle @click="loadOrderStats" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="isLiveReadonly && orderReadState !== 'ready'" class="wb-section-body" role="status">
|
||||
{{ orderReadState === 'error' ? '订单统计读取失败,请重新刷新。' : '正在读取订单统计…' }}
|
||||
</div>
|
||||
<SectionFeedback v-if="orderReadState !== 'ready'" :state="orderReadState" label="订单统计" @retry="loadOrderStats" />
|
||||
<div v-else class="wb-section-body">
|
||||
<el-row :gutter="16" class="wb-kpi-row">
|
||||
<el-col :xs="24" :sm="8">
|
||||
<div class="wb-kpi wb-kpi--violet">
|
||||
<div class="wb-kpi-label">今日单数</div>
|
||||
<div class="wb-kpi-value">{{ orderStatsData.today_total ?? 0 }}</div>
|
||||
<div class="wb-kpi-value">{{ displayMetric(orderStatsData.today_total) }}</div>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="8">
|
||||
<div class="wb-kpi wb-kpi--amber">
|
||||
<div class="wb-kpi-label">今日金额</div>
|
||||
<div class="wb-kpi-value wb-kpi-value--sm">¥{{ orderStatsData.today_amount ?? '0.00' }}</div>
|
||||
<div class="wb-kpi-value wb-kpi-value--sm">{{ displayMetric(orderStatsData.today_amount, '¥') }}</div>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="8">
|
||||
@@ -103,7 +101,7 @@
|
||||
<span class="wb-chart-hint">{{ isLiveReadonly ? '按开单人排名' : '柱状 + 趋势' }}</span>
|
||||
</div>
|
||||
<v-charts
|
||||
v-if="orderStatsData.chart?.xAxis?.length"
|
||||
v-if="hasBars(orderStatsData.chart)"
|
||||
:key="'order-bar-' + orderStatsType"
|
||||
class="wb-chart"
|
||||
style="height: 300px"
|
||||
@@ -191,7 +189,7 @@
|
||||
</div>
|
||||
</section>
|
||||
<!-- 医助理诊单 -->
|
||||
<section class="wb-section wb-section--diagnosis">
|
||||
<section class="wb-section wb-section--diagnosis" :data-state="diagnosisReadState">
|
||||
<div class="wb-section-head">
|
||||
<div class="wb-section-title">
|
||||
<span class="wb-section-icon wb-section-icon--blue">
|
||||
@@ -199,8 +197,8 @@
|
||||
</span>
|
||||
<div>
|
||||
<div class="wb-section-name">医助理诊单统计</div>
|
||||
<div v-if="!isLiveReadonly || diagnosisReadState === 'ready'" class="wb-section-sub">
|
||||
{{ assistantStats.date_range?.[0] }} 至 {{ assistantStats.date_range?.[1] }}
|
||||
<div v-if="diagnosisReadState === 'ready'" class="wb-section-sub">
|
||||
{{ assistantStats.date_range?.length === 2 ? assistantStats.date_range.join(' 至 ') : '—' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -214,15 +212,13 @@
|
||||
<el-button aria-label="刷新诊单统计" :icon="Refresh" circle @click="loadAssistantStats" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="isLiveReadonly && diagnosisReadState !== 'ready'" class="wb-section-body" role="status">
|
||||
{{ diagnosisReadState === 'error' ? '诊单统计读取失败,请重新刷新。' : '正在读取诊单统计…' }}
|
||||
</div>
|
||||
<SectionFeedback v-if="diagnosisReadState !== 'ready'" :state="diagnosisReadState" label="诊单统计" @retry="loadAssistantStats" />
|
||||
<div v-else class="wb-section-body">
|
||||
<el-row :gutter="16" class="wb-kpi-row">
|
||||
<el-col :xs="24" :sm="8" :lg="6">
|
||||
<div class="wb-kpi wb-kpi--blue">
|
||||
<div class="wb-kpi-label">今日创建诊单</div>
|
||||
<div class="wb-kpi-value">{{ assistantStats.today_total ?? 0 }}</div>
|
||||
<div class="wb-kpi-value">{{ displayMetric(assistantStats.today_total) }}</div>
|
||||
<div class="wb-kpi-hint">当日新增总量</div>
|
||||
</div>
|
||||
</el-col>
|
||||
@@ -253,7 +249,7 @@
|
||||
<span class="wb-chart-hint">{{ isLiveReadonly ? '按医助排名' : '柱状 + 趋势线' }}</span>
|
||||
</div>
|
||||
<v-charts
|
||||
v-if="assistantStats.chart.xAxis?.length"
|
||||
v-if="hasBars(assistantStats.chart)"
|
||||
ref="assistantChart"
|
||||
class="wb-chart"
|
||||
style="height: 340px"
|
||||
@@ -319,19 +315,23 @@
|
||||
|
||||
|
||||
<!-- 访问 & 销售趋势 -->
|
||||
<section v-if="!isLiveReadonly" class="wb-section wb-section--trend">
|
||||
<section v-if="!isLiveReadonly" class="wb-section wb-section--trend" :data-state="trendExpanded ? trendReadState : 'collapsed'">
|
||||
<div class="wb-section-head">
|
||||
<div class="wb-section-title">
|
||||
<span class="wb-section-icon wb-section-icon--teal">
|
||||
<el-icon><TrendCharts /></el-icon>
|
||||
</span>
|
||||
<div>
|
||||
<div class="wb-section-name">运营趋势</div>
|
||||
<div class="wb-section-sub">访问量与销售额走势</div>
|
||||
<div class="wb-section-name">运营趋势示例</div>
|
||||
<div class="wb-section-sub">当前接口返回示例趋势,不计入经营统计。</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-button v-if="!isLocalPreview" plain :aria-expanded="trendExpanded" @click="toggleTrend">
|
||||
{{ trendExpanded ? '收起示例趋势' : '查看示例趋势' }}
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="wb-section-body wb-trend-body">
|
||||
<SectionFeedback v-if="trendExpanded && trendReadState !== 'ready'" :state="trendReadState" label="运营趋势" @retry="getData" />
|
||||
<div v-else-if="trendExpanded" class="wb-section-body wb-trend-body">
|
||||
<el-row :gutter="20">
|
||||
<el-col :xs="24" :lg="14">
|
||||
<div class="wb-chart-card wb-trend-card">
|
||||
@@ -339,6 +339,7 @@
|
||||
<span class="wb-chart-title">访问量趋势</span>
|
||||
</div>
|
||||
<v-charts
|
||||
v-if="hasTrend(workbenchData.visitorOption)"
|
||||
ref="visitorChart"
|
||||
class="wb-chart"
|
||||
style="height: 320px"
|
||||
@@ -346,6 +347,7 @@
|
||||
:theme="chartTheme"
|
||||
:autoresize="true"
|
||||
/>
|
||||
<el-empty v-else class="wb-chart-empty" description="暂无访问量趋势数据" />
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :xs="24" :lg="10">
|
||||
@@ -355,6 +357,7 @@
|
||||
<span class="wb-chart-hint">单位(万)</span>
|
||||
</div>
|
||||
<v-charts
|
||||
v-if="hasTrend(workbenchData.saleOption)"
|
||||
ref="saleChart"
|
||||
class="wb-chart"
|
||||
style="height: 320px"
|
||||
@@ -362,6 +365,7 @@
|
||||
:theme="chartTheme"
|
||||
:autoresize="true"
|
||||
/>
|
||||
<el-empty v-else class="wb-chart-empty" description="暂无销售额趋势数据" />
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -371,7 +375,8 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="workbench">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import SectionFeedback from './SectionFeedback.vue'
|
||||
import { useMutationObserver } from '@vueuse/core'
|
||||
import vCharts from 'vue-echarts'
|
||||
import { DataAnalysis, Histogram, Refresh, TrendCharts } from '@element-plus/icons-vue'
|
||||
@@ -384,11 +389,51 @@ import { useComponentRef } from '@/utils/getExposeType'
|
||||
import { calcColor } from '@/utils/util'
|
||||
|
||||
const isLiveReadonly = import.meta.env.MODE === 'live-readonly'
|
||||
const isLocalPreview = import.meta.env.MODE === 'local-preview'
|
||||
// Only the isolated demo opens the example by default. Ordinary business reads are independent.
|
||||
const trendExpanded = ref(isLocalPreview)
|
||||
function toggleTrend() {
|
||||
trendExpanded.value = !trendExpanded.value
|
||||
if (trendExpanded.value) getData()
|
||||
}
|
||||
type ReadState = 'loading' | 'ready' | 'error'
|
||||
const orderReadState = ref<ReadState>('loading')
|
||||
const diagnosisReadState = ref<ReadState>('loading')
|
||||
let orderRequest = 0
|
||||
let diagnosisRequest = 0
|
||||
// Only the latest read for this section owns its result, including rejection.
|
||||
function useSectionRead() {
|
||||
const state = ref<ReadState>('loading')
|
||||
let generation = 0
|
||||
onUnmounted(() => { generation++ })
|
||||
async function run(fetch: () => Promise<any>, apply: (res: any) => void) {
|
||||
const owner = ++generation
|
||||
state.value = 'loading'
|
||||
try {
|
||||
const res = await fetch()
|
||||
if (owner !== generation) return
|
||||
if (!res || typeof res !== 'object' || Array.isArray(res)) throw new Error('无统计结果')
|
||||
apply(res)
|
||||
state.value = 'ready'
|
||||
} catch {
|
||||
if (owner === generation) state.value = 'error'
|
||||
}
|
||||
}
|
||||
return { state, run }
|
||||
}
|
||||
const { state: orderReadState, run: readOrders } = useSectionRead()
|
||||
const { state: diagnosisReadState, run: readDiagnosis } = useSectionRead()
|
||||
const { state: trendReadState, run: readTrends } = useSectionRead()
|
||||
|
||||
function hasMetric(value: unknown) {
|
||||
return (typeof value === 'number' && Number.isFinite(value)) ||
|
||||
(typeof value === 'string' && value.trim() !== '')
|
||||
}
|
||||
function displayMetric(value: unknown, prefix = '') {
|
||||
return hasMetric(value) ? prefix + value : '—'
|
||||
}
|
||||
function hasBars(chart: any) {
|
||||
return chart?.xAxis?.length && chart.series?.some((s: any) => s?.data?.some(hasMetric))
|
||||
}
|
||||
function hasTrend(option: any) {
|
||||
return option.xAxis.data.length && option.series[0].data.some((v: any) => hasMetric(v?.value ?? v))
|
||||
}
|
||||
const settingStore = useSettingStore()
|
||||
const saleChart = useComponentRef(vCharts)
|
||||
const visitorChart = useComponentRef(vCharts)
|
||||
@@ -540,33 +585,26 @@ const assistantChartOption = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
const loadAssistantStats = () => {
|
||||
const request = ++diagnosisRequest
|
||||
if (isLiveReadonly) diagnosisReadState.value = 'loading'
|
||||
assistantDiagnosisStats({ days: assistantStats.days })
|
||||
.then((res: any) => {
|
||||
if (isLiveReadonly) {
|
||||
if (request !== diagnosisRequest) return
|
||||
if (res?.today_total == null) throw new Error('缺少诊单统计')
|
||||
diagnosisReadState.value = 'ready'
|
||||
}
|
||||
assistantStats.date_range = res.date_range
|
||||
assistantStats.today_total = res.today_total ?? 0
|
||||
assistantStats.today_ranking = res.today_ranking || []
|
||||
assistantStats.departments = res.departments || []
|
||||
assistantStats.ranking = res.ranking || []
|
||||
assistantStats.chart = res.chart || { xAxis: [], series: [] }
|
||||
})
|
||||
.catch(() => { if (isLiveReadonly && request === diagnosisRequest) diagnosisReadState.value = 'error' })
|
||||
}
|
||||
const loadAssistantStats = () => readDiagnosis(
|
||||
() => assistantDiagnosisStats({ days: assistantStats.days }),
|
||||
res => {
|
||||
if (isLiveReadonly && !hasMetric(res.today_total)) throw new Error('缺少诊单统计')
|
||||
assistantStats.date_range = res.date_range
|
||||
assistantStats.today_total = res.today_total
|
||||
assistantStats.today_ranking = res.today_ranking || []
|
||||
assistantStats.departments = res.departments || []
|
||||
assistantStats.ranking = res.ranking || []
|
||||
assistantStats.chart = res.chart || { xAxis: [], series: [] }
|
||||
}
|
||||
)
|
||||
|
||||
const orderStatsType = ref(-1)
|
||||
const orderStatsDays = ref(0)
|
||||
const orderStatsData = reactive<any>({
|
||||
order_type_name: '',
|
||||
date_range: [] as string[],
|
||||
today_total: 0,
|
||||
today_amount: '0.00',
|
||||
today_total: null,
|
||||
today_amount: null,
|
||||
today_ranking: [],
|
||||
departments: [],
|
||||
ranking: [],
|
||||
@@ -605,7 +643,7 @@ const orderDeptCountPieOption = computed(() => {
|
||||
const orderDeptAmountPieOption = computed(() => {
|
||||
const data = (orderStatsData.departments || [])
|
||||
.map((d: any) => ({ name: d.dept_name || '—', value: parseAmount(d.amount) }))
|
||||
.filter((d) => d.value > 0)
|
||||
.filter((d: { value: number }) => d.value > 0)
|
||||
return {
|
||||
color: skin.value ? artSeriesColors.value : pieColors,
|
||||
tooltip: {
|
||||
@@ -705,29 +743,24 @@ const orderChartOption = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
const loadOrderStats = () => {
|
||||
const request = ++orderRequest
|
||||
if (isLiveReadonly) orderReadState.value = 'loading'
|
||||
orderStats({ order_type: orderStatsType.value, days: orderStatsDays.value })
|
||||
.then((res: any) => {
|
||||
if (isLiveReadonly) {
|
||||
if (request !== orderRequest) return
|
||||
if (res?.today_total == null || res?.today_amount == null) throw new Error('缺少订单统计')
|
||||
orderReadState.value = 'ready'
|
||||
}
|
||||
Object.assign(orderStatsData, {
|
||||
order_type_name: res.order_type_name ?? '',
|
||||
date_range: res.date_range || [],
|
||||
today_total: res.today_total ?? 0,
|
||||
today_amount: res.today_amount ?? '0.00',
|
||||
today_ranking: res.today_ranking || [],
|
||||
departments: res.departments || [],
|
||||
ranking: res.ranking || [],
|
||||
chart: res.chart || { xAxis: [], series: [] }
|
||||
})
|
||||
const loadOrderStats = () => readOrders(
|
||||
() => orderStats({ order_type: orderStatsType.value, days: orderStatsDays.value }),
|
||||
res => {
|
||||
if (isLiveReadonly && (!hasMetric(res.today_total) || !hasMetric(res.today_amount))) {
|
||||
throw new Error('缺少订单统计')
|
||||
}
|
||||
Object.assign(orderStatsData, {
|
||||
order_type_name: res.order_type_name ?? '',
|
||||
date_range: res.date_range || [],
|
||||
today_total: res.today_total,
|
||||
today_amount: res.today_amount,
|
||||
today_ranking: res.today_ranking || [],
|
||||
departments: res.departments || [],
|
||||
ranking: res.ranking || [],
|
||||
chart: res.chart || { xAxis: [], series: [] }
|
||||
})
|
||||
.catch(() => { if (isLiveReadonly && request === orderRequest) orderReadState.value = 'error' })
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const refreshAll = () => {
|
||||
getData()
|
||||
@@ -762,17 +795,6 @@ const lowSalesColor = computed(() => skin.value ? artSeriesColors.value[4] : {
|
||||
})
|
||||
|
||||
const workbenchData: any = reactive({
|
||||
version: {
|
||||
version: '',
|
||||
website: '',
|
||||
based: '',
|
||||
channel: { gitee: '', website: '' }
|
||||
},
|
||||
support: [],
|
||||
today: {},
|
||||
menu: [],
|
||||
visitor: [],
|
||||
article: [],
|
||||
visitorOption: {
|
||||
xAxis: { type: 'category', data: [] },
|
||||
yAxis: { type: 'value' },
|
||||
@@ -832,43 +854,16 @@ const workbenchData: any = reactive({
|
||||
|
||||
const getData = () => {
|
||||
// WorkbenchLogic::visitor() and sale() generate random series, not operational figures.
|
||||
if (isLiveReadonly) return
|
||||
getWorkbench()
|
||||
.then((res: any) => {
|
||||
workbenchData.version = res.version
|
||||
workbenchData.today = res.today
|
||||
workbenchData.menu = res.menu
|
||||
workbenchData.visitor = res.visitor
|
||||
workbenchData.support = res.support
|
||||
|
||||
workbenchData.visitorOption.xAxis.data = []
|
||||
workbenchData.visitorOption.series[0].data = []
|
||||
workbenchData.saleOption.xAxis.data = []
|
||||
workbenchData.saleOption.series[0].data = []
|
||||
|
||||
res.visitor?.date?.reverse().forEach((item: any) => {
|
||||
workbenchData.visitorOption.xAxis.data.push(item)
|
||||
})
|
||||
res.visitor?.list?.[0]?.data?.forEach((item: any) => {
|
||||
workbenchData.visitorOption.series[0].data.push(item)
|
||||
})
|
||||
res.sale?.date?.reverse().forEach((item: any) => {
|
||||
workbenchData.saleOption.xAxis.data.push(item)
|
||||
})
|
||||
res.sale?.list?.[0]?.data?.forEach((item: any) => {
|
||||
let v: any = item
|
||||
if (item <= 50) {
|
||||
v = {
|
||||
value: item,
|
||||
itemStyle: { color: lowSalesColor }
|
||||
}
|
||||
}
|
||||
workbenchData.saleOption.series[0].data.push(v)
|
||||
})
|
||||
})
|
||||
.catch((err: any) => {
|
||||
console.log('err', err)
|
||||
})
|
||||
if (isLiveReadonly || !trendExpanded.value) return
|
||||
return readTrends(getWorkbench, res => {
|
||||
// Preserve the API's existing date/value ordering without mutating the response.
|
||||
workbenchData.visitorOption.xAxis.data = [...(res.visitor?.date || [])].reverse()
|
||||
workbenchData.visitorOption.series[0].data = res.visitor?.list?.[0]?.data || []
|
||||
workbenchData.saleOption.xAxis.data = [...(res.sale?.date || [])].reverse()
|
||||
workbenchData.saleOption.series[0].data = (res.sale?.list?.[0]?.data || []).map((item: any) =>
|
||||
!hasMetric(item) ? null : item <= 50 ? { value: item, itemStyle: { color: lowSalesColor.value } } : item
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const updateColor = () => {
|
||||
@@ -885,11 +880,7 @@ const updateColor = () => {
|
||||
visitorChart.value?.setOption(workbenchData.visitorOption)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getData()
|
||||
loadAssistantStats()
|
||||
loadOrderStats()
|
||||
})
|
||||
onMounted(refreshAll)
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@@ -1349,6 +1340,7 @@ html[data-admin-ui="v2"] .workbench-page {
|
||||
background: none;
|
||||
border: 0;
|
||||
}
|
||||
.wb-section--trend[data-state="collapsed"] .wb-section-head { padding-bottom: 16px; }
|
||||
.wb-section-title { gap: 10px; }
|
||||
.wb-section-icon {
|
||||
width: 40px; height: 40px; border-radius: 8px; font-size: 20px;
|
||||
|
||||
Reference in New Issue
Block a user