完善小程序登录排班与个人资料流程
This commit is contained in:
@@ -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 : '')
|
||||
},
|
||||
|
||||
|
||||
@@ -68,6 +68,34 @@ async function run() {
|
||||
page.buildViewState({ artists: [], appointments: [], daySummaries: [] })
|
||||
assert.deepStrictEqual([monthBuilds, weekBuilds, dayBuilds], [0, 1, 0])
|
||||
|
||||
const closedWeekPage = createPage({ viewMode: 'week', currentDateText: '2026-10-12' })
|
||||
const closedWeek = Array.from({ length: 7 }, (_, index) => ({
|
||||
date: dateUtil.formatDate(dateUtil.addDays(dateUtil.startOfWeek(closedWeekPage.data.currentDateText), index)),
|
||||
shopOpen: false,
|
||||
shopStartTime: null,
|
||||
shopEndTime: null
|
||||
}))
|
||||
const closedWeekState = closedWeekPage.buildViewState({
|
||||
businessStartTime: '10:00',
|
||||
businessEndTime: '22:00',
|
||||
artists: [],
|
||||
appointments: [],
|
||||
daySummaries: closedWeek
|
||||
})
|
||||
assert.strictEqual(closedWeekState.businessHoursConfigured, false)
|
||||
assert.strictEqual(closedWeekState.weekDays.every(day => day.statusText === '休'), true)
|
||||
|
||||
const openWeekState = closedWeekPage.buildViewState({
|
||||
businessStartTime: '10:00',
|
||||
businessEndTime: '22:00',
|
||||
artists: [],
|
||||
appointments: [],
|
||||
daySummaries: closedWeek.map((day, index) => index === 2
|
||||
? { ...day, shopOpen: true, shopStartTime: '10:00', shopEndTime: '22:00' }
|
||||
: day)
|
||||
})
|
||||
assert.strictEqual(openWeekState.businessHoursConfigured, true)
|
||||
|
||||
page.data.viewMode = 'month'
|
||||
page.data.monthDisplayMode = 'count'
|
||||
const monthDays = definition.buildMonthDays.call(page, {
|
||||
@@ -117,6 +145,16 @@ async function run() {
|
||||
assert.strictEqual(missingHoursEmptyState.hours.length, 0)
|
||||
assert.strictEqual(missingHoursEmptyState.dayLanes.length, 0)
|
||||
assert.strictEqual(missingHoursEmptyState.hasTimedAppointments, false)
|
||||
const closedDaySummaryPage = createPage({ currentDateText: '2026-10-12' })
|
||||
const closedDayState = closedDaySummaryPage.buildViewState({
|
||||
businessStartTime: '10:00',
|
||||
businessEndTime: '22:00',
|
||||
artists: [],
|
||||
appointments: [],
|
||||
daySummaries: [{ date: '2026-10-12', shopOpen: false, shopStartTime: null, shopEndTime: null }]
|
||||
})
|
||||
assert.strictEqual(closedDayState.businessHoursConfigured, false)
|
||||
assert.strictEqual(closedDayState.currentShopOpen, false)
|
||||
missingHoursPage.clearCalendarView()
|
||||
assert.strictEqual(missingHoursPage.data.businessHoursText, '营业时间暂不可用')
|
||||
const missingHoursWithBookingState = missingHoursPage.buildDayView({
|
||||
@@ -156,7 +194,8 @@ async function run() {
|
||||
assert.match(planningWxml, /class="lane-unassigned-tag">不占档期/)
|
||||
assert.match(planningWxml, /门店营业时间未设置/)
|
||||
assert.match(planningWxml, /bindtap="openShopSettings"/)
|
||||
assert.match(planningWxml, /class="week-unassigned-count">待分配 \{\{item\.unassignedCount\}\}/)
|
||||
assert.match(planningWxml, /class="week-unassigned-count">待 \{\{item\.unassignedCount\}\}/)
|
||||
assert.match(planningWxml, /wx:if="\{\{canCreateAppointment && businessHoursConfigured && !calendarError && \(viewMode !== 'day' \|\| currentShopOpen\)\}\}" class="fab" bindtap="createAppointment"/)
|
||||
assert.match(planningWxml, /class="month-unassigned-count">待 \{\{item\.unassignedCount\}\}/)
|
||||
assert.doesNotMatch(planningWxss, /background-size:\s*100% 240rpx/)
|
||||
assert.match(planningWxss, /\.control-card\s*\{[^}]*padding:\s*8rpx 14rpx;/)
|
||||
@@ -239,9 +278,14 @@ async function run() {
|
||||
assert.strictEqual(navigations.pop(), '/pages/shop-settings/index')
|
||||
assert.strictEqual(unconfiguredPage._refreshCalendarOnShow, true)
|
||||
|
||||
const closedDayAppointmentPage = createPage({ viewMode: 'day', canCreateAppointment: true, businessHoursConfigured: true, currentShopOpen: false })
|
||||
closedDayAppointmentPage.createAppointment()
|
||||
assert.strictEqual(navigations.length, 0)
|
||||
assert.strictEqual(toasts.pop(), '该日期门店休息,不能新建普通预约')
|
||||
|
||||
assert.match(planningWxml, /bindtap="selectMonthDate" aria-label="查看\{\{item\.date\}\}日程"/)
|
||||
assert.match(planningWxml, /bindtap="selectWeekDate" aria-label="查看\{\{item\.date\}\}日程"/)
|
||||
assert.match(planningWxml, /class="fab" bindtap="createAppointment"/)
|
||||
assert.match(planningWxss, /grid-template-columns:\s*repeat\(7,\s*minmax\(0,\s*1fr\)\)/)
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
@@ -88,7 +88,11 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!businessHoursConfigured && !hasTimedAppointments}}" class="day-board card business-hours-empty">
|
||||
<view wx:if="{{shopClosed && !hasTimedAppointments}}" class="day-board card business-hours-empty">
|
||||
<text class="business-hours-empty-title">门店今日休息</text>
|
||||
<text class="business-hours-empty-desc">休息日不能创建普通预约,可通过历史补录记录已完成的服务。</text>
|
||||
</view>
|
||||
<view wx:elif="{{!businessHoursConfigured && !hasTimedAppointments}}" class="day-board card business-hours-empty">
|
||||
<text class="business-hours-empty-title">预约时间轴暂不可用</text>
|
||||
<text class="business-hours-empty-desc">请先设置门店营业时间,再安排普通预约。</text>
|
||||
</view>
|
||||
@@ -128,30 +132,16 @@
|
||||
</view>
|
||||
|
||||
<view wx:if="{{viewMode === 'week'}}" class="section">
|
||||
<scroll-view class="week-strip" scroll-x enable-flex>
|
||||
<view class="week-strip">
|
||||
<view wx:for="{{weekDays}}" wx:key="date" class="week-day-card card {{item.date === currentDateText ? 'active' : ''}}" data-date="{{item.date}}" bindtap="selectWeekDate" aria-label="查看{{item.date}}日程">
|
||||
<text class="week-name">{{item.weekName}}</text>
|
||||
<view class="week-card-head"><text class="week-name">{{item.weekName}}</text><text class="week-status {{item.statusText === '休' ? 'rest' : ''}}">{{item.statusText}}</text></view>
|
||||
<text class="week-date">{{item.day}}</text>
|
||||
<text class="week-total">{{item.totalCount}}单</text>
|
||||
<text wx:if="{{item.unassignedCount > 0}}" class="week-unassigned-count">待分配 {{item.unassignedCount}}</text>
|
||||
<text wx:if="{{item.unassignedCount > 0}}" class="week-unassigned-count">待 {{item.unassignedCount}}</text>
|
||||
<view class="week-bars {{item.totalCount === 0 ? 'empty' : ''}}">
|
||||
<view wx:for="{{item.artistCounts}}" wx:for-item="count" wx:key="artistId" class="week-bar" style="background: {{count.color}}; width: {{count.width}}%;"></view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<view class="card week-grid">
|
||||
<view class="week-grid-head">
|
||||
<text>本周排班密度</text>
|
||||
<text class="muted">{{weekRange}}</text>
|
||||
</view>
|
||||
<view wx:for="{{weekDays}}" wx:key="date" class="week-line">
|
||||
<view class="week-line-date">{{item.weekName}} {{item.day}}</view>
|
||||
<view class="week-line-bars {{item.totalCount === 0 ? 'empty' : ''}}">
|
||||
<view wx:for="{{item.artistCounts}}" wx:for-item="count" wx:key="artistId" class="week-count-bar" style="background: {{count.color}}; width: {{count.barWidth}}%;">
|
||||
<text>{{count.shortName}}{{count.count}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -206,5 +196,5 @@
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<button wx:if="{{canCreateAppointment && businessHoursConfigured && !calendarError}}" class="fab" bindtap="createAppointment">+</button>
|
||||
<button wx:if="{{canCreateAppointment && businessHoursConfigured && !calendarError && (viewMode !== 'day' || currentShopOpen)}}" class="fab" bindtap="createAppointment">+</button>
|
||||
</view>
|
||||
|
||||
@@ -556,17 +556,20 @@
|
||||
}
|
||||
|
||||
.week-strip {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, minmax(0, 1fr));
|
||||
gap: 6rpx;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.week-day-card {
|
||||
display: inline-flex;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 148rpx;
|
||||
min-height: 164rpx;
|
||||
margin-right: 12rpx;
|
||||
padding: 16rpx;
|
||||
min-width: 0;
|
||||
min-height: 104rpx;
|
||||
margin: 0;
|
||||
padding: 8rpx 4rpx;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.week-day-card.active {
|
||||
@@ -576,42 +579,47 @@
|
||||
.week-name,
|
||||
.week-total {
|
||||
color: #8f877e;
|
||||
font-size: 22rpx;
|
||||
font-size: 18rpx;
|
||||
}
|
||||
|
||||
.week-card-head { display:flex; width:100%; align-items:center; justify-content:space-between; gap:2rpx; }
|
||||
.week-status { color:#247b63; font-size:17rpx; font-weight:800; }
|
||||
.week-status.rest { color:#a08a78; }
|
||||
|
||||
.week-unassigned-count {
|
||||
display: inline-flex;
|
||||
align-self: flex-start;
|
||||
margin-top: 8rpx;
|
||||
padding: 4rpx 8rpx;
|
||||
margin-top: 4rpx;
|
||||
padding: 2rpx 4rpx;
|
||||
border-radius: 6rpx;
|
||||
background: #fff1dc;
|
||||
color: #a56b24;
|
||||
font-size: 18rpx;
|
||||
font-size: 15rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.week-date {
|
||||
margin: 8rpx 0;
|
||||
margin: 3rpx 0;
|
||||
color: #17211f;
|
||||
font-size: 38rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.week-bars {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6rpx;
|
||||
margin-top: 12rpx;
|
||||
min-height: 22rpx;
|
||||
gap: 3rpx;
|
||||
width: 90%;
|
||||
margin-top: 3rpx;
|
||||
min-height: 10rpx;
|
||||
}
|
||||
|
||||
.week-bars.empty {
|
||||
min-height: 22rpx;
|
||||
min-height: 10rpx;
|
||||
}
|
||||
|
||||
.week-bar {
|
||||
height: 8rpx;
|
||||
height: 5rpx;
|
||||
border-radius: 999rpx;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user