This commit is contained in:
yin 2026-10-21 17:59:49 +08:00
parent 91dd317867
commit fc3b26e6c8
11 changed files with 1962 additions and 936 deletions

1320
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,36 +39,37 @@
"check:pages": "node scripts/check-pages.mjs"
},
"dependencies": {
"@dcloudio/uni-app": "3.0.0-5020420260813003",
"@dcloudio/uni-app-harmony": "3.0.0-5020420260813003",
"@dcloudio/uni-app-plus": "3.0.0-5020420260813003",
"@dcloudio/uni-components": "3.0.0-5020420260813003",
"@dcloudio/uni-h5": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-alipay": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-baidu": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-harmony": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-jd": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-kuaishou": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-lark": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-qq": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-toutiao": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-weixin": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-xhs": "3.0.0-5020420260813003",
"@dcloudio/uni-quickapp-webview": "3.0.0-5020420260813003",
"@dcloudio/uni-app": "3.0.0-5020620260917001",
"@dcloudio/uni-app-harmony": "3.0.0-5020620260917001",
"@dcloudio/uni-app-plus": "3.0.0-5020620260917001",
"@dcloudio/uni-components": "3.0.0-5020620260917001",
"@dcloudio/uni-h5": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-alipay": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-baidu": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-harmony": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-jd": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-kuaishou": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-lark": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-qq": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-toutiao": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-weixin": "3.0.0-5020620260917001",
"@dcloudio/uni-mp-xhs": "3.0.0-5020620260917001",
"@dcloudio/uni-quickapp-webview": "3.0.0-5020620260917001",
"clipboard": "^2.0.11",
"dayjs": "^1.11.23",
"pinia": "^2.1.7",
"uview-plus": "^3.8.125",
"vue": "^3.4.21",
"vue-i18n": "^9.1.9"
"vue": "3.4.21",
"vue-i18n": "9.14.5"
},
"devDependencies": {
"@dcloudio/types": "^3.4.8",
"@dcloudio/uni-automator": "3.0.0-5020420260813003",
"@dcloudio/uni-cli-shared": "3.0.0-5020420260813003",
"@dcloudio/uni-stacktracey": "3.0.0-5020420260813003",
"@dcloudio/vite-plugin-uni": "3.0.0-5020420260813003",
"@vue/runtime-core": "^3.4.21",
"@dcloudio/types": "3.4.31",
"@dcloudio/uni-automator": "3.0.0-5020620260917001",
"@dcloudio/uni-cli-shared": "3.0.0-5020620260917001",
"@dcloudio/uni-stacktracey": "3.0.0-5020620260917001",
"@dcloudio/vite-plugin-uni": "3.0.0-5020620260917001",
"@vue/runtime-core": "3.5.44",
"rollup": "4.14.3",
"sass": "^1.63.2",
"typescript": "^6.0.3",
"vite": "5.2.8",

View File

@ -0,0 +1,157 @@
/**
* 首页看板(dashboard.*)
*
* 与 new3(Web 端)`src/api/dashboard/dashboard.ts` + `views/dashboard/*` 同源,
* 全部走 `/system` 网关,业务参数放 body(看板接口目前都是**无业务入参**,
* 只有热销排行可带 `{ top: 10 }`)。
*
* ⚠️ 响应外层不统一(与项目其它接口同类):业务字段可能在 `data` 里,
* 也可能直接落在响应顶层 —— 统一用 `unwrap()` 兼容两种情况。
*
* 权限点(对应 web 端模块显隐,小程序端只用于**选择**调用哪个统计接口):
* - `dashboard.storeBaseData` → 货主侧统计(真实数据,跨已签约仓库汇总)
* - `dashboard.warehouseBaseData` → 仓库侧统计(**后端返回固定演示数据**)
*/
import request from '@/utils/request'
import { SYSTEM_URL, gatewayParams } from '@/utils/gateway'
/** 发货统计(dashboard.storeStats / dashboard.warehouseStats 的 data) */
export interface DashboardStats {
/** 今日订单数 */
todayOrders?: number
/** 今日新增较昨日增长率(%) */
orderTrend?: number
/** 未分配快递号订单数 */
unassignedOrders?: number
/** 未打印订单数 */
unprintedOrders?: number
/** 未拣货订单数 */
unpickedOrders?: number
/** 待发货订单数 */
pendingShipments?: number
/** 发货进度(%) */
shipmentProgress?: number
/** 今日已出库订单数 */
todayOutbound?: number
/** 出库完成率(%) */
outboundRate?: number
/** 拦截订单数 */
interceptedOrders?: number
/** 异常订单数 */
exceptionOrders?: number
/** 已复核订单数(仅 storeStats) */
recheckedOrders?: number
/** 复核进度(%)(仅 storeStats,后端可能不下发,前端按 已复核/今日订单 兜底) */
recheckProgress?: number
/** 已打包订单数(仅 storeStats) */
packedOrders?: number
/** 打包完成率(%)(仅 storeStats,后端可能不下发,前端按 已打包/今日订单 兜底) */
packRate?: number
}
/** 饼图项(平台分布 / 快递占比) */
export interface DashboardRatioItem {
/** 平台 / 快递公司名称(未填写时为「未指定平台」/「未指定快递」) */
name: string
/** 订单数 */
value: number
/** 后端下发的配色(可缺省,前端有兜底色板) */
itemStyle?: { color?: string }
}
/** 热销商品排行项(今日销量 Top10,`name` 后端已脱敏) */
export interface DashboardRankItem {
/** 排行序号(从 1 开始) */
id: number
/** 商品名称(脱敏) */
name: string
/** 库存商品 ID(极少数情况回退商品编码字符串) */
sku: number | string
/** 今日销量(件) */
value: number
/** 环比昨日(%,1 位小数) */
trend: number
}
/** 统计接口方法名 */
export type DashboardStatsMethod = 'dashboard.storeStats' | 'dashboard.warehouseStats'
/** 拆信封:优先取 `data`,没有则用响应本身 */
function unwrap<T>(body: any): T {
return (body && body.data !== undefined && body.data !== null ? body.data : body) as T
}
/** 列表容错:直接数组 / `list`、`items`、`rows` / `data` 包裹 */
function pickRows(body: any): any[] {
if (Array.isArray(body)) return body
for (const key of ['list', 'items', 'rows']) {
if (Array.isArray(body?.[key])) return body[key]
}
const inner = body?.data
if (inner && inner !== body) return pickRows(inner)
return []
}
/** 统一的 dashboard.* 调用(失败不 toast,由页面按面板给出重试入口) */
async function callDashboard<T>(method: string, data: Record<string, any> = {}): Promise<T> {
const res = await request<any>({
url: SYSTEM_URL,
method: 'POST',
params: gatewayParams(method),
data,
auth: true,
toastError: false
})
return unwrap<T>(res)
}
/**
* 发货统计(今日订单 / 未分配快递单号等)
*
* - `dashboard.storeStats`:货主侧真实数据(默认)
* - `dashboard.warehouseStats`:仓库侧(后端目前返回**演示数据**)
*/
export async function fetchDashboardStats(
method: DashboardStatsMethod = 'dashboard.storeStats'
): Promise<DashboardStats> {
const data = await callDashboard<DashboardStats>(method)
return data && typeof data === 'object' ? data : {}
}
/** 平台分布(饼图数据,按订单数降序) */
export async function fetchPlatformDistribution(): Promise<DashboardRatioItem[]> {
const data = await callDashboard<any>('dashboard.platform_distribution')
return normalizeRatio(pickRows(data))
}
/** 快递占比(饼图数据,按订单数降序) */
export async function fetchExpressRatio(): Promise<DashboardRatioItem[]> {
const data = await callDashboard<any>('dashboard.express_ratio')
return normalizeRatio(pickRows(data))
}
/** 热销商品排行(今日销量 Top10) */
export async function fetchHotOrderRank(top = 10): Promise<DashboardRankItem[]> {
const data = await callDashboard<any>('dashboard.hot_order_rank', { top })
return pickRows(data)
.map((item: any) => ({
id: Number(item?.id ?? 0),
name: String(item?.name ?? '未知商品'),
sku: item?.sku ?? '',
value: Number(item?.value ?? 0),
trend: Number(item?.trend ?? 0)
}))
.filter((item) => !!item.name)
}
/** 饼图项归一化:过滤无名称 / 非数字项 */
function normalizeRatio(rows: any[]): DashboardRatioItem[] {
return rows
.map((item: any) => ({
name: String(item?.name ?? '').trim() || '未指定',
value: Number(item?.value ?? 0),
itemStyle: item?.itemStyle
}))
.filter((item) => item.name !== '未指定' || item.value > 0)
}

View File

@ -0,0 +1,235 @@
<template>
<view class="ratio-card">
<view class="ratio-card__head">
<text class="ratio-card__title">{{ title }}</text>
<text v-if="!loading && !error && items.length" class="ratio-card__total">
共 {{ total }} 单
</text>
</view>
<!-- 加载中 -->
<view v-if="loading" class="ratio-card__state">加载中…</view>
<!-- 失败:面板级重试(不打断其它面板) -->
<view v-else-if="error" class="ratio-card__state ratio-card__state--error" @click="emit('retry')">
<text class="ratio-card__state-text">{{ error }}</text>
<text class="ratio-card__retry">点击重试</text>
</view>
<!-- 空数据 -->
<view v-else-if="!items.length" class="ratio-card__state">{{ emptyText }}</view>
<!-- 占比条 + 明细 -->
<template v-else>
<view class="ratio-card__bar">
<view
v-for="(item, index) in items"
:key="`seg-${item.name}-${index}`"
class="ratio-card__seg"
:style="{ width: percent(item) + '%', backgroundColor: colorOf(item, index) }"
></view>
</view>
<view class="ratio-card__list">
<view
v-for="(item, index) in items"
:key="`row-${item.name}-${index}`"
class="ratio-card__row"
>
<view class="ratio-card__dot" :style="{ backgroundColor: colorOf(item, index) }"></view>
<text class="ratio-card__name">{{ item.name }}</text>
<text class="ratio-card__value">{{ item.value }}</text>
<text class="ratio-card__percent">{{ percent(item) }}%</text>
</view>
</view>
</template>
</view>
</template>
<script setup lang="ts">
/**
* 占比面板(平台分布 / 快递占比共用)
*
* 为什么不用饼图:小程序端没有现成的 ECharts(web 端用 echarts,小程序包体与
* canvas 适配都是成本),移动端窄屏上「**顶部堆叠占比条 + 下方明细**」反而更易读:
* 每行都能同时看到 名称 / 单量 / 百分比。
*
* 用法:
* ```vue
* <ratio-card
* title="平台分布"
* :items="platformItems"
* :loading="platformLoading"
* :error="platformError"
* @retry="loadPlatform"
* />
* ```
*/
import { computed } from 'vue'
import type { DashboardRatioItem } from '@/api/dashboard/dashboard'
const props = withDefaults(
defineProps<{
title: string
items: DashboardRatioItem[]
loading?: boolean
/** 非空表示加载失败(显示可点击的重试) */
error?: string
emptyText?: string
}>(),
{
loading: false,
error: '',
emptyText: '暂无数据'
}
)
const emit = defineEmits<{ retry: [] }>()
/** 兜底色板:后端没下发 `itemStyle.color` 时按顺序取色 */
const PALETTE = [
'#2979ff',
'#19be6b',
'#ff9900',
'#f56c6c',
'#9c27b0',
'#00bcd4',
'#8d6e63',
'#909399'
]
const total = computed(() =>
props.items.reduce((sum, item) => sum + (Number(item.value) || 0), 0)
)
function percent(item: DashboardRatioItem): string {
if (!total.value) return '0'
const value = ((Number(item.value) || 0) / total.value) * 100
// 极小值也给个可视宽度,否则占比条上完全看不见
const fixed = value > 0 && value < 0.5 ? 0.5 : value
return fixed.toFixed(1)
}
function colorOf(item: DashboardRatioItem, index: number): string {
return item?.itemStyle?.color || PALETTE[index % PALETTE.length]
}
</script>
<style lang="scss" scoped>
.ratio-card {
margin: 0 24rpx 24rpx;
padding: 28rpx 28rpx 8rpx;
background-color: #ffffff;
border-radius: 24rpx;
box-shadow: 0 8rpx 24rpx rgba(41, 121, 255, 0.06);
&__head {
display: flex;
align-items: center;
justify-content: space-between;
}
&__title {
font-size: 30rpx;
font-weight: 600;
color: #303133;
}
&__total {
font-size: 24rpx;
color: #909399;
}
/* 堆叠占比条 */
&__bar {
display: flex;
width: 100%;
height: 20rpx;
margin-top: 24rpx;
border-radius: 999rpx;
overflow: hidden;
background-color: #f0f2f5;
}
&__seg {
height: 100%;
min-width: 4rpx;
}
&__list {
margin-top: 16rpx;
}
&__row {
display: flex;
align-items: center;
padding: 16rpx 0;
border-bottom: 1rpx solid #f5f7fa;
&:last-child {
border-bottom: none;
}
}
&__dot {
flex-shrink: 0;
width: 16rpx;
height: 16rpx;
margin-right: 16rpx;
border-radius: 50%;
}
&__name {
flex: 1;
min-width: 0;
font-size: 26rpx;
color: #606266;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&__value {
flex-shrink: 0;
min-width: 80rpx;
font-size: 26rpx;
color: #303133;
text-align: right;
}
&__percent {
flex-shrink: 0;
min-width: 110rpx;
font-size: 24rpx;
color: #909399;
text-align: right;
}
&__state {
display: flex;
align-items: center;
justify-content: center;
padding: 56rpx 0;
font-size: 26rpx;
color: #a8abb2;
&--error {
flex-direction: column;
color: #f56c6c;
}
}
&__state-text {
font-size: 26rpx;
color: #909399;
text-align: center;
}
&__retry {
margin-top: 12rpx;
font-size: 26rpx;
color: #2979ff;
}
}
</style>

View File

@ -9,9 +9,17 @@
},
"pages": [
{
"path": "pages/index/index",
"path": "pages/dashboard/dashboard",
"style": {
"navigationBarTitleText": "首页"
"navigationBarTitleText": "首页",
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark"
}
},
{
"path": "pages/workbench/workbench",
"style": {
"navigationBarTitleText": "工作台"
}
},
{
@ -119,9 +127,13 @@
"borderStyle": "black",
"list": [
{
"pagePath": "pages/index/index",
"pagePath": "pages/dashboard/dashboard",
"text": "首页"
},
{
"pagePath": "pages/workbench/workbench",
"text": "工作台"
},
{
"pagePath": "pages/mine/mine",
"text": "我的"
@ -133,7 +145,11 @@
"list": [
{
"name": "首页",
"path": "pages/index/index"
"path": "pages/dashboard/dashboard"
},
{
"name": "工作台",
"path": "pages/workbench/workbench"
},
{
"name": "登录",

File diff suppressed because it is too large Load Diff

View File

@ -116,7 +116,7 @@ import AuthModal from '@/components/auth-modal/auth-modal.vue'
import { savePendingLoginCode } from '@/utils/entry'
/** 首页(tabBar 页,返回时用 switchTab) */
const HOME_PAGE = '/pages/index/index'
const HOME_PAGE = '/pages/dashboard/dashboard'
const userStore = useUserStore()

View File

@ -38,10 +38,10 @@ import { getToken } from '@/utils/auth'
import { LOGIN_PAGE } from '@/utils/auth-guard'
/** 首页(tabBar 页) */
const HOME_PAGE = '/pages/index/index'
const HOME_PAGE = '/pages/dashboard/dashboard'
/** tabBar 页面清单:这些页面只能用 switchTab 进入 */
const TAB_PAGES = [HOME_PAGE, '/pages/mine/mine']
const TAB_PAGES = [HOME_PAGE, '/pages/workbench/workbench', '/pages/mine/mine']
/** 登录成功后要回跳的目标页,由 auth-guard 通过 redirect 参数带入 */
const redirect = ref('')

View File

@ -216,7 +216,7 @@
⚠️ 硬约束:`usePageAuth.goLogin()` 是「**就地弹抽屉**」而不是跳页(见 `composables/usePageAuth.ts`),
它只改 store 的 `authView`;**每个会调 `goLogin()` / `requireLogin()` 的页面都必须自己挂一份
`<auth-modal />`**,否则会出现「点了去登录没反应、回其他页面反而弹出登录框」(因为抽屉内容没了)。
同款挂载点:`pages/index/index.vue`、`pages/mine/mine.vue`、`pages/login/confirm-login.vue` 等。
同款挂载点:`pages/workbench/workbench.vue`、`pages/mine/mine.vue`、`pages/login/confirm-login.vue` 等。
-->
<auth-modal></auth-modal>

View File

@ -59,12 +59,23 @@ export interface PageMeta {
export const PAGE_REGISTRY: PageMeta[] = [
// ─────────────── 公共页面:无需登录即可访问,不会被拦截 ───────────────
{
key: '/home',
path: 'pages/index/index',
key: '/dashboard',
path: 'pages/dashboard/dashboard',
title: '首页',
icon: 'home',
auth: 'public',
tabBar: true,
// tabBar 本身就是入口,不再进九宫格;看板未登录时走页内引导(不强制登录)
hidden: true
},
{
// 原「首页」的功能入口页(动态菜单段 + 辅助工具段),现改名为「工作台」
key: '/home',
path: 'pages/workbench/workbench',
title: '工作台',
icon: 'grid',
auth: 'public',
tabBar: true,
// tabBar 本身就是入口,不再进九宫格
hidden: true
},