Commit cbe53bd1 by 张立顺

fix 服务中心弹框bug

1 parent 4a15fce8
# 服务中心公告:精品 vs 权益 弹窗逻辑
精品首页(`tabIndex`)与权益首页(`packageEquity`)对服务中心未读公告的处理**一致**:有未读则弹窗,但**每个 `moduleType` 每天最多弹 1 次**(用户点确认进入后标记)。
精品首页(`tabIndex`)与权益首页(`packageEquity`)对服务中心未读公告的处理**一致**,对齐 **V5.8.1**:有未读(`status:0`)即弹首条,无本地 moduleType 门禁。
## 行为对比
......@@ -12,25 +12,23 @@
## 流程
1. `fetchServiceCenterUnread()` — 角标(60s TTL + in-flight;探测全部 `noticeSort` 类型)
2. `resolveServiceNoticePopupCandidate()` — 按 `noticeSort` 取**第一条**有未读且**今日该类型尚未弹过**的公告
2. `resolveFirstUnreadNotice()` — 按 `noticeSort` 取**第一条** `status:0` 未读公告
3. `enqueueServiceNoticePopup(page, candidate)` — `addModalToQueue` priority 10;用户**点确认**后:
- `markServiceNoticePopupShown(moduleType)` 写入固定 key `serviceNoticePop`(结构 `{ date, [moduleType]: true }`)
- 先调 `getCompanyNoticeDetail({ id })` — 服务端将该条标为已读
- `clearServiceCenterNoticeCache()` 清探测缓存
- 跳转详情并 `showNextModal` 链式展示
**与 V5.8.1 的差异**:V5.8.1 有未读即每次 `onShow` 都弹;当前实现用户确认进入后,同日同类型不再弹(角标仍可显示未读数)。
**返回首页后**:已读条目不参与 `status:0` 列表,同一条不再弹;同类型其他未读仍可继续弹下一条。
## 共享模块
| 模块 | 路径 |
|------|------|
| 角标 / 弹窗候选 | [`utils/serviceCenterNoticeService.js`](../utils/serviceCenterNoticeService.js) |
| 角标 / 未读解析 | [`utils/serviceCenterNoticeService.js`](../utils/serviceCenterNoticeService.js) |
| 弹窗入队 | [`utils/serviceNoticePopupHandler.js`](../utils/serviceNoticePopupHandler.js) |
双端通过 [`tabIndex/services/serviceCenterNoticeService.js`](../tabIndex/services/serviceCenterNoticeService.js)、[`packageEquity/services/serviceCenterNoticeService.js`](../packageEquity/services/serviceCenterNoticeService.js) re-export。
Storage key 双端共用固定 key `serviceNoticePop`(须在 [`utils/constantData.js`](../utils/constantData.js) 注册),内含 `date` 字段区分当日,避免精品/权益各记各的导致重复弹。
## 调用链
- **精品**:`initData` → `checkDailyRecport` → `runDailyChecks` → `checkServiceNotice`(`isStaff`)→ `showNextModal`
......@@ -40,8 +38,7 @@ Storage key 双端共用固定 key `serviceNoticePop`(须在 [`utils/constantD
1. **`checkAgreeClient` 悬挂**:已修复 `code != '0'` 与 `.catch` 不 resolve 的问题
2. **`wx.__HAS_SHOW_MODAL`**:`runDailyChecks` / `initList` 展示前会重置;`modalQueueService` 支持短暂重试
3. **今日已弹过该类型**:属预期行为;次日或清 storage 后可再弹
4. **入队失败**:查看控制台 `[serviceNoticePopup] missing dialogOptions` 或 `[checkServiceNotice] enqueue failed`
3. **入队失败**:查看控制台 `[serviceNoticePopup] missing dialogOptions` 或 `[checkServiceNotice] enqueue failed`
## 测试
......
......@@ -24,7 +24,7 @@
- **Tab0 看板**:`homeRefreshService` in-flight;`initList` 不再刷 home;`onShow` 补子页返回路径
- **Tab1–4 子页**:`pageShow[N]` 懒挂载 + `hide` 保活;`show` → `refreshOnShow` + `tabRefreshService`
- **父页去重**:`getMerchant4SMode` 仅 `onLoad`;`checkStaffOrderStatus` 仅 Tab0 + `staffOrderValidService`
- **服务中心公告**:每日每 `moduleType` 弹 1 次,确认后标记;见 [`docs/SERVICE-CENTER-NOTICE-POPUP.md`](../../docs/SERVICE-CENTER-NOTICE-POPUP.md)
- **服务中心公告**:V5.8.1 已读语义,`resolveFirstUnreadNotice` + 确认调 detail;见 [`docs/SERVICE-CENTER-NOTICE-POPUP.md`](../../docs/SERVICE-CENTER-NOTICE-POPUP.md)
- **tab-bar**:`suppressInitialClick` 避免工单/权益列表首屏三入口
- 详录:[`TAB-REFRESH-CHANGELOG.md`](./TAB-REFRESH-CHANGELOG.md)
- 单测:`IT-EQ-HOME-*`、`IT-EQ-TAB-*`、`IT-EQ-STAFF-*`(`npm run test:equity` 68 用例)
......@@ -54,7 +54,7 @@
| 职责 | equityPage(父页) | home(本组件) |
|------|-------------------|----------------|
| 公告角标/弹窗 | `checkServiceNotice`(仅 Tab0 + [`serviceCenterNoticeService`](../services/serviceCenterNoticeService.js) 缓存;每日每 moduleType 弹 1 次) | 只读 `serviceCenterUnreadNum` |
| 公告角标/弹窗 | `checkServiceNotice`(仅 Tab0 + [`serviceCenterNoticeService`](../services/serviceCenterNoticeService.js) 缓存;V5.8.1 已读语义) | 只读 `serviceCenterUnreadNum` |
| 门店 mode | `equityPage.onLoad` / 切店 `initData` 调用 `getMerchant4SMode` 下发 `mode` | `scheduleInitialMenuBuild` 等 mode 就绪后建菜单 |
| 菜单异步 API | 不调用 | `rebuildEquityMenus` 唯一入口 |
| 切 4S 店 | `SideSelectPopup` → `equityPage.initData` → `getMerchant4SMode` → home `onStoreSwitched`(同步 userInfo/品牌、`invalidateMenuCache` 含 API 缓存、`rebuildEquityMenus({ force, mode })`、`refreshEquityHome`);Tab1–4 额外 `refreshOnShow` | 动态日报 / 工资申诉 / 驻店目标等随门店重建 |
......@@ -110,7 +110,7 @@ npm run test:equity
| 步骤 | 模块 |
|------|------|
| 角标 | `fetchServiceCenterUnread`(60s 缓存) |
| 弹窗候选 | `resolveServiceNoticePopupCandidate`(每日每 moduleType 弹 1 次,确认后标记) |
| 弹窗候选 | `resolveFirstUnreadNotice`(status:0 首条未读,确认调 detail 标已读) |
| 入队 | `equityPage.checkServiceNotice` → priority 10 |
触发:`initList` 且 `isStaff && tabIndex === 0`。详见 [`docs/SERVICE-CENTER-NOTICE-POPUP.md`](../../docs/SERVICE-CENTER-NOTICE-POPUP.md)。
......
......@@ -18,7 +18,7 @@ import carLifeApi from '../../carEquityApi'
import {
fetchServiceCenterUnread,
resolveServiceNoticePopupCandidate
resolveFirstUnreadNotice
} from '../../services/serviceCenterNoticeService.js'
import { enqueueServiceNoticePopup } from '~/utils/serviceNoticePopupHandler.js'
import {
......@@ -674,7 +674,7 @@ Page({
const unread = await fetchServiceCenterUnread()
this.setData({ serviceCenterUnreadNum: unread })
const candidate = await resolveServiceNoticePopupCandidate()
const candidate = await resolveFirstUnreadNotice()
if (!candidate) return
try {
......
export {
fetchServiceCenterUnread,
resolveServiceNoticePopupCandidate,
markServiceNoticePopupShown,
resolveFirstUnreadNotice,
clearServiceCenterNoticeCache,
__setListApiForTest
} from '../../utils/serviceCenterNoticeService.js'
import { describe, it, beforeEach, afterEach } from 'node:test'
import assert from 'node:assert/strict'
function createStorageMock() {
const data = {}
return {
get(key) {
return data[key]
},
set(key, value) {
data[key] = value
}
}
}
describe('serviceCenterNoticeService', async () => {
const {
fetchServiceCenterUnread,
resolveServiceNoticePopupCandidate,
markServiceNoticePopupShown,
resolveFirstUnreadNotice,
__setListApiForTest,
clearServiceCenterNoticeCache
} = await import('../services/serviceCenterNoticeService.js')
......@@ -32,7 +19,7 @@ describe('serviceCenterNoticeService', async () => {
return '2026-06-09'
}
}
globalThis.wx = { $storage: createStorageMock() }
globalThis.wx = {}
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
......@@ -55,8 +42,8 @@ describe('serviceCenterNoticeService', async () => {
assert.equal(apiCalls.length, 3)
})
it('IT-EQ-NOTICE-002: resolveServiceNoticePopupCandidate returns first unread by noticeSort', async () => {
const first = await resolveServiceNoticePopupCandidate()
it('IT-EQ-NOTICE-002: resolveFirstUnreadNotice returns first unread by noticeSort', async () => {
const first = await resolveFirstUnreadNotice()
assert.ok(first)
assert.equal(first.moduleType, 6)
clearServiceCenterNoticeCache()
......@@ -70,36 +57,12 @@ describe('serviceCenterNoticeService', async () => {
}
return { data: { list: [] } }
})
const second = await resolveServiceNoticePopupCandidate()
const second = await resolveFirstUnreadNotice()
assert.ok(second)
assert.equal(second.moduleType, 7)
})
it('IT-EQ-NOTICE-003: skips moduleType already shown today', async () => {
markServiceNoticePopupShown(6)
const candidate = await resolveServiceNoticePopupCandidate()
assert.equal(candidate, null)
})
it('IT-EQ-NOTICE-004: daily gate is per moduleType not global', async () => {
markServiceNoticePopupShown(6)
clearServiceCenterNoticeCache()
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
return { data: { list: [{ id: 1, msgTitle: '课程', reminderType: 1 }] } }
}
if (params.moduleType === 7) {
return { data: { list: [{ id: 2, msgTitle: '案例', reminderType: 1 }] } }
}
return { data: { list: [] } }
})
const candidate = await resolveServiceNoticePopupCandidate()
assert.ok(candidate)
assert.equal(candidate.moduleType, 7)
})
it('IT-EQ-NOTICE-005: probe scans all module types once per cache window', async () => {
it('IT-EQ-NOTICE-003: probe scans all module types once per cache window', async () => {
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
......@@ -108,14 +71,7 @@ describe('serviceCenterNoticeService', async () => {
return { data: { list: [] } }
})
await fetchServiceCenterUnread()
await resolveServiceNoticePopupCandidate()
await resolveFirstUnreadNotice()
assert.equal(apiCalls.length, 3)
})
it('IT-EQ-NOTICE-006: allows popup again when storage date is stale', async () => {
wx.$storage.set('serviceNoticePop', { date: '2026-06-08', 6: true })
const candidate = await resolveServiceNoticePopupCandidate()
assert.ok(candidate)
assert.equal(candidate.moduleType, 6)
})
})
# DEVLOG — tabIndex 精品首页
## 2026-06 — 服务中心公告每日弹窗门禁
## 2026-06 — 服务中心公告按已读状态弹窗(V5.8.1)
- 恢复每个 `moduleType` 每天最多弹 1 次;`resolveServiceNoticePopupCandidate` + 固定 key `serviceNoticePop`(内嵌 `date`)
- **确认后标记**(非入队时标记),修复「进入详情返回仍弹同一条」
- 去掉 moduleType 每日门禁;`resolveFirstUnreadNotice` + 确认时 `getCompanyNoticeDetail` 标已读
- 共享 [`utils/serviceCenterNoticeService.js`](../../utils/serviceCenterNoticeService.js)、[`utils/serviceNoticePopupHandler.js`](../../utils/serviceNoticePopupHandler.js)
## 2026-06 — 服务中心公告对齐 V5.8.1(已 supersede)
## 2026-06 — 服务中心公告每日弹窗门禁(已 supersede)
- 曾移除「今日已弹」门禁;已由上条每日门禁替代
- 曾按 moduleType 每日弹 1 次;已由上条服务端已读方案替代
## 2026-06 — 服务中心公告弹窗恢复
......
......@@ -15,7 +15,7 @@
| 方法 | 服务 | 说明 |
|------|------|------|
| `checkDailyRecport` → `checkServiceNotice` | [`dailyCheckService.js`](../services/dailyCheckService.js) + [`serviceCenterNoticeService.js`](../services/serviceCenterNoticeService.js) | 每日每 moduleType 弹 1 次,确认后标记 |
| `checkDailyRecport` → `checkServiceNotice` | [`dailyCheckService.js`](../services/dailyCheckService.js) + [`serviceCenterNoticeService.js`](../services/serviceCenterNoticeService.js) | V5.8.1:status:0 首条未读,确认调 detail 标已读 |
- 调用:`runDailyChecks` 在 `isStaff` 时并行执行 `checkServiceNotice(page)`
- 弹窗入队见 [`utils/serviceNoticePopupHandler.js`](../../utils/serviceNoticePopupHandler.js)
......
......@@ -9,7 +9,7 @@ import {
} from './todoService.js'
import {
fetchServiceCenterUnread,
resolveServiceNoticePopupCandidate
resolveFirstUnreadNotice
} from './serviceCenterNoticeService.js'
import { enqueueServiceNoticePopup } from '../../utils/serviceNoticePopupHandler.js'
......@@ -149,12 +149,12 @@ export function checkAgreeClient(page, loginUserObj) {
})
}
/** 服务中心未读角标 + 弹窗(每日每 moduleType 最多弹 1 次,确认后标记) */
/** 服务中心未读角标 + 弹窗(V5.8.1:status:0 首条未读,确认调 detail 标已读) */
export async function checkServiceNotice(page) {
const unread = await fetchServiceCenterUnread()
page.setData({ serviceCenterUnreadNum: unread })
const candidate = await resolveServiceNoticePopupCandidate()
const candidate = await resolveFirstUnreadNotice()
if (!candidate) return
try {
......
export {
fetchServiceCenterUnread,
resolveServiceNoticePopupCandidate,
markServiceNoticePopupShown,
resolveFirstUnreadNotice,
clearServiceCenterNoticeCache,
__setListApiForTest
} from '../../utils/serviceCenterNoticeService.js'
import { describe, it, beforeEach, afterEach } from 'node:test'
import assert from 'node:assert/strict'
function createStorageMock() {
const data = {}
return {
get(key) {
return data[key]
},
set(key, value) {
data[key] = value
}
}
}
describe('tabIndex serviceCenterNoticeService', async () => {
const {
fetchServiceCenterUnread,
resolveServiceNoticePopupCandidate,
markServiceNoticePopupShown,
resolveFirstUnreadNotice,
__setListApiForTest,
clearServiceCenterNoticeCache
} = await import('../services/serviceCenterNoticeService.js')
......@@ -32,7 +19,7 @@ describe('tabIndex serviceCenterNoticeService', async () => {
return '2026-06-09'
}
}
globalThis.wx = { $storage: createStorageMock() }
globalThis.wx = {}
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
......@@ -55,8 +42,8 @@ describe('tabIndex serviceCenterNoticeService', async () => {
assert.equal(apiCalls.length, 3)
})
it('IT-TAB-NOTICE-002: resolveServiceNoticePopupCandidate returns first unread by noticeSort', async () => {
const first = await resolveServiceNoticePopupCandidate()
it('IT-TAB-NOTICE-002: resolveFirstUnreadNotice returns first unread by noticeSort', async () => {
const first = await resolveFirstUnreadNotice()
assert.ok(first)
assert.equal(first.moduleType, 6)
clearServiceCenterNoticeCache()
......@@ -70,36 +57,12 @@ describe('tabIndex serviceCenterNoticeService', async () => {
}
return { data: { list: [] } }
})
const second = await resolveServiceNoticePopupCandidate()
const second = await resolveFirstUnreadNotice()
assert.ok(second)
assert.equal(second.moduleType, 7)
})
it('IT-TAB-NOTICE-003: skips moduleType already shown today', async () => {
markServiceNoticePopupShown(6)
const candidate = await resolveServiceNoticePopupCandidate()
assert.equal(candidate, null)
})
it('IT-TAB-NOTICE-004: daily gate is per moduleType not global', async () => {
markServiceNoticePopupShown(6)
clearServiceCenterNoticeCache()
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
return { data: { list: [{ id: 1, msgTitle: '课程', reminderType: 1 }] } }
}
if (params.moduleType === 7) {
return { data: { list: [{ id: 2, msgTitle: '案例', reminderType: 1 }] } }
}
return { data: { list: [] } }
})
const candidate = await resolveServiceNoticePopupCandidate()
assert.ok(candidate)
assert.equal(candidate.moduleType, 7)
})
it('IT-TAB-NOTICE-005: probe scans all module types once per cache window', async () => {
it('IT-TAB-NOTICE-003: probe scans all module types once per cache window', async () => {
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
......@@ -108,14 +71,7 @@ describe('tabIndex serviceCenterNoticeService', async () => {
return { data: { list: [] } }
})
await fetchServiceCenterUnread()
await resolveServiceNoticePopupCandidate()
await resolveFirstUnreadNotice()
assert.equal(apiCalls.length, 3)
})
it('IT-TAB-NOTICE-006: allows popup again when storage date is stale', async () => {
wx.$storage.set('serviceNoticePop', { date: '2026-06-08', 6: true })
const candidate = await resolveServiceNoticePopupCandidate()
assert.ok(candidate)
assert.equal(candidate.moduleType, 6)
})
})
......@@ -23,7 +23,6 @@ export const STORAGE_OBJECTkEY = {
crowdFundingParams: 'crowdFundingParams',
dateStaffPop: 'dateStaffPop',
abnormalOrderPop: 'abnormalOrderPop',
serviceNoticePop: 'serviceNoticePop',
mock_data: 'mock_data',
recordList:'recordList'
}
......
/**
* 服务中心公告:角标拉取(TTL + in-flight)与弹窗候选(每日每 moduleType 最多弹 1 次)
* 服务中心公告:角标拉取(TTL + in-flight)与首条未读(status:0,无本地门禁)
*/
import { noticeSort } from './enum/serviceCenter.js'
......@@ -83,48 +83,11 @@ export async function fetchServiceCenterUnread() {
}
}
const POPUP_STORAGE_KEY = 'serviceNoticePop'
function todayDateString() {
const d = new Date()
if (typeof d.format === 'function') {
return d.format('yyyy-MM-dd')
}
return d.toISOString().slice(0, 10)
}
function readPopupStorage() {
const stored = wx.$storage?.get?.(POPUP_STORAGE_KEY) || {}
const today = todayDateString()
if (stored.date && stored.date !== today) {
return { date: today }
}
return stored.date ? stored : { date: today }
}
function wasPopupShownToday(moduleType) {
const stored = readPopupStorage()
const today = todayDateString()
return stored.date === today && !!stored[moduleType]
}
/** 用户点确认进入后标记,避免同日同 moduleType 重复弹 */
export function markServiceNoticePopupShown(moduleType) {
const stored = readPopupStorage()
const today = todayDateString()
const next =
stored.date === today
? { ...stored, [moduleType]: true }
: { date: today, [moduleType]: true }
wx.$storage?.set?.(POPUP_STORAGE_KEY, next)
}
/** 按 noticeSort 返回今日尚未弹过的首条未读公告 */
export async function resolveServiceNoticePopupCandidate() {
/** 按 noticeSort 返回首条未读公告(V5.8.1:有未读即弹,依赖服务端 status) */
export async function resolveFirstUnreadNotice() {
const probes = await probeNoticeLists()
for (const { moduleType, list } of probes) {
if (!list?.length) continue
if (wasPopupShownToday(moduleType)) continue
return { moduleType, noticeItem: list[0] }
}
return null
......
......@@ -3,10 +3,7 @@
*/
import { dialogOptions, ServerCenterEnum } from './enum/index.js'
import { getCompanyNoticeDetail } from '~/api/serviceCenter/index'
import {
markServiceNoticePopupShown,
clearServiceCenterNoticeCache
} from './serviceCenterNoticeService.js'
import { clearServiceCenterNoticeCache } from './serviceCenterNoticeService.js'
function resolveDialogParams(serviceCenterEnum, noticeItem) {
const typeOpts = dialogOptions[serviceCenterEnum]
......@@ -42,12 +39,11 @@ export function enqueueServiceNoticePopup(page, candidate) {
false,
10,
async () => {
markServiceNoticePopupShown(serviceCenterEnum)
clearServiceCenterNoticeCache()
wx.$util.showLoading()
try {
const { data } = await getCompanyNoticeDetail({ id: noticeItem.id })
clearServiceCenterNoticeCache()
if (dialogParams.type === ServerCenterEnum.longCourse) {
const { data } = await getCompanyNoticeDetail({ id: noticeItem.id })
wx.navigateTo({
url: `/packageStudyCenter/pages/taskDetail/longCourse/longCourse?row=${encodeURIComponent(JSON.stringify(data.msgDetail))}&form=serviceCenter`,
fail: err => {
......
......@@ -136,7 +136,6 @@ const removeStorage = () => {
wx.removeStorageSync('dj_boutique_sessionId')
wx.removeStorageSync('dateStaffPop')
wx.removeStorageSync('abnormalOrderPop')
wx.removeStorageSync('serviceNoticePop')
wx.removeStorageSync('dj_boutique_webview_h5_tokens')
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!