feat(admin): 改善工作台和账户消耗的等待、异常与移动体验
This commit is contained in:
@@ -78,9 +78,11 @@ export function createRouteRecord(route: any, firstRoute: boolean): RouteRecordR
|
||||
export function loadRouteView(component: string) {
|
||||
try {
|
||||
const normalizedComponent = normalizeMenuPath(component)
|
||||
const key = Object.keys(modules).find((key) => {
|
||||
return key.includes(`/${normalizedComponent}.vue`)
|
||||
})
|
||||
// Menus store paths relative to views/. A suffix alone can open a different
|
||||
// authorized page, e.g. assistant_service/workbench/index instead of workbench/index.
|
||||
const exact = `/src/views/${normalizedComponent}.vue`
|
||||
if (Object.hasOwn(modules, exact)) return modules[exact]
|
||||
const key = Object.keys(modules).find(key => key.endsWith(`/${normalizedComponent}.vue`))
|
||||
if (key) {
|
||||
return modules[key]
|
||||
}
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
<template>
|
||||
<div class="personal-account-cost-page">
|
||||
<el-card class="!border-none mb-4" shadow="never">
|
||||
<div class="flex flex-wrap">
|
||||
<div class="w-1/2 md:w-1/3">
|
||||
<div class="leading-10">当前筛选天数</div>
|
||||
<div class="text-4xl">{{ pager.extend.days_count ?? 0 }}</div>
|
||||
<el-card shadow="never" class="cost-filter-card">
|
||||
<el-form :model="queryParams" label-position="top" class="stats-filter-form" @submit.prevent="handleQuery">
|
||||
<div class="cost-time-filter">
|
||||
<list-time-filter
|
||||
v-model:time-type="time_type"
|
||||
v-model:date-range="dateRange"
|
||||
variant="inline"
|
||||
@time-type-change="onTimeTypeChange"
|
||||
@custom-change="handleQuery"
|
||||
/>
|
||||
</div>
|
||||
<div class="w-1/2 md:w-1/3">
|
||||
<div class="leading-10">累计账户消耗 (元)</div>
|
||||
<div class="text-4xl">¥{{ pager.extend.total_amount ?? '0.00' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card class="!border-none" shadow="never">
|
||||
<el-form :inline="true" :model="queryParams" class="stats-filter-form">
|
||||
<list-time-filter
|
||||
v-model:time-type="time_type"
|
||||
v-model:date-range="dateRange"
|
||||
@time-type-change="onTimeTypeChange"
|
||||
@custom-change="onCustomDateChange"
|
||||
/>
|
||||
|
||||
<el-form-item label="部门">
|
||||
<el-tree-select
|
||||
@@ -33,7 +23,7 @@
|
||||
placeholder="全部部门"
|
||||
clearable
|
||||
filterable
|
||||
class="w-[220px]"
|
||||
class="cost-input"
|
||||
@change="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
@@ -44,42 +34,70 @@
|
||||
:loading="mediaSourceLoading"
|
||||
placeholder="全部来源"
|
||||
:allow-create="false"
|
||||
select-class="w-[220px]"
|
||||
select-class="cost-input"
|
||||
@change="handleQuery"
|
||||
@visible-change="onMediaSourceDropdownVisible"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item class="w-[280px]" label="备注/录入人">
|
||||
<el-form-item class="cost-remark-filter" label="备注/录入人">
|
||||
<el-input
|
||||
v-model="queryParams.remark"
|
||||
placeholder="备注 / 创建人"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="pager.loading" @click="handleQuery">查询</el-button>
|
||||
<el-form-item class="cost-filter-actions">
|
||||
<el-button type="primary" native-type="submit" :disabled="awaitingDates">查询</el-button>
|
||||
<el-button @click="handleReset">重置</el-button>
|
||||
<el-button v-if="selfInputPath" class="ml-2" @click="goSelfInput">返回统计</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card class="!border-none mt-4" shadow="never">
|
||||
<div>
|
||||
<el-button v-perms="['stats.personal_account_cost/add']" type="primary" @click="handleAdd">
|
||||
<template #icon>
|
||||
<icon name="el-icon-Plus" />
|
||||
</template>
|
||||
新增
|
||||
</el-button>
|
||||
</div>
|
||||
<el-card shadow="never" class="cost-results">
|
||||
<template #header>
|
||||
<div class="cost-heading">
|
||||
<h2>账户消耗明细</h2>
|
||||
<div class="cost-heading-actions">
|
||||
<el-button v-if="selfInputPath" @click="goSelfInput">返回统计</el-button>
|
||||
<el-button v-perms="['stats.personal_account_cost/add']" type="primary" @click="handleAdd">
|
||||
<template #icon><icon name="el-icon-Plus" /></template>
|
||||
新增
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists">
|
||||
<dl class="cost-summary" aria-label="当前筛选汇总" :aria-busy="state === 'loading'">
|
||||
<div>
|
||||
<dt>累计账户消耗 (元)</dt>
|
||||
<dd>
|
||||
<span v-if="state === 'loading'" class="cost-skeleton" aria-hidden="true"></span>
|
||||
<template v-else>{{ state === 'ready' ? money(pager.extend?.total_amount) : '—' }}</template>
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt title="按有记录的日期去重">当前筛选天数</dt>
|
||||
<dd>
|
||||
<span v-if="state === 'loading'" class="cost-skeleton is-count" aria-hidden="true"></span>
|
||||
<template v-else>{{ state === 'ready' ? (pager.extend?.days_count ?? '—') : '—' }}</template>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<el-table
|
||||
:data="state === 'ready' ? pager.lists : []"
|
||||
size="large"
|
||||
:aria-busy="state === 'loading'"
|
||||
>
|
||||
<template #empty>
|
||||
<span v-if="state === 'error'" role="alert">账户消耗加载失败。</span>
|
||||
<el-button v-if="state === 'error'" type="primary" link @click="loadCosts">重新加载</el-button>
|
||||
<span v-else role="status">{{ emptyText }}</span>
|
||||
</template>
|
||||
<el-table-column label="日期" prop="cost_date" min-width="120" />
|
||||
<el-table-column label="自媒体来源" prop="media_source" min-width="160" show-overflow-tooltip />
|
||||
<el-table-column label="账户消耗" min-width="120">
|
||||
<template #default="{ row }">¥{{ row.amount }}</template>
|
||||
<el-table-column label="账户消耗" min-width="120" align="right">
|
||||
<template #default="{ row }">{{ money(row.amount) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="备注" prop="remark" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column label="录入人" prop="creator_name" min-width="100" />
|
||||
@@ -99,10 +117,10 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="最后修改人" prop="updater_name" min-width="100" />
|
||||
<el-table-column label="更新时间" prop="update_time" min-width="180" />
|
||||
<el-table-column label="操作" width="160" fixed="right">
|
||||
<el-table-column v-if="canEdit || canDelete" label="操作" :width="canEdit && canDelete ? 120 : 78" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['stats.personal_account_cost/edit']"
|
||||
v-if="canEdit"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleEdit(row)"
|
||||
@@ -110,7 +128,7 @@
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['stats.personal_account_cost/delete']"
|
||||
v-if="canDelete"
|
||||
type="danger"
|
||||
link
|
||||
@click="handleDelete(row.id)"
|
||||
@@ -121,8 +139,8 @@
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="flex justify-end mt-4">
|
||||
<pagination v-model="pager" @change="getLists" />
|
||||
<div v-if="state === 'ready'" class="cost-pagination">
|
||||
<pagination v-model="pager" @change="loadCosts" />
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
@@ -143,6 +161,7 @@ import { deptAll } from '@/api/org/department'
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
import { getRoutePath } from '@/router'
|
||||
import feedback from '@/utils/feedback'
|
||||
import { hasPermission } from '@/utils/perm'
|
||||
|
||||
import CostEditPopup from './cost-edit.vue'
|
||||
import MediaSourceSelect from './MediaSourceSelect.vue'
|
||||
@@ -169,6 +188,12 @@ const deptTreeProps = {
|
||||
|
||||
const selfInputPath = computed(() => getRoutePath('stats.self_input/overview') || '')
|
||||
|
||||
const canEdit = computed(() => hasPermission(['stats.personal_account_cost/edit']))
|
||||
const canDelete = computed(() => hasPermission(['stats.personal_account_cost/delete']))
|
||||
|
||||
// Keep the API's decimal representation (including trailing zeros); missing is not zero.
|
||||
const money = (value?: number | string | null) => value == null || value === '' ? '—' : `¥${value}`
|
||||
|
||||
const goSelfInput = () => {
|
||||
if (selfInputPath.value) {
|
||||
router.push(selfInputPath.value)
|
||||
@@ -186,11 +211,12 @@ const {
|
||||
dateRange,
|
||||
resolve,
|
||||
handleTimeTypeChange,
|
||||
handleCustomDateChange,
|
||||
resetTimeFilter,
|
||||
} = useListTimeFilter('today')
|
||||
|
||||
const { pager, getLists, resetPage } = usePaging({
|
||||
const { pager, getLists } = usePaging({
|
||||
firstLoading: true,
|
||||
latestOnly: true,
|
||||
fetchFun: async (params: Record<string, any>) => {
|
||||
const [start_date, end_date] = resolve()
|
||||
return personalAccountCostLists({
|
||||
@@ -202,13 +228,39 @@ const { pager, getLists, resetPage } = usePaging({
|
||||
params: queryParams,
|
||||
})
|
||||
|
||||
const awaitingDates = computed(() => time_type.value === 'custom' &&
|
||||
!(dateRange.value?.[0] && dateRange.value?.[1]))
|
||||
const failed = ref(false)
|
||||
const state = computed(() => awaitingDates.value ? 'dates' : pager.loading ? 'loading' : failed.value ? 'error' : 'ready')
|
||||
const emptyText = computed(() => ({
|
||||
dates: '请选择开始和结束日期',
|
||||
loading: '正在加载账户消耗…',
|
||||
ready: '当前筛选下没有消耗记录',
|
||||
error: '',
|
||||
})[state.value])
|
||||
|
||||
const loadCosts = async () => {
|
||||
if (awaitingDates.value) return
|
||||
failed.value = false
|
||||
try {
|
||||
await getLists()
|
||||
} catch {
|
||||
// latestOnly suppresses superseded failures. Clear the last successful
|
||||
// result only when the current request fails, without changing the page to retry.
|
||||
failed.value = true
|
||||
pager.lists = []
|
||||
pager.extend = {}
|
||||
pager.count = 0
|
||||
}
|
||||
}
|
||||
|
||||
const handleQuery = () => {
|
||||
if (awaitingDates.value) return
|
||||
pager.page = 1
|
||||
getLists()
|
||||
return loadCosts()
|
||||
}
|
||||
|
||||
const onTimeTypeChange = () => handleTimeTypeChange(handleQuery)
|
||||
const onCustomDateChange = () => handleCustomDateChange(handleQuery)
|
||||
|
||||
const handleReset = () => {
|
||||
resetTimeFilter()
|
||||
@@ -217,7 +269,7 @@ const handleReset = () => {
|
||||
queryParams.remark = ''
|
||||
pager.page = 1
|
||||
pager.size = 15
|
||||
getLists()
|
||||
return loadCosts()
|
||||
}
|
||||
|
||||
const onMediaSourceDropdownVisible = (visible: boolean) => {
|
||||
@@ -228,7 +280,7 @@ const onMediaSourceDropdownVisible = (visible: boolean) => {
|
||||
|
||||
const handleCostSuccess = async () => {
|
||||
await refreshMediaSourceOptions()
|
||||
getLists()
|
||||
await loadCosts()
|
||||
}
|
||||
|
||||
const handleAdd = async () => {
|
||||
@@ -246,9 +298,14 @@ const handleEdit = async (row: Record<string, any>) => {
|
||||
}
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
await feedback.confirm('确定删除该账户消耗记录?')
|
||||
try {
|
||||
await feedback.confirm('确定删除该账户消耗记录?')
|
||||
} catch (reason) {
|
||||
if (reason === 'cancel' || reason === 'close') return
|
||||
throw reason
|
||||
}
|
||||
await personalAccountCostDelete({ id })
|
||||
getLists()
|
||||
await loadCosts()
|
||||
}
|
||||
|
||||
const loadDeptOptions = async () => {
|
||||
@@ -265,23 +322,99 @@ const loadDeptOptions = async () => {
|
||||
onMounted(async () => {
|
||||
loadDeptOptions()
|
||||
loadMediaSourceOptions()
|
||||
await getLists()
|
||||
await loadCosts()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.personal-account-cost-page {
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
padding: 20px;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
:root[data-admin-ui='v2'] .personal-account-cost-page { padding: 0; }
|
||||
|
||||
.cost-filter-card, .cost-results { min-width: 0; }
|
||||
|
||||
.stats-filter-form {
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
display: grid;
|
||||
grid-template-columns: minmax(125px, 1fr) minmax(125px, 1fr) minmax(155px, 1.4fr) auto;
|
||||
align-items: end;
|
||||
gap: 12px 16px;
|
||||
:deep(.el-form-item) { margin: 0; min-width: 0; }
|
||||
:deep(.el-form-item__label) { margin-bottom: 4px; }
|
||||
:deep(.el-form-item__content), :deep(.el-radio-group) { min-width: 0; }
|
||||
:deep(.cost-input) { width: 100%; }
|
||||
}
|
||||
.cost-time-filter {
|
||||
grid-column: 1 / -1;
|
||||
min-width: 0;
|
||||
:deep(.el-form-item) { display: flex; flex-flow: row wrap; align-items: center; gap: 6px 12px; }
|
||||
:deep(.el-form-item__label) { margin: 0; }
|
||||
:deep(.list-time-filter-inline), :deep(.el-date-editor) { max-width: 100%; }
|
||||
}
|
||||
|
||||
.dept-cell {
|
||||
cursor: help;
|
||||
border-bottom: 1px dashed #c0c4cc;
|
||||
.cost-heading, .cost-heading-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
:deep(.el-button + .el-button) { margin-left: 0; }
|
||||
}
|
||||
.cost-heading { justify-content: space-between; }
|
||||
.cost-heading h2 { margin: 0; font-size: 16px; font-weight: 600; }
|
||||
.cost-summary {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
margin: 0 0 18px;
|
||||
padding: 0;
|
||||
dt { color: var(--el-text-color-regular); font-size: 13px; }
|
||||
dd {
|
||||
margin: 4px 0 0;
|
||||
font-size: clamp(22px, 2.6vw, 32px);
|
||||
font-weight: 600;
|
||||
line-height: 1.22;
|
||||
font-variant-numeric: tabular-nums;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
}
|
||||
.cost-skeleton {
|
||||
display: inline-block;
|
||||
height: .7em;
|
||||
width: min(5em, 85%);
|
||||
border-radius: 4px;
|
||||
background: var(--el-fill-color);
|
||||
&.is-count { width: min(1.8em, 85%); }
|
||||
}
|
||||
.cost-pagination {
|
||||
margin-top: 16px;
|
||||
:deep(.el-pagination) { justify-content: flex-end; flex-wrap: wrap; row-gap: 6px; }
|
||||
}
|
||||
.dept-cell { cursor: help; border-bottom: 1px dashed var(--el-text-color-secondary); }
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.stats-filter-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.personal-account-cost-page { gap: 12px; padding: 8px; }
|
||||
.cost-results, .cost-filter-card {
|
||||
:deep(.el-card__header), :deep(.el-card__body) { padding: 12px; }
|
||||
}
|
||||
.stats-filter-form { gap: 8px 10px; }
|
||||
.cost-time-filter {
|
||||
:deep(.el-form-item) { display: block; }
|
||||
:deep(.el-form-item__label) { margin-bottom: 4px; }
|
||||
:deep(.el-radio-group) { flex-wrap: wrap; row-gap: 4px; }
|
||||
:deep(.el-radio-button__inner) { padding-inline: 8px; }
|
||||
}
|
||||
.cost-remark-filter, .cost-filter-actions { grid-column: 1 / -1; }
|
||||
.cost-summary { margin-bottom: 12px; gap: 8px; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.personal-account-cost-page :deep(*) { transition-duration: 0s !important; }
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -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