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

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
+70 -23
View File
@@ -47,22 +47,38 @@ function resolveAppointmentTimeText(item) {
return `${startText}-${endText}`
}
function resolveBusinessHours(calendar = {}) {
const parts = String(calendar.businessHours || '').split('-')
const normalizeTime = value => {
const match = /^(\d{1,2}):(\d{2})(?::\d{2})?$/.exec(String(value || '').trim())
if (!match) return ''
const hour = Number(match[1])
const minute = Number(match[2])
if (hour > 23 || minute > 59) return ''
return `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`
function normalizeTime(value) {
const match = /^(\d{1,2}):(\d{2})(?::\d{2})?$/.exec(String(value || '').trim())
if (!match) return ''
const hour = Number(match[1])
const minute = Number(match[2])
if (hour > 23 || minute > 59) return ''
return `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`
}
function resolveBusinessHours(calendar = {}, targetDate) {
const day = targetDate && (calendar.daySummaries || []).find(item => item.date === targetDate)
if (day) {
if (day.shopOpen === false) return null
const dayStart = normalizeTime(day.shopStartTime)
const dayEnd = normalizeTime(day.shopEndTime)
if (dayStart && dayEnd && dateUtil.minutesOfDay(dayEnd) > dateUtil.minutesOfDay(dayStart)) return { start: dayStart, end: dayEnd }
}
const parts = String(calendar.businessHours || '').split('-')
const start = normalizeTime(calendar.businessStartTime || parts[0])
const end = normalizeTime(calendar.businessEndTime || parts[1])
if (!start || !end || dateUtil.minutesOfDay(end) <= dateUtil.minutesOfDay(start)) return null
return { start, end }
}
function hasBusinessHours(calendar = {}) {
const summaries = Array.isArray(calendar.daySummaries) ? calendar.daySummaries : []
if (summaries.length) {
return summaries.some(day => day.shopOpen !== false && Boolean(resolveBusinessHours(calendar, day.date)))
}
return Boolean(resolveBusinessHours(calendar))
}
function layoutAppointmentBlocks(items, startMinute, minuteScale, laneHeaderHeight, defaultLaneWidth) {
const entries = (items || [])
.filter(item => item.startTime)
@@ -168,7 +184,7 @@ Page({
phoneBannerVisible: false,
profilePromptVisible: false,
profileSaving: false,
profileForm: { nickname: '', avatar: '' }
profileForm: { nickname: '', avatar: '', avatarFileId: '' }
},
onLoad() {
@@ -211,7 +227,7 @@ Page({
this.setData({
phoneBannerVisible: Number(profile.phoneVerified) !== 1 && dismissed !== today,
profilePromptVisible: false,
profileForm: { nickname: missingNickname ? '' : profile.nickname, avatar }
profileForm: { nickname: missingNickname ? '' : profile.nickname, avatar, avatarFileId: '' }
})
} catch (error) {
// 资料提醒失败不影响日程数据。
@@ -264,8 +280,11 @@ Page({
if (!filePath) return
this.setData({ profileSaving: true })
try {
const avatar = await uploadProfileImage(filePath)
this.setData({ 'profileForm.avatar': avatar })
const uploaded = await uploadProfileImage(filePath)
this.setData({
'profileForm.avatar': filePath,
'profileForm.avatarFileId': uploaded && uploaded.fileId ? String(uploaded.fileId) : ''
})
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
} finally {
@@ -285,12 +304,15 @@ Page({
}
this.setData({ profileSaving: true })
try {
await userApi.updateInfo({ nickname, avatar: this.data.profileForm.avatar })
await userApi.updateInfo({
nickname,
avatarFileId: this.data.profileForm.avatarFileId || undefined
})
profileCache.invalidate()
this.setData({ profilePromptVisible: false })
wx.showToast({ title: '资料已保存' })
wx.showToast({ title: '资料已保存', duration: 3000 })
} catch (error) {
wx.showToast({ title: error.message || '资料保存失败', icon: 'none' })
wx.showToast({ title: error.message || '资料保存失败', icon: 'none', duration: 3000 })
} finally {
this.setData({ profileSaving: false })
}
@@ -457,7 +479,7 @@ Page({
const snapshot = {
businessStartTime: businessHours ? businessHours.start : '',
businessEndTime: businessHours ? businessHours.end : '',
businessHoursConfigured: Boolean(businessHours),
businessHoursConfigured: hasBusinessHours(calendar),
artists: Array.isArray(calendar.artists) ? calendar.artists : [],
appointments: Array.isArray(calendar.appointments) ? calendar.appointments : [],
daySummaries: Array.isArray(calendar.daySummaries) ? calendar.daySummaries : []
@@ -467,9 +489,6 @@ Page({
businessStartTime: snapshot.businessStartTime,
businessEndTime: snapshot.businessEndTime,
businessHoursConfigured: snapshot.businessHoursConfigured,
businessHoursText: snapshot.businessHoursConfigured
? `${snapshot.businessStartTime}-${snapshot.businessEndTime}`
: '营业时间未设置',
artists: snapshot.artists,
calendarError: '',
rangeUnassignedCount: snapshot.appointments.filter(item => !item.artistId).length,
@@ -494,12 +513,20 @@ Page({
dateTitle: title,
rangeText: this.data.viewMode === 'month' ? '月视图' : this.data.viewMode === 'week' ? '周视图' : '日视图',
weekRange: `${formatMonthDay(range.start)} - ${formatMonthDay(range.end)}`,
businessHoursConfigured: Boolean(resolveBusinessHours(calendar)),
businessHoursConfigured: hasBusinessHours(calendar),
currentShopOpen: true,
businessHoursText: '营业时间暂不可用',
monthDays: [],
weekDays: [],
dayLanes: [],
hours: []
}
const daySummary = this.summaryMap(calendar)[current]
const dailyHours = resolveBusinessHours(calendar, current)
state.currentShopOpen = !daySummary || daySummary.shopOpen !== false
state.businessHoursText = !state.currentShopOpen
? '门店休息'
: dailyHours ? `${dailyHours.start}-${dailyHours.end}` : '营业时间暂不可用'
if (this.data.viewMode === 'month') {
state.monthDays = this.buildMonthDays(calendar)
return state
@@ -534,7 +561,7 @@ Page({
isPast: day.date < todayText,
totalCount: summary.totalCount || 0,
unassignedCount,
dayStatus: summary.dayStatus || 'free',
dayStatus: this.resolveDisplayStatus(summary, artistCounts),
artistCounts,
expandedBlocks: this.data.monthDisplayMode === 'blocks' ? this.buildExpandedBlocks(artistCounts) : [],
rowBlocks: this.data.monthDisplayMode === 'rows' ? this.buildRowBlocks(artistCounts) : []
@@ -560,6 +587,10 @@ Page({
day: target.getDate(),
totalCount: summary.totalCount || 0,
unassignedCount,
shopOpen: summary.shopOpen !== false,
statusText: this.resolveDisplayStatus(summary, artistCounts) === 'rest'
? '休'
: this.resolveDisplayStatus(summary, artistCounts) === 'full' ? '满' : '营业',
artistCounts: artistCounts.map(count => ({
...count,
width: Math.max(12, Math.min(100, count.count * 22)),
@@ -571,7 +602,8 @@ Page({
buildDayView(calendar) {
const minuteScale = 4
const businessHours = resolveBusinessHours(calendar)
const daySummary = this.summaryMap(calendar)[this.data.currentDateText] || null
const businessHours = resolveBusinessHours(calendar, this.data.currentDateText)
const filteredArtists = this.data.selectedArtistId
? (calendar.artists || []).filter(item => String(item.id) === String(this.data.selectedArtistId))
: (calendar.artists || [])
@@ -597,6 +629,7 @@ Page({
freeArtistCount: 0,
pendingCount,
unassignedCount: dayAppointments.filter(item => !item.artistId).length,
shopClosed: Boolean(daySummary && daySummary.shopOpen === false),
historicalBackfillItems
}
}
@@ -670,10 +703,20 @@ Page({
freeArtistCount: employeeLanes.filter(item => item.blocks.every(block => block.historicalBackfill)).length,
pendingCount,
unassignedCount: unassignedBlocks.length,
shopClosed: Boolean(daySummary && daySummary.shopOpen === false),
historicalBackfillItems
}
},
resolveDisplayStatus(summary = {}, artistCounts = []) {
if (summary.shopOpen === false || summary.dayStatus === 'rest') return 'rest'
if (this.data.selectedArtistId) {
const selected = artistCounts.find(item => String(item.artistId) === String(this.data.selectedArtistId))
return selected ? selected.status : 'rest'
}
return summary.dayStatus === 'full' ? 'full' : 'working'
},
withUnassignedCount(artistCounts, unassignedCount) {
if (!unassignedCount) return artistCounts
return [{
@@ -771,6 +814,10 @@ Page({
wx.showToast({ title: '请先在店铺设置中配置营业时间', icon: 'none' })
return
}
if (this.data.viewMode === 'day' && this.data.currentShopOpen === false) {
wx.showToast({ title: '该日期门店休息,不能新建普通预约', icon: 'none' })
return
}
this.openAppointmentForm(this.data.viewMode === 'day' ? this.data.currentDateText : '')
},