修复预约草稿恢复逻辑
This commit is contained in:
@@ -118,10 +118,6 @@ function buildDraftKey() {
|
|||||||
return `${DRAFT_STORAGE_PREFIX}:${userInfo.id || 'guest'}:${userInfo.shopId || 'default'}`
|
return `${DRAFT_STORAGE_PREFIX}:${userInfo.id || 'guest'}:${userInfo.shopId || 'default'}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasPresetOptions(options) {
|
|
||||||
return Boolean(options.customerName || options.phone || options.date || options.artistId)
|
|
||||||
}
|
|
||||||
|
|
||||||
function readDraftForm() {
|
function readDraftForm() {
|
||||||
try {
|
try {
|
||||||
const draft = wx.getStorageSync(buildDraftKey())
|
const draft = wx.getStorageSync(buildDraftKey())
|
||||||
@@ -573,6 +569,32 @@ function normalizeCustomer(customer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildInitialAppointmentForm(defaultForm, draftForm, options) {
|
||||||
|
const baseForm = draftForm || {}
|
||||||
|
const optionCustomerName = options.customerName ? decodeURIComponent(options.customerName) : ''
|
||||||
|
const optionPhone = options.phone ? decodeURIComponent(options.phone) : ''
|
||||||
|
const optionDate = options.date || ''
|
||||||
|
const optionArtistId = options.artistId || ''
|
||||||
|
const baseArtistId = baseForm.artistId || ''
|
||||||
|
const appointmentDate = optionDate || baseForm.appointmentDate || dateUtil.formatDate(new Date())
|
||||||
|
const artistId = optionArtistId || baseArtistId
|
||||||
|
const shouldClearCustomerUserId = Boolean(optionCustomerName || optionPhone)
|
||||||
|
const shouldClearAppointmentTime = Boolean(
|
||||||
|
(optionDate && optionDate !== baseForm.appointmentDate) ||
|
||||||
|
(optionArtistId && String(optionArtistId) !== String(baseArtistId))
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
...defaultForm,
|
||||||
|
...baseForm,
|
||||||
|
customerUserId: shouldClearCustomerUserId ? '' : (baseForm.customerUserId || ''),
|
||||||
|
customerName: optionCustomerName || baseForm.customerName || '',
|
||||||
|
phone: optionPhone || baseForm.phone || '',
|
||||||
|
appointmentDate,
|
||||||
|
appointmentTime: shouldClearAppointmentTime ? '' : (baseForm.appointmentTime || ''),
|
||||||
|
artistId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
form: {
|
form: {
|
||||||
@@ -631,19 +653,12 @@ Page({
|
|||||||
|
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
const creatable = canCreateAppointment()
|
const creatable = canCreateAppointment()
|
||||||
const draftForm = creatable && !hasPresetOptions(options) ? readDraftForm() : null
|
const draftForm = creatable ? readDraftForm() : null
|
||||||
const baseForm = draftForm || {}
|
const initialForm = buildInitialAppointmentForm(this.data.form, draftForm, options)
|
||||||
this.setData({
|
this.setData({
|
||||||
canCreateAppointment: creatable,
|
canCreateAppointment: creatable,
|
||||||
form: {
|
form: initialForm,
|
||||||
...this.data.form,
|
manualProductImageUrls: splitManualImageValues(initialForm.manualProductImageUrl || ''),
|
||||||
...baseForm,
|
|
||||||
customerName: options.customerName ? decodeURIComponent(options.customerName) : (baseForm.customerName || ''),
|
|
||||||
phone: options.phone ? decodeURIComponent(options.phone) : (baseForm.phone || ''),
|
|
||||||
appointmentDate: options.date || baseForm.appointmentDate || dateUtil.formatDate(new Date()),
|
|
||||||
artistId: options.artistId || baseForm.artistId || ''
|
|
||||||
},
|
|
||||||
manualProductImageUrls: splitManualImageValues(baseForm.manualProductImageUrl || ''),
|
|
||||||
draftSavedAtText: draftForm ? '已恢复本机草稿' : ''
|
draftSavedAtText: draftForm ? '已恢复本机草稿' : ''
|
||||||
})
|
})
|
||||||
if (!creatable) {
|
if (!creatable) {
|
||||||
|
|||||||
@@ -296,3 +296,11 @@
|
|||||||
- 处理方式:涉及 `$env:GIT_INDEX_FILE`、`$LASTEXITCODE` 等内层变量时,改用 `rtk proxy powershell -NoProfile -Command '...'`,并用 PowerShell 双单引号传递路径字符串;如果真实暂存区已被影响,立即按原 `git diff --cached --name-only` 清单恢复暂存。
|
- 处理方式:涉及 `$env:GIT_INDEX_FILE`、`$LASTEXITCODE` 等内层变量时,改用 `rtk proxy powershell -NoProfile -Command '...'`,并用 PowerShell 双单引号传递路径字符串;如果真实暂存区已被影响,立即按原 `git diff --cached --name-only` 清单恢复暂存。
|
||||||
- 以后避免:提交前临时 index 检测不要用 `rtk powershell` 双引号一行命令;先用一个无副作用变量输出命令确认内层变量能保留,再执行 git read-tree/add/detect-changes。
|
- 以后避免:提交前临时 index 检测不要用 `rtk powershell` 双引号一行命令;先用一个无副作用变量输出命令确认内层变量能保留,再执行 git read-tree/add/detect-changes。
|
||||||
- 验证方式:命令执行后 `Test-Path` 确认临时 index 已删除,`git status --short` 和 `git diff --cached --name-only` 确认真实暂存区仍是预期文件。
|
- 验证方式:命令执行后 `Test-Path` 确认临时 index 已删除,`git status --short` 和 `git diff --cached --name-only` 确认真实暂存区仍是预期文件。
|
||||||
|
|
||||||
|
## 2026-07-22 预约表单草稿恢复不能被入口预填参数短路
|
||||||
|
|
||||||
|
- 问题:店务小程序预约表单保存草稿后,从规划页或客户详情页再次进入时,如果 URL 带 `date`、`artistId`、`customerName` 或 `phone`,本机草稿不会恢复。
|
||||||
|
- 原因:`onLoad` 把“存在入口预填参数”和“恢复草稿”做成互斥条件,规划页新建预约默认总会带日期,导致已保存草稿被跳过。
|
||||||
|
- 处理方式:进入页面时只要当前账号可创建预约就读取草稿,再用入口参数覆盖对应字段;入口客户信息覆盖时清空旧 `customerUserId`,入口日期或美甲师变化时清空旧预约时间。
|
||||||
|
- 以后避免:表单草稿恢复逻辑不要用入口参数整体短路;预填参数只覆盖它明确表达的字段,依赖日期、人员、客户身份的字段要按依赖关系重算或清空。
|
||||||
|
- 验证方式:保存含作品、时长、客户等字段的草稿后,从规划页带日期进入应显示“已恢复本机草稿”,且保留草稿内容;若入口日期或美甲师不同,预约时间应为空并重新按最新排班加载。
|
||||||
|
|||||||
Reference in New Issue
Block a user