优化:提升小程序全链路性能
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
const { BRAND_CONFIG } = require('../../utils/config')
|
||||
const userApi = require('../../api/user')
|
||||
const auth = require('../../utils/auth')
|
||||
const planningApi = require('../../api/planning')
|
||||
const employeesApi = require('../../api/employees')
|
||||
const shopApi = require('../../api/shop')
|
||||
const dateUtil = require('../../utils/date')
|
||||
const { buildProfileCard } = require('../../utils/profile-card')
|
||||
const profileCache = require('../../utils/profile-cache')
|
||||
|
||||
function resolveRoleText(type) {
|
||||
const role = Number(type)
|
||||
@@ -46,36 +43,19 @@ Page({
|
||||
},
|
||||
|
||||
async loadOverview() {
|
||||
const today = dateUtil.formatDate(new Date())
|
||||
this.setData({ overviewLoading: true })
|
||||
try {
|
||||
const [calendar, shop] = await Promise.all([
|
||||
planningApi.calendar({ startDate: today, endDate: today }),
|
||||
shopApi.settings()
|
||||
])
|
||||
const appointments = Array.isArray(calendar.appointments) ? calendar.appointments : []
|
||||
const now = Date.now()
|
||||
const upcomingAppointments = appointments.filter(item => {
|
||||
const appointmentTime = new Date(String(item.appointmentTime || item.startTime || '').replace(/-/g, '/')).getTime()
|
||||
return Number.isFinite(appointmentTime) && appointmentTime >= now
|
||||
}).length
|
||||
const artists = Array.isArray(calendar.artists) ? calendar.artists : []
|
||||
const scheduleRules = await Promise.all(artists.map(artist => employeesApi.scheduleRule({ artistId: artist.id })))
|
||||
const scheduleExceptions = scheduleRules.reduce((total, setting) => {
|
||||
const exceptions = Array.isArray(setting && setting.exceptions) ? setting.exceptions : []
|
||||
return total + exceptions.filter(item => item.workDate === today).length
|
||||
}, 0)
|
||||
const shopOpen = Number(shop && shop.status) !== 0
|
||||
const overview = await planningApi.todayOverview()
|
||||
this.setData({
|
||||
overview: {
|
||||
date: `${today.slice(5, 7)}月${today.slice(8, 10)}日`,
|
||||
todayAppointments: appointments.length,
|
||||
pendingAppointments: appointments.filter(item => Number(item.status) === 0).length,
|
||||
upcomingAppointments,
|
||||
availableEmployees: artists.filter(item => Number(item.status) !== 0).length,
|
||||
scheduleExceptions,
|
||||
shopOpen,
|
||||
shopStatus: shopOpen ? '营业中' : '已暂停'
|
||||
date: overview.date || '',
|
||||
todayAppointments: Number(overview.todayAppointments || 0),
|
||||
pendingAppointments: Number(overview.pendingAppointments || 0),
|
||||
upcomingAppointments: Number(overview.upcomingAppointments || 0),
|
||||
availableEmployees: Number(overview.availableEmployees || 0),
|
||||
scheduleExceptions: Number(overview.scheduleExceptions || 0),
|
||||
shopOpen: overview.shopOpen !== false,
|
||||
shopStatus: overview.shopStatus || (overview.shopOpen === false ? '已暂停' : '营业中')
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
@@ -110,7 +90,7 @@ Page({
|
||||
|
||||
async loadProfile() {
|
||||
try {
|
||||
const profile = await userApi.info()
|
||||
const profile = await profileCache.getProfile()
|
||||
this.syncProfileToSession(profile)
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '个人信息加载失败', icon: 'none' })
|
||||
|
||||
Reference in New Issue
Block a user