重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,508 @@
/**
* Purpose: dashboardApi supports index.js by holding or executing the dashboard api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const dashboardApi = require('../../api/dashboard')
/**
* Purpose: orderApi supports index.js by holding or executing the order api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const orderApi = require('../../api/order')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: permission supports index.js by holding or executing the permission page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const permission = require('../../utils/permission')
/**
* Purpose: cache supports index.js by holding or executing the cache page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const cache = require('../../utils/cache')
const { CACHE_TTL } = require('../../utils/config')
const { consumeDirty } = require('../../utils/page-state')
function formatMoney(value) {
return Number(value || 0).toFixed(2)
}
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: userInfo supports index.js by holding or executing the user info page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userInfo: null,
/**
* Purpose: currentShop supports index.js by holding or executing the current shop page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentShop: null,
/**
* Purpose: permissionCount supports index.js by holding or executing the permission count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionCount: 0,
/**
* Purpose: shortcutModules supports index.js by holding or executing the shortcut modules page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shortcutModules: [],
/**
* Purpose: stats supports index.js by holding or executing the stats page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
stats: null,
/**
* Purpose: pendingOrders supports index.js by holding or executing the pending orders page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
pendingOrders: 0,
/**
* Purpose: analytics stores vNext operations analytics for the mobile workbench summary.
* Usage: set from dashboard analytics when the current user has analytics:view.
*/
analytics: null,
/**
* Purpose: todoStats stores lightweight operations todo counters for the workbench.
* Usage: show pending order and vNext operations counts without blocking the base dashboard.
*/
todoStats: [],
/**
* Purpose: shoplessAdmin supports index.js by holding or executing the shopless admin page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shoplessAdmin: false,
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
if (!navigation.ensureLogin('进入工作台')) {
return
}
this.syncGlobalState()
const dirty = consumeDirty('admin-workbench')
if (!this.data.initialized || dirty) {
this.loadDashboard({
/**
* Purpose: force supports index.js by holding or executing the force page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
force: dirty
})
}
},
/**
* Purpose: syncGlobalState supports index.js by holding or executing the sync global state page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
syncGlobalState() {
const app = getApp()
const userInfo = app.globalData.userInfo
const currentShop = app.globalData.currentShop
const permissionCodes = app.globalData.permissionCodes || []
const modules = permission.getManageModules(userInfo, permissionCodes, currentShop)
this.setData({
userInfo,
currentShop,
/**
* Purpose: permissionCount supports index.js by holding or executing the permission count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionCount: permissionCodes.length,
/**
* Purpose: shortcutModules supports index.js by holding or executing the shortcut modules page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shortcutModules: modules.filter(item => item.allowed).slice(0, 4),
/**
* Purpose: shoplessAdmin supports index.js by holding or executing the shopless admin page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shoplessAdmin: permission.isPlatformAdmin(userInfo) && !currentShop
})
},
async loadDashboard(options) {
const requestId = (this._loadRequestId || 0) + 1
this._loadRequestId = requestId
const force = Boolean(options && options.force)
const app = getApp()
const permissionCodes = app.globalData.permissionCodes || []
const currentShopId = this.data.currentShop && this.data.currentShop.id ? String(this.data.currentShop.id) : 'none'
const statsCacheKey = `workbench:stats:${currentShopId}`
const pendingCacheKey = `workbench:pending:${currentShopId}`
const analyticsCacheKey = `workbench:analytics:${currentShopId}`
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: true
})
if (this.data.shoplessAdmin) {
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: stats supports index.js by holding or executing the stats page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
stats: null,
analytics: null,
todoStats: [],
/**
* Purpose: pendingOrders supports index.js by holding or executing the pending orders page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
pendingOrders: 0,
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: true
})
}
return
}
if (permission.hasPermission(permissionCodes, 'dashboard:view')) {
try {
if (force) {
cache.removeCache(statsCacheKey)
}
const stats = force
? await dashboardApi.getStats()
: await cache.remember(statsCacheKey, CACHE_TTL.workbench, () => dashboardApi.getStats())
if (requestId !== this._loadRequestId) {
return
}
this.setData({
stats,
/**
* Purpose: pendingOrders supports index.js by holding or executing the pending orders page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
pendingOrders: Number(stats && stats.todayOrders) || 0,
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: true
})
} catch (error) {}
}
await this.loadOperationsSummary({
requestId,
force,
permissionCodes,
analyticsCacheKey,
pendingCacheKey
})
if (requestId !== this._loadRequestId) {
return
}
if (this.data.initialized) {
return
}
if (this.data.analytics || this.data.todoStats.length) {
this.setData({
loading: false,
initialized: true
})
return
}
if (permission.hasPermission(permissionCodes, 'order:view')) {
try {
if (force) {
cache.removeCache(pendingCacheKey)
}
const result = force
? await orderApi.listOrders({
/**
* Purpose: page supports index.js by holding or executing the page page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
size: 20,
/**
* Purpose: status supports index.js by holding or executing the status page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
status: 1
})
: await cache.remember(pendingCacheKey, CACHE_TTL.workbench, () => orderApi.listOrders({
/**
* Purpose: page supports index.js by holding or executing the page page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
size: 20,
/**
* Purpose: status supports index.js by holding or executing the status page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
status: 1
}))
if (requestId !== this._loadRequestId) {
return
}
this.setData({
/**
* Purpose: stats supports index.js by holding or executing the stats page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
stats: null,
/**
* Purpose: pendingOrders supports index.js by holding or executing the pending orders page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
pendingOrders: Number(result && result.total) || 0,
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: true
})
} catch (error) {
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: stats supports index.js by holding or executing the stats page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
stats: null,
/**
* Purpose: pendingOrders supports index.js by holding or executing the pending orders page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
pendingOrders: 0,
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: true
})
}
}
return
}
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: stats supports index.js by holding or executing the stats page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
stats: null,
/**
* Purpose: pendingOrders supports index.js by holding or executing the pending orders page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
pendingOrders: 0,
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: true
})
}
},
async loadOperationsSummary(options) {
const requestId = options.requestId
const force = options.force
const permissionCodes = options.permissionCodes || []
const analyticsCacheKey = options.analyticsCacheKey
const pendingCacheKey = options.pendingCacheKey
const tasks = []
if (permission.hasPermission(permissionCodes, 'analytics:view')) {
if (force) {
cache.removeCache(analyticsCacheKey)
}
tasks.push(cache.remember(analyticsCacheKey, CACHE_TTL.workbench, () => dashboardApi.getAnalytics())
.then(analytics => ({ key: 'analytics', value: analytics }))
.catch(() => ({ key: 'analytics', value: null })))
}
if (permission.hasPermission(permissionCodes, 'order:view')) {
if (force) {
cache.removeCache(pendingCacheKey)
}
tasks.push(cache.remember(pendingCacheKey, CACHE_TTL.workbench, () => orderApi.listOrders({
page: 1,
size: 1,
status: 1
})).then(result => ({
key: 'pendingOrders',
value: Number(result && result.total) || 0
})).catch(() => ({
key: 'pendingOrders',
value: 0
})))
}
if (!tasks.length) {
return
}
const results = await Promise.all(tasks)
if (requestId !== this._loadRequestId) {
return
}
const nextData = {}
results.forEach(item => {
nextData[item.key] = item.value
})
const analytics = Object.prototype.hasOwnProperty.call(nextData, 'analytics') ? nextData.analytics : this.data.analytics
const pendingOrders = Object.prototype.hasOwnProperty.call(nextData, 'pendingOrders') ? nextData.pendingOrders : this.data.pendingOrders
nextData.todoStats = this.buildTodoStats(analytics, pendingOrders, permissionCodes)
nextData.analytics = analytics
nextData.pendingOrders = pendingOrders
this.setData(nextData)
},
buildTodoStats(analytics, pendingOrders, permissionCodes) {
const todos = []
if (permission.hasPermission(permissionCodes, 'order:view')) {
todos.push({
key: 'orders',
label: '待服务订单',
value: pendingOrders || 0,
note: '来自订单待服务状态',
path: '/pages/orders/index'
})
}
if (permission.hasPermission(permissionCodes, 'after_sale:view')) {
todos.push({
key: 'afterSales',
label: '售后待处理',
value: '--',
note: '进入售后处理查看明细',
path: '/pages/after-sales/index'
})
}
if (permission.hasPermission(permissionCodes, 'inventory:view')) {
todos.push({
key: 'inventory',
label: '库存预警',
value: '--',
note: '进入库存管理查看低库存',
path: '/pages/inventory/index'
})
}
if (analytics) {
todos.push({
key: 'paid',
label: '已支付订单',
value: Number(analytics.paidOrderCount) || 0,
note: `GMV ¥${formatMoney(analytics.totalAmount)}`
})
}
return todos.slice(0, 4)
},
/**
* Purpose: handleOpenModule supports index.js by holding or executing the handle open module page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleOpenModule(event) {
const path = event.currentTarget.dataset.path
if (!path) {
return
}
if (path === '/pages/orders/index') {
navigation.switchTab(path)
return
}
navigation.navigate(path).catch(() => undefined)
},
/**
* Purpose: handleOpenShops supports index.js by holding or executing the handle open shops page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleOpenShops() {
navigation.navigate('/pages/shops/index').catch(() => undefined)
},
/**
* Purpose: handleOpenOrders supports index.js by holding or executing the handle open orders page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleOpenOrders() {
navigation.switchTab('/pages/orders/index').catch(() => undefined)
},
handleOpenManage() {
navigation.switchTab('/pages/manage/index').catch(() => undefined)
},
handleOpenProfile() {
navigation.switchTab('/pages/profile/index').catch(() => undefined)
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,103 @@
<navigation-bar title="工作台" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">{{userInfo.nickname || userInfo.account || '后台账号'}}</text>
<text class="hero-title">{{currentShop ? currentShop.shopName : '平台总览模式'}}</text>
<text class="hero-desc">当前身份:{{userInfo ? userInfo.type === 4 ? '平台管理员' : userInfo.type === 2 ? '店长' : '美甲师' : '--'}}。已同步 {{permissionCount}} 项后台权限。</text>
<view class="badge-row">
<text class="badge">{{currentShop ? '当前店铺已锁定' : '平台总览'}}</text>
<text class="soft-badge">{{shoplessAdmin ? '店铺业务仅查看' : '移动端工作流已就绪'}}</text>
</view>
</view>
<view wx:if="{{shoplessAdmin}}" class="surface-card">
<text class="section-title">平台总览模式</text>
<text class="section-desc">当前管理员不绑定具体店铺,可查看全局数据和店铺业务列表;涉及新增、编辑、删除、发放等操作会被服务端拦截。</text>
<view class="action-row">
<button class="primary-btn" bindtap="handleOpenShops">进入店铺管理</button>
</view>
</view>
<view wx:else class="surface-card">
<text class="section-title">今日概览</text>
<text class="section-desc">把高频动作和最关键的经营数字集中到一屏,方便在手机上快速判断接下来该处理什么。</text>
<view class="stats-grid">
<view class="stat-card">
<text class="stat-label">待处理订单</text>
<text class="stat-value">{{pendingOrders}}</text>
<text class="stat-note">优先处理预约确认与履约</text>
</view>
<view class="stat-card">
<text class="stat-label">当前权限</text>
<text class="stat-value">{{permissionCount}}</text>
<text class="stat-note">前端仅做显隐,服务端仍会兜底校验</text>
</view>
<view class="stat-card" wx:if="{{analytics}}">
<text class="stat-label">经营订单</text>
<text class="stat-value">{{analytics.orderCount || 0}}</text>
<text class="stat-note">支付 {{analytics.paidOrderCount || 0}} · 完成 {{analytics.completedOrderCount || 0}}</text>
</view>
<view class="stat-card" wx:if="{{analytics}}">
<text class="stat-label">收藏/加购</text>
<text class="stat-value">{{analytics.favoriteCount || 0}}/{{analytics.cartCount || 0}}</text>
<text class="stat-note">浏览 {{analytics.viewCount || 0}} · 评价 {{analytics.reviewCount || 0}}</text>
</view>
<view class="stat-card" wx:if="{{stats}}">
<text class="stat-label">用户总量</text>
<text class="stat-value">{{stats.totalUsers || 0}}</text>
<text class="stat-note">按当前角色与店铺范围计算</text>
</view>
<view class="stat-card" wx:if="{{stats}}">
<text class="stat-label">作品总量</text>
<text class="stat-value">{{stats.totalProducts || 0}}</text>
<text class="stat-note">支持后续直接跳去作品管理</text>
</view>
</view>
<view class="action-row">
<button class="secondary-btn" bindtap="handleOpenOrders">查看订单</button>
</view>
</view>
<view wx:if="{{!shoplessAdmin && todoStats.length}}" class="surface-card">
<text class="section-title">待办与运营</text>
<text class="section-desc">同步 vNext 运营能力的轻量摘要,点有入口的待办可直接进入处理页。</text>
<view class="stats-grid">
<block wx:for="{{todoStats}}" wx:key="key">
<view class="stat-card" data-path="{{item.path}}" bindtap="handleOpenModule">
<text class="stat-label">{{item.label}}</text>
<text class="stat-value">{{item.value}}</text>
<text class="stat-note">{{item.note}}</text>
</view>
</block>
</view>
</view>
<view class="surface-card">
<text class="section-title">快捷入口</text>
<text class="section-desc">只展示当前账号真实可进入的模块,避免手机端一屏堆太多无权限入口。</text>
<block wx:for="{{shortcutModules}}" wx:key="key">
<view class="list-card" data-path="{{item.path}}" bindtap="handleOpenModule">
<view class="list-head">
<view>
<text class="list-title">{{item.title}}</text>
<text class="list-subtitle">{{item.description}}</text>
</view>
<text class="badge">进入</text>
</view>
</view>
</block>
<view wx:if="{{!shortcutModules.length}}" class="empty-state">
<text class="empty-title">暂无可用快捷入口</text>
<text class="empty-desc">当前账号没有可直接打开的后台模块,请先检查权限或切换店铺。</text>
</view>
</view>
<view class="admin-bottom-nav">
<view class="admin-bottom-link active">工作台</view>
<view class="admin-bottom-link" bindtap="handleOpenOrders">订单</view>
<view class="admin-bottom-link" bindtap="handleOpenManage">经营</view>
<view class="admin-bottom-link" bindtap="handleOpenProfile">我的</view>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}