修复回归安全问题并补充验证
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const mock = require('../../utils/mock')
|
||||
|
||||
const EMPLOYEE_COLORS = ['#7BA7C7', '#89A98B', '#A893BC', '#D49A89', '#C9A66B', '#7E9A9A']
|
||||
|
||||
Page({
|
||||
data: {
|
||||
employees: []
|
||||
employees: [],
|
||||
loadError: false,
|
||||
errorMessage: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -11,11 +14,7 @@ Page({
|
||||
},
|
||||
|
||||
async loadEmployees() {
|
||||
const fallback = mock.artists.map((item, index) => ({
|
||||
...item,
|
||||
monthOrders: 32 - index * 5,
|
||||
monthAmount: 5800 - index * 760
|
||||
}))
|
||||
this.setData({ loadError: false, errorMessage: '' })
|
||||
try {
|
||||
const data = await employeesApi.list({ page: 1, size: 50 })
|
||||
const list = data.list || data || []
|
||||
@@ -24,13 +23,17 @@ Page({
|
||||
id: item.userId || item.id,
|
||||
name: item.nickname || item.name || item.artistName || `美甲师${index + 1}`,
|
||||
shortName: (item.nickname || item.name || '师').slice(-1),
|
||||
color: mock.artists[index % mock.artists.length].color,
|
||||
color: item.color || EMPLOYEE_COLORS[index % EMPLOYEE_COLORS.length],
|
||||
monthOrders: item.monthOrders || item.orderCount || 0,
|
||||
monthAmount: item.monthAmount || item.turnover || 0
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({ employees: fallback })
|
||||
this.setData({
|
||||
employees: [],
|
||||
loadError: true,
|
||||
errorMessage: error.message || '员工数据加载失败,请检查服务连接后重试'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -4,7 +4,15 @@
|
||||
<button class="compact-btn" bindtap="addEmployee">新增</button>
|
||||
</view>
|
||||
|
||||
<view class="list">
|
||||
<view wx:if="{{loadError}}" class="card error-card">
|
||||
<text class="error-title">数据加载失败</text>
|
||||
<text class="error-desc">{{errorMessage}}</text>
|
||||
<button class="compact-btn" bindtap="loadEmployees">重试</button>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{!employees.length}}" class="empty">暂无员工数据</view>
|
||||
|
||||
<view wx:else class="list">
|
||||
<view wx:for="{{employees}}" wx:key="id" class="card employee-card" data-id="{{item.id}}" bindtap="openDetail">
|
||||
<view class="employee-left">
|
||||
<view class="avatar" style="background: {{item.color}};">{{item.shortName}}</view>
|
||||
|
||||
Reference in New Issue
Block a user