From 5536acc4d408dc9ea6c67c36352304df1ff8f63d Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Wed, 22 Jul 2026 20:28:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=84=E7=BA=A6=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=E6=81=A2=E5=A4=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/appointment-form/index.js | 45 ++++++++++++------- memory/bugs.md | 8 ++++ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/JY-Salon-WeChat/pages/appointment-form/index.js b/JY-Salon-WeChat/pages/appointment-form/index.js index 348ce6c6..121b2dc2 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.js +++ b/JY-Salon-WeChat/pages/appointment-form/index.js @@ -118,10 +118,6 @@ function buildDraftKey() { 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() { try { 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({ data: { form: { @@ -631,19 +653,12 @@ Page({ onLoad(options) { const creatable = canCreateAppointment() - const draftForm = creatable && !hasPresetOptions(options) ? readDraftForm() : null - const baseForm = draftForm || {} + const draftForm = creatable ? readDraftForm() : null + const initialForm = buildInitialAppointmentForm(this.data.form, draftForm, options) this.setData({ canCreateAppointment: creatable, - form: { - ...this.data.form, - ...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 || ''), + form: initialForm, + manualProductImageUrls: splitManualImageValues(initialForm.manualProductImageUrl || ''), draftSavedAtText: draftForm ? '已恢复本机草稿' : '' }) if (!creatable) { diff --git a/memory/bugs.md b/memory/bugs.md index 3f47873b..a5967b58 100644 --- a/memory/bugs.md +++ b/memory/bugs.md @@ -296,3 +296,11 @@ - 处理方式:涉及 `$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。 - 验证方式:命令执行后 `Test-Path` 确认临时 index 已删除,`git status --short` 和 `git diff --cached --name-only` 确认真实暂存区仍是预期文件。 + +## 2026-07-22 预约表单草稿恢复不能被入口预填参数短路 + +- 问题:店务小程序预约表单保存草稿后,从规划页或客户详情页再次进入时,如果 URL 带 `date`、`artistId`、`customerName` 或 `phone`,本机草稿不会恢复。 +- 原因:`onLoad` 把“存在入口预填参数”和“恢复草稿”做成互斥条件,规划页新建预约默认总会带日期,导致已保存草稿被跳过。 +- 处理方式:进入页面时只要当前账号可创建预约就读取草稿,再用入口参数覆盖对应字段;入口客户信息覆盖时清空旧 `customerUserId`,入口日期或美甲师变化时清空旧预约时间。 +- 以后避免:表单草稿恢复逻辑不要用入口参数整体短路;预填参数只覆盖它明确表达的字段,依赖日期、人员、客户身份的字段要按依赖关系重算或清空。 +- 验证方式:保存含作品、时长、客户等字段的草稿后,从规划页带日期进入应显示“已恢复本机草稿”,且保留草稿内容;若入口日期或美甲师不同,预约时间应为空并重新按最新排班加载。