功能:支持待分配预约与首次排班引导

This commit is contained in:
2026-10-12 23:52:20 +08:00
parent 59608ef57f
commit 3ab615ccd4
26 changed files with 816 additions and 82 deletions
+52 -5
View File
@@ -6,6 +6,9 @@ const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123'
Page({
data: {
pickerMode: false,
appointmentContext: { date: '', time: '', durationMinutes: '' },
onboardingVisible: false,
createdEmployee: null,
form: {
nickname: '',
phone: '',
@@ -20,7 +23,14 @@ Page({
},
onLoad(options) {
this.setData({ pickerMode: options && options.picker === '1' })
this.setData({
pickerMode: options && options.picker === '1',
appointmentContext: {
date: options.date || '',
time: options.time || '',
durationMinutes: options.durationMinutes || ''
}
})
},
onInput(event) {
@@ -54,6 +64,9 @@ Page({
this.setData({ 'form.avatar': '', 'form.avatarUrl': '' })
},
stopTouchMove() {
},
async submit() {
const form = this.data.form
const nickname = String(form.nickname || '').trim()
@@ -83,14 +96,48 @@ Page({
})
const id = result && typeof result === 'object' ? (result.id || result.userId) : result
const employee = { id, name: nickname, title: nickname, avatar: form.avatar || '' }
const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel()
if (eventChannel && eventChannel.emit) eventChannel.emit('employeeCreated', employee)
wx.showToast({ title: '员工已新增', icon: 'success' })
setTimeout(() => wx.navigateBack(), 450)
this.setData({ createdEmployee: employee, onboardingVisible: true })
} catch (error) {
wx.showToast({ title: error.message || '新增失败', icon: 'none' })
} finally {
this.setData({ creating: false })
}
},
setupFirstSchedule() {
const employee = this.data.createdEmployee
if (!employee || !employee.id) return
const context = this.data.appointmentContext
const query = [
`id=${encodeURIComponent(employee.id)}`,
'onboarding=1',
`source=${this.data.pickerMode ? 'appointment' : 'employees'}`,
`date=${encodeURIComponent(context.date || '')}`,
`time=${encodeURIComponent(context.time || '')}`,
`durationMinutes=${encodeURIComponent(context.durationMinutes || '')}`
]
wx.navigateTo({
url: `/pages/schedule-setting/index?${query.join('&')}`,
success: result => {
result.eventChannel.on('scheduleSaved', () => {
setTimeout(() => this.finishCreated(true, true), 250)
})
}
})
},
skipFirstSchedule() {
this.finishCreated(!this.data.pickerMode, false)
},
finishCreated(autoSelect, scheduleSaved) {
const employee = this.data.createdEmployee
const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel()
if (eventChannel && eventChannel.emit) {
eventChannel.emit('employeeCreated', { ...employee, autoSelect, scheduleSaved })
}
this.setData({ onboardingVisible: false })
wx.showToast({ title: scheduleSaved ? '排班已保存' : '员工已新增', icon: 'success' })
setTimeout(() => wx.navigateBack(), 300)
}
})
@@ -2,11 +2,13 @@ const assert = require('assert')
const employeesApi = require('../../api/employees')
let navigatedBack = false
let navigatedTo = ''
global.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
showToast: () => {},
navigateBack: () => { navigatedBack = true }
navigateBack: () => { navigatedBack = true },
navigateTo: options => { navigatedTo = options.url }
}
global.setTimeout = callback => { callback(); return 1 }
@@ -41,9 +43,19 @@ async function run() {
})
employeesApi.createUser = async () => 88
await page.submit()
assert.strictEqual(page.data.onboardingVisible, true)
assert.strictEqual(emitted, undefined)
page.data.pickerMode = true
page.skipFirstSchedule()
assert.strictEqual(emitted.name, 'employeeCreated')
assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '' })
assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '', autoSelect: false, scheduleSaved: false })
assert.strictEqual(navigatedBack, true)
page.data.onboardingVisible = true
page.data.createdEmployee = { id: 88, name: '小周' }
page.data.appointmentContext = { date: '2026-10-12', time: '14:00', durationMinutes: '60' }
page.setupFirstSchedule()
assert.strictEqual(navigatedTo.includes('/pages/schedule-setting/index?id=88&onboarding=1&source=appointment'), true)
}
run().catch(error => {
@@ -41,4 +41,14 @@
<view class="fixed-bottom">
<button class="primary-btn" loading="{{creating}}" disabled="{{avatarUploading || creating}}" bindtap="submit">保存员工</button>
</view>
<view wx:if="{{onboardingVisible}}" class="onboarding-mask" catchtouchmove="stopTouchMove">
<view class="onboarding-card">
<view class="onboarding-icon">✓</view>
<text class="onboarding-title">员工已创建</text>
<text class="onboarding-desc">{{pickerMode ? '设置常规排班后,可继续把当前预约分配给该员工。' : '为新员工设置首个常规排班,之后即可正常承接预约。'}}</text>
<button class="primary-btn onboarding-primary" bindtap="setupFirstSchedule">{{pickerMode ? '设置排班并分配' : '立即设置排班'}}</button>
<button class="onboarding-skip" bindtap="skipFirstSchedule">{{pickerMode ? '暂不设置' : '稍后设置'}}</button>
</view>
</view>
</view>
@@ -79,3 +79,43 @@
.create-form .field-label {
width: 176rpx;
}
.onboarding-mask {
position: fixed;
z-index: 50;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
padding: 44rpx;
background: rgba(34, 39, 36, 0.58);
}
.onboarding-card {
display: flex;
width: 100%;
box-sizing: border-box;
flex-direction: column;
align-items: center;
padding: 42rpx 34rpx 28rpx;
border-radius: 28rpx;
background: #fffdf8;
}
.onboarding-icon {
display: flex;
align-items: center;
justify-content: center;
width: 82rpx;
height: 82rpx;
border-radius: 50%;
background: #e5eee9;
color: #39705d;
font-size: 38rpx;
font-weight: 900;
}
.onboarding-title { margin-top: 22rpx; color: #29241f; font-size: 32rpx; font-weight: 900; }
.onboarding-desc { margin-top: 12rpx; color: #837b72; font-size: 23rpx; line-height: 1.7; text-align: center; }
.onboarding-primary { width: 100%; margin-top: 30rpx; }
.onboarding-skip { margin-top: 12rpx; background: transparent; color: #7e776f; font-size: 23rpx; }