Files
JayuCloud/JC-Salon-WeChat/pages/profile/index.js
T

137 lines
4.5 KiB
JavaScript
Raw Normal View History

2026-06-24 22:13:00 +08:00
const { BRAND_CONFIG } = require('../../utils/config')
2026-06-27 15:19:32 +08:00
const auth = require('../../utils/auth')
const planningApi = require('../../api/planning')
const { buildProfileCard } = require('../../utils/profile-card')
2026-10-11 16:53:02 +08:00
const profileCache = require('../../utils/profile-cache')
2026-06-24 22:13:00 +08:00
2026-06-27 01:46:44 +08:00
function resolveRoleText(type) {
const role = Number(type)
if (role === 2) return '店长'
if (role === 3) return '美甲师'
if (role === 4) return '管理员'
return '管理端'
}
2026-06-04 16:39:06 +08:00
Page({
data: {
2026-06-27 01:46:44 +08:00
roleText: '管理端',
profileCard: buildProfileCard({}, BRAND_CONFIG.defaultShopName),
overviewLoading: false,
overview: {
date: '',
todayAppointments: 0,
pendingAppointments: 0,
upcomingAppointments: 0,
availableEmployees: 0,
scheduleExceptions: 0,
shopOpen: true,
shopStatus: '营业中'
},
2026-06-04 16:39:06 +08:00
menus: [
2026-10-10 17:32:26 +08:00
{ title: '个人信息', url: '/pages/profile-edit/index' },
{ title: '账号设置', url: '/pages/account-settings/index' },
2026-06-04 16:39:06 +08:00
{ title: '店铺设置', url: '/pages/shop-settings/index' },
{ title: '数据导出', url: '/pages/export/index' },
2026-10-22 00:27:12 +08:00
{ title: '用户协议', url: '/pages/legal/index?type=USER_TERMS' },
{ title: '隐私政策', url: '/pages/legal/index?type=PRIVACY_POLICY' },
2026-06-04 16:39:06 +08:00
{ title: '关于系统', url: '/pages/about/index' }
]
},
onShow() {
2026-06-27 15:19:32 +08:00
this.refreshFromSession()
this.loadProfile()
this.loadOverview()
},
async loadOverview() {
this.setData({ overviewLoading: true })
try {
2026-10-11 16:53:02 +08:00
const overview = await planningApi.todayOverview()
this.setData({
overview: {
2026-10-11 16:53:02 +08:00
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) {
wx.showToast({ title: error.message || '今日概览加载失败', icon: 'none' })
} finally {
this.setData({ overviewLoading: false })
}
},
goOverviewAction(event) {
const action = event.currentTarget.dataset.action
if (action === 'scheduleExceptions') {
wx.navigateTo({ url: '/pages/leave-management/index' })
return
}
wx.switchTab({ url: '/pages/planning/index' })
2026-06-27 15:19:32 +08:00
},
refreshFromSession() {
2026-06-04 16:39:06 +08:00
const app = getApp()
2026-06-27 01:46:44 +08:00
const userInfo = app.globalData.userInfo || {}
const fallbackShopName = app.globalData.shopName || BRAND_CONFIG.defaultShopName
2026-06-04 16:39:06 +08:00
this.setData({
2026-06-27 15:19:32 +08:00
roleText: resolveRoleText(userInfo.type),
profileCard: buildProfileCard(userInfo, fallbackShopName)
2026-06-04 16:39:06 +08:00
})
},
go(event) {
wx.navigateTo({ url: event.currentTarget.dataset.url })
2026-06-27 15:19:32 +08:00
},
2026-11-01 00:41:51 +08:00
onProfileAvatarError() {
this.setData({ 'profileCard.avatar': '' })
},
2026-06-27 15:19:32 +08:00
async loadProfile() {
try {
2026-10-11 16:53:02 +08:00
const profile = await profileCache.getProfile()
2026-06-27 15:19:32 +08:00
this.syncProfileToSession(profile)
} catch (error) {
wx.showToast({ title: error.message || '个人信息加载失败', icon: 'none' })
}
},
syncProfileToSession(profile) {
const app = getApp()
const session = auth.getSession()
const currentUserInfo = session.userInfo || app.globalData.userInfo || {}
const nextUserInfo = {
...currentUserInfo,
id: profile.id || currentUserInfo.id,
account: profile.account || currentUserInfo.account,
nickname: profile.nickname || '',
avatar: profile.avatar || '',
phone: profile.phone || currentUserInfo.phone || '',
phoneVerified: profile.phoneVerified,
maskedPhone: profile.maskedPhone || '',
2026-06-27 15:19:32 +08:00
contactPhone: profile.contactPhone || '',
wechatId: profile.wechatId || '',
signature: profile.signature || '',
type: profile.type || currentUserInfo.type,
shopId: profile.shopId || currentUserInfo.shopId,
shopName: profile.shopName || currentUserInfo.shopName || session.shopName || app.globalData.shopName || ''
2026-06-27 15:19:32 +08:00
}
app.setSession({
...session,
shopName: nextUserInfo.shopName || session.shopName,
2026-06-27 15:19:32 +08:00
userInfo: nextUserInfo
})
this.setData({
roleText: resolveRoleText(nextUserInfo.type),
profileCard: buildProfileCard(nextUserInfo, BRAND_CONFIG.defaultShopName)
2026-06-27 15:19:32 +08:00
})
2026-06-04 16:39:06 +08:00
}
})