完善小程序登录排班与个人资料流程

This commit is contained in:
2026-11-03 15:33:03 +08:00
parent 6aafbd4eac
commit 19e2cd2594
37 changed files with 779 additions and 195 deletions
+47 -15
View File
@@ -26,6 +26,27 @@ function resolveBusinessHours(value) {
return { start, end }
}
const WEEKDAYS = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
function normalizeWeeklyHours(weeklyHours, legacyHours) {
const legacy = resolveBusinessHours(legacyHours) || { start: '10:00', end: '22:00' }
const source = Array.isArray(weeklyHours) && weeklyHours.length === 7
? weeklyHours
: WEEKDAYS.map((_, index) => ({ dayOfWeek: index + 1, open: true, startTime: legacy.start, endTime: legacy.end }))
const byDay = new Map(source.map(item => [Number(item.dayOfWeek), item]))
return WEEKDAYS.map((dayName, index) => {
const day = byDay.get(index + 1) || {}
const open = day.open !== false
return {
dayOfWeek: index + 1,
dayName,
open,
startTime: resolveBusinessHours(`${day.startTime || legacy.start}-${day.endTime || legacy.end}`)?.start || legacy.start,
endTime: resolveBusinessHours(`${day.startTime || legacy.start}-${day.endTime || legacy.end}`)?.end || legacy.end
}
})
}
Page({
data: {
profile: {},
@@ -37,7 +58,7 @@ Page({
businessHoursConfigured: false,
nameSaving: false,
settingsError: '',
form: { shopName: BRAND_CONFIG.defaultShopName, pendingShopName: '', startTime: '', endTime: '', defaultDuration: 60 }
form: { shopName: BRAND_CONFIG.defaultShopName, pendingShopName: '', weeklyHours: normalizeWeeklyHours(), defaultDuration: 60 }
},
onShow() { this.loadProfileAndSettings() },
@@ -57,10 +78,10 @@ Page({
: hasRemainingDays
? `剩余 ${remainingDays} 天`
: '有效期未设置'
const businessHours = resolveBusinessHours(settings.businessHours)
const weeklyHours = normalizeWeeklyHours(settings.weeklyHours, settings.businessHours)
this.setData({
profile,
businessHoursConfigured: Boolean(businessHours),
businessHoursConfigured: weeklyHours.some(day => day.open),
businessExpireDateText,
businessExpiryStatusText,
nameModerationText: resolveNameStatus(settings.shopNameModerationStatus),
@@ -68,8 +89,7 @@ Page({
...this.data.form,
shopName: settings.pendingShopName || settings.shopName || profile.shopName || BRAND_CONFIG.defaultShopName,
pendingShopName: settings.pendingShopName || '',
startTime: businessHours ? businessHours.start : '',
endTime: businessHours ? businessHours.end : '',
weeklyHours,
defaultDuration: Number(settings.defaultAppointmentDurationMinutes) || 60
}
})
@@ -77,8 +97,7 @@ Page({
this.setData({
settingsError: error.message || '设置加载失败',
businessHoursConfigured: false,
'form.startTime': '',
'form.endTime': ''
'form.weeklyHours': []
})
} finally {
this.setData({ settingsLoading: false })
@@ -86,15 +105,25 @@ Page({
},
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
onStartChange(event) { this.setData({ 'form.startTime': event.detail.value }) },
onEndChange(event) { this.setData({ 'form.endTime': event.detail.value }) },
toggleBusinessDay(event) {
const index = Number(event.currentTarget.dataset.index)
const weeklyHours = (this.data.form.weeklyHours || []).map((item, itemIndex) => itemIndex === index ? { ...item, open: Boolean(event.detail.value) } : item)
this.setData({ 'form.weeklyHours': weeklyHours })
},
changeBusinessTime(event) {
const index = Number(event.currentTarget.dataset.index)
const field = event.currentTarget.dataset.field
const weeklyHours = (this.data.form.weeklyHours || []).map((item, itemIndex) => itemIndex === index ? { ...item, [field]: event.detail.value } : item)
this.setData({ 'form.weeklyHours': weeklyHours })
},
async saveAppointmentSettings() {
const { startTime, endTime, defaultDuration } = this.data.form
const { weeklyHours, defaultDuration } = this.data.form
const duration = Number(defaultDuration)
const businessHours = resolveBusinessHours(`${startTime}-${endTime}`)
if (!businessHours) {
wx.showToast({ title: '请设置完整有效的营业时间', icon: 'none' })
const normalizedHours = normalizeWeeklyHours(weeklyHours)
if (normalizedHours.some(day => day.open && !resolveBusinessHours(`${day.startTime}-${day.endTime}`))) {
wx.showToast({ title: '请检查营业日的开始和结束时间', icon: 'none' })
return
}
if (!Number.isInteger(duration) || duration < 15 || duration > 720) {
@@ -103,8 +132,11 @@ Page({
}
this.setData({ settingsSaving: true })
try {
await shopApi.saveAppointmentSettings({ businessHours: `${businessHours.start}-${businessHours.end}`, defaultAppointmentDurationMinutes: duration })
this.setData({ businessHoursConfigured: true })
await shopApi.saveAppointmentSettings({
weeklyHours: normalizedHours.map(({ dayOfWeek, open, startTime, endTime }) => ({ dayOfWeek, open, startTime: open ? startTime : null, endTime: open ? endTime : null })),
defaultAppointmentDurationMinutes: duration
})
this.setData({ businessHoursConfigured: normalizedHours.some(day => day.open) })
wx.showToast({ title: '预约设置已生效', icon: 'success' })
} catch (error) {
wx.showToast({ title: error.message || '保存失败,请重试', icon: 'none' })