feat: 管理端补充工作台图表、列表导出与批量操作

- 工作台新增近 7 日预约趋势与订单状态分布图

- 订单/用户/就诊人/陪诊师支持 CSV 导出,逐页拉取规避接口分页上限

- 订单列表增加状态快筛、筛选条件同步地址栏、加载失败重试

- 订单详情支持指派/更换陪诊师,性别值归一到订单枚举

- 用户列表支持批量锁定/解锁,导出补齐就诊人数量与归属信息

- 抽取 useTableQuery 统一分页、搜索与删除后页码回退

- ESLint 开启 vue/no-undef-properties,修复 EChart 扩展只注册一次的问题
This commit is contained in:
lik
2026-11-08 11:12:38 +08:00
parent b8b5c81352
commit c30ca3ed41
18 changed files with 1324 additions and 187 deletions
+139 -3
View File
@@ -23,6 +23,36 @@
</BCol>
</BRow>
<BRow class="g-3 mt-1">
<BCol xl="8">
<BCard no-body class="h-100">
<BCardHeader>
<h5 class="card-title mb-0">近 7 日预约趋势</h5>
</BCardHeader>
<BCardBody>
<div v-if="loading" class="text-center py-5">
<BSpinner variant="primary" />
</div>
<EChart v-else :get-options="trendOptions" :extensions="CHART_EXTENSIONS" style="height: 280px; width: 100%" />
</BCardBody>
</BCard>
</BCol>
<BCol xl="4">
<BCard no-body class="h-100">
<BCardHeader>
<h5 class="card-title mb-0">订单状态分布</h5>
</BCardHeader>
<BCardBody>
<div v-if="loading" class="text-center py-5">
<BSpinner variant="primary" />
</div>
<EChart v-else :get-options="statusOptions" :extensions="CHART_EXTENSIONS" style="height: 280px; width: 100%" />
</BCardBody>
</BCard>
</BCol>
</BRow>
<BRow class="g-3 mt-1">
<BCol xl="8">
<BCard no-body class="h-100">
@@ -134,7 +164,12 @@
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { LineChart, PieChart } from 'echarts/charts'
import { GridComponent, LegendComponent, TooltipComponent } from 'echarts/components'
import type { EChartsOption } from 'echarts'
import { CanvasRenderer } from 'echarts/renderers'
import { escortApi } from '~/api/escort'
import EChart from '~/components/wrappers/EChart.vue'
import PageBreadcrumb from '~/components/PageBreadcrumb.vue'
import Icon from '~/components/wrappers/Icon.vue'
import type { EscortRecord } from '~/types/api'
@@ -148,6 +183,17 @@ import {
today,
} from '~/utils/format'
const CHART_EXTENSIONS = [LineChart, PieChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer]
// 状态分布环形图配色(与 badge-soft 语义色对应)
const STATUS_COLORS: Record<string, string> = {
pending: '#f0ad4e',
confirmed: '#4d9ce8',
in_progress: '#5b6ee8',
completed: '#34c38f',
cancelled: '#98a6ad',
}
const loading = ref(true)
const recent = ref<EscortRecord[]>([])
const cancelRequests = ref<EscortRecord[]>([])
@@ -159,6 +205,9 @@ const summary = reactive({
unpaid: 0,
})
const statusCounts = reactive<Record<string, number>>({})
const trend = reactive<{ dates: string[]; counts: number[] }>({ dates: [], counts: [] })
const statCards = computed(() => [
{
label: '今日预约订单',
@@ -202,24 +251,111 @@ const recentFields = [
{ key: 'status', label: '状态' },
]
const trendOptions = computed<EChartsOption>(() => ({
tooltip: { trigger: 'axis' },
grid: { left: 8, right: 16, top: 28, bottom: 0, containLabel: true },
xAxis: {
type: 'category',
boundaryGap: false,
data: trend.dates,
axisTick: { show: false },
},
yAxis: { type: 'value', minInterval: 1, splitLine: { lineStyle: { type: 'dashed' } } },
series: [
{
name: '预约订单',
type: 'line',
smooth: true,
symbolSize: 6,
data: trend.counts,
lineStyle: { width: 2.5 },
areaStyle: { opacity: 0.08 },
itemStyle: { color: '#5b6ee8' },
},
],
}))
const statusOptions = computed<EChartsOption>(() => ({
tooltip: { trigger: 'item' },
legend: { bottom: 0, icon: 'circle', itemWidth: 8, itemHeight: 8, textStyle: { fontSize: 12 } },
series: [
{
name: '订单状态',
type: 'pie',
radius: ['52%', '76%'],
center: ['50%', '44%'],
avoidLabelOverlap: true,
label: { show: false },
itemStyle: { borderRadius: 4, borderColor: '#fff', borderWidth: 2 },
data: Object.keys(STATUS_LABELS).map((status) => ({
name: STATUS_LABELS[status],
value: statusCounts[status] || 0,
itemStyle: { color: STATUS_COLORS[status] },
})),
},
],
}))
const shiftDate = (days: number) => {
const date = new Date()
date.setDate(date.getDate() - days)
return formatDate(date)
}
const load = async () => {
loading.value = true
try {
const [todayRes, pendingRes, cancelRes, unpaidRes, recentRes, cancelListRes] = await Promise.all([
const statusKeys = Object.keys(STATUS_LABELS)
const [
todayRes,
cancelRes,
unpaidRes,
recentRes,
cancelListRes,
trendRes,
...statusResList
] = await Promise.all([
escortApi.list({ page: 1, pageSize: 1, appointmentDate: today() }),
escortApi.list({ page: 1, pageSize: 1, status: 'pending' }),
escortApi.list({ page: 1, pageSize: 1, cancelStatus: 'requested' }),
escortApi.list({ page: 1, pageSize: 1, paymentStatus: 'unpaid' }),
escortApi.list({ page: 1, pageSize: 8 }),
escortApi.list({ page: 1, pageSize: 5, cancelStatus: 'requested' }),
// 近 7 日订单,按预约日期在前端聚合出趋势
escortApi.list({
page: 1,
pageSize: 500,
startDate: shiftDate(6),
endDate: today(),
includeCancelled: '1',
}),
...statusKeys.map((status) => escortApi.list({ page: 1, pageSize: 1, status })),
])
summary.today = todayRes.total
summary.pending = pendingRes.total
summary.cancelRequested = cancelRes.total
summary.unpaid = unpaidRes.total
recent.value = recentRes.records
cancelRequests.value = cancelListRes.records
statusKeys.forEach((status, index) => {
statusCounts[status] = statusResList[index]?.total || 0
})
summary.pending = statusCounts.pending || 0
const countsByDate: Record<string, number> = {}
trendRes.records.forEach((item) => {
const date = formatDate(item.schedule?.date)
if (date !== '-') countsByDate[date] = (countsByDate[date] || 0) + 1
})
const dates: string[] = []
const counts: number[] = []
for (let i = 6; i >= 0; i--) {
const date = shiftDate(i)
dates.push(date.slice(5))
counts.push(countsByDate[date] || 0)
}
trend.dates = dates
trend.counts = counts
} finally {
loading.value = false
}