优化店务小程序个人中心界面
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const { BRAND_CONFIG } = require('../../utils/config')
|
||||
const userApi = require('../../api/user')
|
||||
const shopApi = require('../../api/shop')
|
||||
const dashboardApi = require('../../api/dashboard')
|
||||
const authApi = require('../../api/auth')
|
||||
const auth = require('../../utils/auth')
|
||||
|
||||
@@ -34,21 +35,74 @@ function resolveShopCoverImage(settings) {
|
||||
return String(settings.coverImageUrls[0] || '').trim()
|
||||
}
|
||||
|
||||
function formatCount(value) {
|
||||
const count = Number(value)
|
||||
if (!Number.isFinite(count)) return '--'
|
||||
return String(Math.max(0, Math.trunc(count)))
|
||||
}
|
||||
|
||||
function formatMoney(value) {
|
||||
const amount = Number(value)
|
||||
if (!Number.isFinite(amount)) return '--'
|
||||
return `¥${amount.toFixed(2).replace(/\.00$/, '')}`
|
||||
}
|
||||
|
||||
function resolveTodayAppointments(stats) {
|
||||
return stats.todayAppointments || stats.todayAppointmentCount || stats.todayServiceCount || stats.todayServices || stats.todayOrders
|
||||
}
|
||||
|
||||
function buildDashboardStats(stats) {
|
||||
const data = stats || {}
|
||||
return [
|
||||
{ mark: '今', label: '今日预约', value: formatCount(resolveTodayAppointments(data)), unit: '单' },
|
||||
{ mark: '单', label: '今日订单', value: formatCount(data.todayOrders), unit: '单' },
|
||||
{ mark: '¥', label: '今日收入', value: formatMoney(data.todayOrderAmount), unit: '' }
|
||||
]
|
||||
}
|
||||
|
||||
function resolveBusinessStatus(settings) {
|
||||
if (Number(settings.status) === 0) {
|
||||
return { text: '已停用', className: 'closed' }
|
||||
}
|
||||
if (settings.authorizationExpired) {
|
||||
return { text: '授权到期', className: 'warning' }
|
||||
}
|
||||
return { text: '营业中', className: 'open' }
|
||||
}
|
||||
|
||||
function resolveBusinessHours(settings) {
|
||||
const businessHours = String(settings.businessHours || '').trim()
|
||||
if (businessHours) return `今日营业 ${businessHours}`
|
||||
const startTime = String(settings.startTime || '').slice(0, 5)
|
||||
const endTime = String(settings.endTime || '').slice(0, 5)
|
||||
if (startTime && endTime) return `今日营业 ${startTime} - ${endTime}`
|
||||
return '营业时间未设置'
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
shopName: BRAND_CONFIG.defaultShopName,
|
||||
shopCoverImage: '',
|
||||
phone: '店长端',
|
||||
roleText: '管理端',
|
||||
businessStatusText: '营业中',
|
||||
businessStatusClass: 'open',
|
||||
businessHoursText: '营业时间未设置',
|
||||
dashboardStats: buildDashboardStats({}),
|
||||
userInfo: {},
|
||||
loggingOut: false,
|
||||
menus: [
|
||||
{ title: '个人信息', url: '/pages/profile-settings/index' },
|
||||
{ title: '店铺设置', url: '/pages/shop-settings/index' },
|
||||
{ title: '数据导出', url: '/pages/export/index' },
|
||||
{ title: '修改密码', url: '/pages/password/index' },
|
||||
{ title: '关于系统', url: '/pages/about/index' },
|
||||
{ title: '退出登录', action: 'logout', danger: true }
|
||||
managementMenus: [
|
||||
{ mark: '店', title: '我的店铺', desc: '店铺信息、营业设置等', url: '/pages/shop-settings/index' },
|
||||
{ mark: '员', title: '员工管理', desc: '员工信息、排班与权限', url: '/pages/employees/index' },
|
||||
{ mark: '会', title: '会员管理', desc: '客户管理、会员等级', url: '/pages/customers/index' },
|
||||
{ mark: '数', title: '经营数据', desc: '营业统计、数据导出', url: '/pages/export/index' }
|
||||
],
|
||||
settingMenus: [
|
||||
{ mark: '人', title: '个人资料', desc: '头像、昵称、联系方式等', url: '/pages/profile-settings/index' },
|
||||
{ mark: '安', title: '账号与安全', desc: '修改密码、绑定手机号等', url: '/pages/password/index' },
|
||||
{ mark: '知', title: '消息通知', desc: '系统通知与消息偏好', url: '', disabled: true },
|
||||
{ mark: '?', title: '帮助中心', desc: '使用帮助与常见问题', url: '/pages/about/index' },
|
||||
{ mark: '关', title: '关于甲屿店务', desc: '当前版本 1.2.0', url: '/pages/about/index' }
|
||||
]
|
||||
},
|
||||
|
||||
@@ -56,6 +110,7 @@ Page({
|
||||
this.refreshFromSession()
|
||||
this.loadShopHeader()
|
||||
this.loadProfile()
|
||||
this.loadDashboardStats()
|
||||
},
|
||||
|
||||
refreshFromSession() {
|
||||
@@ -80,24 +135,43 @@ Page({
|
||||
const app = getApp()
|
||||
const shopName = settings.shopName || settings.name || app.globalData.shopName || BRAND_CONFIG.appName
|
||||
const shopCoverImage = resolveShopCoverImage(settings)
|
||||
const status = resolveBusinessStatus(settings || {})
|
||||
app.globalData.shopName = shopName
|
||||
app.globalData.shopCoverImage = shopCoverImage
|
||||
this.setData({
|
||||
shopName,
|
||||
shopCoverImage
|
||||
shopCoverImage,
|
||||
businessStatusText: status.text,
|
||||
businessStatusClass: status.className,
|
||||
businessHoursText: resolveBusinessHours(settings || {})
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '店铺信息加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
async loadDashboardStats() {
|
||||
try {
|
||||
const stats = await dashboardApi.stats()
|
||||
this.setData({ dashboardStats: buildDashboardStats(stats || {}) })
|
||||
} catch (error) {
|
||||
this.setData({ dashboardStats: buildDashboardStats({}) })
|
||||
wx.showToast({ title: error.message || '经营数据加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
go(event) {
|
||||
const action = event.currentTarget.dataset.action
|
||||
if (action === 'logout') {
|
||||
this.confirmLogout()
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: event.currentTarget.dataset.url })
|
||||
const url = event.currentTarget.dataset.url
|
||||
if (!url) {
|
||||
wx.showToast({ title: '功能即将开放', icon: 'none' })
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url })
|
||||
},
|
||||
|
||||
confirmLogout() {
|
||||
|
||||
Reference in New Issue
Block a user