功能:新增下一阶段运营能力和生产部署
This commit is contained in:
@@ -26,6 +26,10 @@ 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.
|
||||
@@ -62,6 +66,16 @@ Page({
|
||||
* 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.
|
||||
@@ -142,6 +156,7 @@ Page({
|
||||
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({
|
||||
/**
|
||||
@@ -159,6 +174,8 @@ Page({
|
||||
* 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.
|
||||
@@ -208,10 +225,31 @@ Page({
|
||||
*/
|
||||
initialized: true
|
||||
})
|
||||
return
|
||||
} 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) {
|
||||
@@ -332,6 +370,100 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
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.
|
||||
|
||||
@@ -34,6 +34,16 @@
|
||||
<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>
|
||||
@@ -50,6 +60,20 @@
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user