修复回归安全问题并补充验证
This commit is contained in:
@@ -1,26 +1,62 @@
|
||||
const employeesApi = require('../../api/employees')
|
||||
const config = require('../../utils/config')
|
||||
const mock = require('../../utils/mock')
|
||||
|
||||
const normalizeEmployee = (item = {}) => ({
|
||||
id: item.userId || item.id,
|
||||
name: item.nickname || item.name || item.artistName || '美甲师',
|
||||
shortName: (item.nickname || item.name || item.artistName || '师').slice(-1),
|
||||
color: item.color || '#7BA7C7',
|
||||
monthOrders: item.monthOrders || item.orderCount || 0,
|
||||
monthAmount: item.monthAmount || item.turnover || 0,
|
||||
avgAmount: item.avgAmount || item.averageAmount || 0
|
||||
})
|
||||
|
||||
Page({
|
||||
data: {
|
||||
id: '',
|
||||
employee: {}
|
||||
employee: {},
|
||||
loadError: false,
|
||||
errorMessage: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const id = options.id || mock.artists[0].id
|
||||
const artist = mock.artists.find(item => String(item.id) === String(id)) || mock.artists[0]
|
||||
this.setData({
|
||||
id,
|
||||
employee: {
|
||||
...artist,
|
||||
monthOrders: 32,
|
||||
monthAmount: 5800,
|
||||
avgAmount: 181
|
||||
onLoad(options = {}) {
|
||||
const id = options.id || ''
|
||||
this.setData({ id })
|
||||
this.loadEmployee()
|
||||
},
|
||||
|
||||
async loadEmployee() {
|
||||
this.setData({ loadError: false, errorMessage: '' })
|
||||
try {
|
||||
const employee = await employeesApi.detail(this.data.id)
|
||||
this.setData({ employee: normalizeEmployee(employee) })
|
||||
} catch (error) {
|
||||
if (config.USE_DEV_MOCK_DATA) {
|
||||
const artist = mock.artists.find(item => String(item.id) === String(this.data.id)) || mock.artists[0]
|
||||
this.setData({
|
||||
employee: normalizeEmployee({
|
||||
...artist,
|
||||
monthOrders: 32,
|
||||
monthAmount: 5800,
|
||||
avgAmount: 181
|
||||
})
|
||||
})
|
||||
} else {
|
||||
this.setData({
|
||||
employee: {},
|
||||
loadError: true,
|
||||
errorMessage: error.message || '员工详情加载失败,请检查服务连接后重试'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
go(event) {
|
||||
if (this.data.loadError) {
|
||||
wx.showToast({ title: '请先重新加载员工详情', icon: 'none' })
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: `${event.currentTarget.dataset.url}?id=${this.data.id}` })
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user