Commit df9693ee by 张立顺

fix bug

1 parent f55c29da
......@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd";
* 4预发布
* 5cdptest
*/
let index = 0;
let index = 2;
const accountInfo = wx.getAccountInfoSync();
const systemInfo = wx.getSystemInfoSync();
const envName = accountInfo.miniProgram.envVersion;
......
......@@ -2,6 +2,7 @@
display: flex;
align-items: center;
justify-content: space-between;
gap: 24rpx;
min-height: 96rpx;
padding: 0 32rpx;
box-sizing: border-box;
......@@ -17,6 +18,7 @@
display: flex;
align-items: center;
flex-shrink: 0;
min-width: 0;
max-width: 50%;
font-size: 28rpx;
color: #292d33;
......
......@@ -19,6 +19,7 @@
- **翻页**:`当前行/总行`,左右圆钮 + CDN 图标(`IMG_URL + upgrade/formLift.png` / `formRight.png`)
- **浅蓝内容区**(`rgba(148,194,255,0.2)`,`border-radius: 24rpx`):「第 N 行」+ 删除(浅蓝圆底)
- **字段**:每个子字段独立 **白色圆角块**,块间距 16rpx(非整表连续分割线)
- **字段行**:`form-info-row` 左侧 label 与右侧 value 最小间距 **24rpx**(`form-field-radio.wxss` `gap`)
- 组件样式:`form-group-repeater.wxss` + `styleIsolation: apply-shared` 覆盖子字段行样式
组件:[`form-group-repeater`](../components/form-group-repeater/)
......
......@@ -48,7 +48,7 @@
| Schema 能力 | 实现 | 说明 |
|-------------|------|------|
| F1-1 出勤 radio | [`radio-value.js`](../form-engine/radio-value.js) | 无 `rules.result`,始终可见 |
| F1-2/F1-3、group `rules.keys` + `result: val1 == "在岗"` | [`field-show-rule.js`](../form-engine/visibility/specs/field-show-rule.js) | eval `rules.result`;调休时隐藏 |
| F1-2/F1-3、group `rules.keys` + `result: val1 == "在岗"` | [`field-show-rule.js`](../form-engine/visibility/specs/field-show-rule.js) | eval `rules.result`;调休时隐藏;详情回显白名单不覆盖出勤 gate([`detail-echo.js`](../form-engine/visibility/specs/detail-echo.js)) |
| F1-4 备注 | 无 `rules.result` | 调休时仍可见 |
| group `rules` / `childrenRules` | `schema-normalizer` → `normalizeStaticGroupChildren` | `childrenRules` 合并进子字段 `rules`(min/integer 等) |
| 子字段 `sceneType` / `baseSceneCode` | `isFieldVisible` → `matchesBaseSceneCode` | 轻改码 vs 延保码分行展示 |
......
/** 详情 jsonContent 回显范围:跳过模版 brand/scene 过滤 */
import { isSubform, isStaticGroup } from '../../field-types.js'
import { isDividerVisible } from '../../visibility.js'
import { ATTENDANCE_KEY, isDividerVisible } from '../../visibility.js'
/** 字段是否受 F1-1 出勤 rules.result 联动(与 field-show-rule.js 一致) */
function isAttendanceGatedField(field = {}) {
const rules = field.rules || {}
const keys = rules.keys || []
return keys.includes(ATTENDANCE_KEY) && !!rules.result
}
function resolveEchoSubformKeys(ctx = {}, options = {}) {
if (options.echoSubformKeys instanceof Set && options.echoSubformKeys.size) {
......@@ -47,6 +54,13 @@ export function detailEchoSpec(field, ctx, _values, options = {}) {
if (field.type === 'divider') {
return isDividerVisible(field, ctx)
}
if (
options.hasAttendanceField &&
!options.attendanceOnDuty &&
isAttendanceGatedField(field)
) {
return null
}
return true
}
if (options.hasAttendanceField && options.attendanceOnDuty) {
......
......@@ -781,6 +781,7 @@ describe('select JSON object on save', async () => {
})
describe('submit adapter', async () => {
const require = createRequire(import.meta.url)
const {
buildFieldDataList,
buildNormalizedFieldDataList,
......@@ -791,6 +792,8 @@ describe('submit adapter', async () => {
} = await import('../form-engine/submit-adapter.js')
const { enrichPageContextWithDetailEcho } = await import('../form-engine/app-subform-json.js')
const { createFormEngine } = await import('../form-engine/core.js')
const { buildMockDetailJsonContent } = require('../api/mockDetailJsonContent.js')
const schemaIndexed = require('../fixtures/schema-staff-daily-full.js')
const schema = loadSchemaFixture('staff')
it('IT-API-002: buildFieldDataList maps visible leaf fields', () => {
......@@ -1048,6 +1051,40 @@ describe('submit adapter', async () => {
assert.ok(afterOnDuty.sectionGroups.some(item => item.key === 'F1-5'))
})
it('IT-STAFF-OFF-003: on-duty echo then switch to off-duty hides brand groups', () => {
const engine = createFormEngine(schema)
const jsonContent = buildMockDetailJsonContent(schemaIndexed, {
'F1-1': '在岗',
'F1-5-1': 1,
'F1-5-2': 2,
'F1-5-3': 3
})
const ctx = enrichPageContextWithDetailEcho(
{
baseSceneCode: 100101,
brandIds: [3454],
merchantId: '100',
sceneList: [{ baseSceneCode: 100101 }]
},
{ jsonContent }
)
engine.init(schema, {
...ctx,
initialValues: {
'F1-1': '在岗',
'F1-5-1': 1,
'F1-5-2': 2,
'F1-5-3': 3
}
})
assert.ok(engine.getVisibleList().some(item => item.key === 'F1-5'))
const afterOffDuty = engine.setFieldValue('F1-1', '调休')
assert.deepEqual(
afterOffDuty.visibleList.map(item => item.key).sort(),
['F1-1', 'F1-4']
)
})
it('IT-API-005: mapBrandListToBrandIds handles other brand', () => {
assert.deepEqual(
mapBrandListToBrandIds([
......
......@@ -54,6 +54,29 @@ describe('visibility specs', () => {
assert.equal(isFieldVisibleBySpecs(field, ctx, {}, {}), true)
})
it('IT-VIS-SPEC-005: off-duty detail echo defers attendance-gated fields to fieldShowRuleSpec', () => {
const field = {
key: 'F1-5',
type: 'group',
brandId: [3454],
rules: { keys: ['F1-1'], result: 'val1 == "在岗"' }
}
const ctx = {
hasDetailEcho: true,
echoSubformKeys: ['F1-5'],
brandIds: [3454],
sceneList: [{ baseSceneCode: 100101 }]
}
const values = { 'F1-1': '调休' }
const options = {
schemaList: staffSchema.list,
hasAttendanceField: true,
attendanceOnDuty: false
}
assert.equal(detailEchoSpec(field, ctx, values, options), null)
assert.equal(isFieldVisibleBySpecs(field, ctx, values, options), false)
})
it('IT-STAFF-OFF-001: on-duty passes detail echo when key not in echoTopLevelKeys', () => {
const field = { key: 'F1-5', type: 'group', brandId: [3454], rules: { keys: ['F1-1'], result: 'val1 == "在岗"' } }
const ctx = {
......
......@@ -55,8 +55,9 @@
| 职责 | equityPage(父页) | home(本组件) |
|------|-------------------|----------------|
| 公告角标/弹窗 | `checkServiceNotice`(仅 Tab0 + [`serviceCenterNoticeService`](../services/serviceCenterNoticeService.js) 缓存) | 只读 `serviceCenterUnreadNum` |
| 门店 mode | `equityPage.onLoad` 单次 `getMerchant4SMode` 下发 `mode`(初始 `null`) | `scheduleInitialMenuBuild` 等 mode 就绪后建菜单 |
| 门店 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` | 动态日报 / 工资申诉 / 驻店目标等随门店重建 |
| 看板/待办/接待 | `initList` 不刷新看板、不触发 home `onLoad` | `onLoad` / `show` → `refreshEquityHome`([`homeRefreshService`](../services/homeRefreshService.js) in-flight) |
| 开单预警 | `checkStaffOrderStatus` 仅 Tab0;[`staffOrderValidService`](../services/staffOrderValidService.js) 当日缓存 | 不调用 |
......@@ -71,6 +72,11 @@ attached → onLoad
properties.mode → 首次非 null:_buildInitialMenusOnce;后续变化:rebuildEquityMenus(指纹)
rebuildEquityMenus → getMenuFingerprint;hasPerformanceConfig / getTargetCheck → menuApiCache
切店 invalidateMenuCache → invalidateEquityMenuApiCaches(menuApiCache + invalidateSharedMenuApiCaches / dailyReportNewVersionGate,与精品共用 isNeed 缓存)
SideSelect 切店 → equityPage.initData → getMerchant4SMode → home.onStoreSwitched({ mode })
→ setData userInfo/storeInfo → getMerchantCarBrandList → rebuildEquityMenus({ force, mode })
→ refreshEquityHome;tabIndex>0 → #page-N.refreshOnShow
refreshEquityHome → buildHomeRefreshFingerprint + withHomeRefreshDedup(仅 in-flight,每次切回 Tab0 都刷)
......@@ -95,7 +101,7 @@ Tab 1/2 内部 tab-bar → suppressInitialClick 避免 ready 重复 tabClick
npm run test:equity
```
用例前缀:`IT-EQ-DASH-*`、`IT-EQ-TODO-*`、`IT-EQ-REC-*`、`IT-EQ-MENU-*`、`IT-EQ-CACHE-*`、`IT-EQ-HOME-*`、`IT-EQ-TAB-*`、`IT-EQ-STAFF-*`、`IT-EQ-NOTICE-*`
用例前缀:`IT-EQ-DASH-*`、`IT-EQ-TODO-*`、`IT-EQ-REC-*`、`IT-EQ-MENU-*`、`IT-EQ-CACHE-*`、`IT-EQ-HOME-*`、`IT-EQ-TAB-*`、`IT-EQ-STAFF-*`、`IT-EQ-NOTICE-*`、`IT-EQ-STORE-SWITCH-*`
## 不在本组件范围
......
......@@ -55,6 +55,7 @@ export function getMenuFingerprint(userInfo = {}, extra = {}) {
userInfo.uuid,
userInfo.shopMerchantId,
userInfo.merchantId,
userInfo.default4SStoreInfo?.merchantId,
userInfo.loginRole,
userInfo.loginRoleOnSelectMerchant,
userInfo.subLoginUser?.loginRole,
......
......@@ -22,3 +22,7 @@ export { buildEquityMenusSync, buildEquityMenusAsync } from './buildMenus.js'
export { resolveActionType } from './resolveActionType.js'
export { resolveAsyncMenuProviders, resolveCustomerClue } from './asyncProviders.js'
export { createEquityMenuJumpHandler } from './jumpHandlers.js'
export {
clearMenuApiCache,
invalidateEquityMenuApiCaches
} from './menuApiCache.js'
......@@ -2,6 +2,8 @@
* 权益菜单异步 provider 用 API 缓存(in-flight + TTL)
*/
import { invalidateSharedMenuApiCaches } from '../../utils/invalidateMenuApiCaches.js'
const CACHE_TTL_MS = 60 * 1000
const cache = new Map()
const pending = new Map()
......@@ -11,6 +13,12 @@ export function clearMenuApiCache() {
pending.clear()
}
/** 切店 / invalidateMenuCache 时一并清空菜单与动态日报 isNeed 缓存 */
export function invalidateEquityMenuApiCaches() {
clearMenuApiCache()
invalidateSharedMenuApiCaches()
}
function cacheKey(prefix, id) {
return `${prefix}:${id == null ? '' : String(id)}`
}
......
......@@ -599,6 +599,29 @@ Page({
this.showNextModal()
})
},
/**
* 侧边切换 4S 店后刷新(SideSelectPopup.eventCallback 调用,对齐 tabIndex.initData)。
* 重建菜单(含动态日报三入口)并刷新 Tab0 看板/待办/接待。
* @param {Object} [data] - selectMerchantScene 返回,可含 subLoginUser
*/
async initData(data) {
const userInfo = wx.$util.getUserInfo()
if (data?.subLoginUser) {
userInfo.subLoginUser = data.subLoginUser
wx.$util.setUserInfo(userInfo)
}
this.setData({ userInfo })
await this.getMerchant4SMode()
const home = this.selectComponent('#page-0')
if (home?.onStoreSwitched) {
await home.onStoreSwitched({ mode: this.data.mode })
}
const { tabIndex } = this.data
if (tabIndex > 0) {
const tab = this.selectComponent(`#page-${tabIndex}`)
tab?.refreshOnShow?.()
}
},
back() {
if (this.data.staffUuid) {
return wx.$router.back()
......
......@@ -45,7 +45,8 @@ import {
createEquityMenuJumpHandler,
applyEquityMenuBadges,
onWorkReportPopupSelect,
getMenuFingerprint
getMenuFingerprint,
invalidateEquityMenuApiCaches
} from '../../menu/index.js'
import {
handleOrderPromptConfirm,
......@@ -212,6 +213,7 @@ Component({
},
invalidateMenuCache() {
this._menuFingerprint = null
invalidateEquityMenuApiCaches()
},
_shouldRefreshMenus(userInfo) {
const fingerprint = getMenuFingerprint(userInfo, {
......@@ -272,11 +274,14 @@ Component({
if (!userInfo) return
if (!options.force && !this._shouldRefreshMenus(userInfo)) return
const mode =
options.mode !== undefined ? options.mode : this.data.mode
const result = await buildEquityMenusAsync({
userInfo,
isStaff: app.globalData.isStaff,
mentorFlag: this.data.mentorFlag,
mode: this.data.mode,
mode,
merchantBrand: this.data.merchantBrand || [],
deps: {
getBusinessSchoolScene,
......@@ -319,6 +324,31 @@ Component({
})
},
/**
* 切 4S 店后同步门店上下文、品牌列表并重建菜单(由 equityPage.initData 调用)。
* @param {Object} [options]
* @param {number} [options.mode] - 父页 getMerchant4SMode 结果,避免 properties.mode 延迟
*/
async onStoreSwitched(options = {}) {
const userInfo = wx.$util.getUserInfo() || {}
const storeInfo = userInfo.default4SStoreInfo || {}
await new Promise(resolve => {
this.setData({ userInfo, storeInfo }, resolve)
})
if (!wx.$hasPermission?.canViewViolation?.(userInfo)) {
await this.getMerchantCarBrandList()
}
this.invalidateMenuCache()
const mode =
options.mode !== undefined ? options.mode : this.data.mode
await this.rebuildEquityMenus({ force: true, mode })
if (this._homeReady) {
await this.refreshEquityHome({
force: true,
forceReception: true
})
}
},
/**
* Tab0 统一刷新:看板 + 待办 + 可选菜单/接待列表。
* 经 homeRefreshService 做 in-flight 去重;每次切回 Tab0 都会执行(无 TTL 跳过)。
* @param {Object} [options]
......@@ -567,8 +597,9 @@ Component({
})
},
async getMerchantCarBrandList() {
const { userInfo } = this.data
const { shopMerchantId } = userInfo
const userInfo = wx.$util.getUserInfo() || this.data.userInfo || {}
const shopMerchantId = userInfo.shopMerchantId
if (!shopMerchantId) return
const { code, data } = await carLifeApi.getMerchantCarBrandList([shopMerchantId])
if (code == 0 && data) {
this.setData({
......
......@@ -247,6 +247,20 @@ describe('equityMenu', async () => {
assert.notEqual(base, mode1)
})
it('IT-EQ-MENU-FP-004: getMenuFingerprint changes when default4SStoreInfo.merchantId changes', () => {
const a = getMenuFingerprint({
uuid: 'u1',
shopMerchantId: 's1',
default4SStoreInfo: { merchantId: 'store-a' }
})
const b = getMenuFingerprint({
uuid: 'u1',
shopMerchantId: 's1',
default4SStoreInfo: { merchantId: 'store-b' }
})
assert.notEqual(a, b)
})
// --- Role snapshots ---
function syncMenuIds(ctx) {
......
/**
* 权益切 4S 店 — 菜单/缓存补全单测
*
* 运行:npm run test:equity
* 用例前缀:IT-EQ-STORE-SWITCH-*
*/
import { describe, it, beforeEach, afterEach } from 'node:test'
import assert from 'node:assert/strict'
import { setupWxMock } from './menuTestHelpers.mjs'
import {
cachedHasPerformanceConfig,
clearMenuApiCache,
invalidateEquityMenuApiCaches
} from '../menu/menuApiCache.js'
import {
__setApiClientForTest,
clearDailyReportNewVersionCache,
fetchDailyReportNewVersionMenuVisible
} from '../../utils/dailyReportNewVersionGate.js'
import { buildEquityMenusSync } from '../menu/buildMenus.js'
import { createEquityMenuContext } from '../menu/context.js'
describe('equityStoreSwitch', () => {
setupWxMock(globalThis)
beforeEach(() => {
clearMenuApiCache()
clearDailyReportNewVersionCache()
})
afterEach(() => {
clearMenuApiCache()
clearDailyReportNewVersionCache()
__setApiClientForTest(null)
})
it('IT-EQ-STORE-SWITCH-001: invalidateEquityMenuApiCaches clears menu API cache', async () => {
let perfCalls = 0
const commonApi = {
hasPerformanceConfig: async () => {
perfCalls++
return { data: true }
}
}
await cachedHasPerformanceConfig(commonApi, 'store-a')
await cachedHasPerformanceConfig(commonApi, 'store-a')
assert.equal(perfCalls, 1)
invalidateEquityMenuApiCaches()
await cachedHasPerformanceConfig(commonApi, 'store-a')
assert.equal(perfCalls, 2)
})
it('IT-EQ-STORE-SWITCH-001b: invalidateEquityMenuApiCaches clears daily report isNeed cache', async () => {
let isNeedCalls = 0
__setApiClientForTest({
dailyReportNewVersionIsNeed: async () => {
isNeedCalls++
return { code: 0, data: true }
}
})
await fetchDailyReportNewVersionMenuVisible('store-a')
await fetchDailyReportNewVersionMenuVisible('store-a')
assert.equal(isNeedCalls, 1)
invalidateEquityMenuApiCaches()
await fetchDailyReportNewVersionMenuVisible('store-a')
assert.equal(isNeedCalls, 2)
})
it('IT-EQ-STORE-SWITCH-002: explicit mode controls defeat_order without property sync', () => {
const baseCtx = {
userInfo: { loginRole: 4, sceneType: 0 },
isStaff: true
}
const withMode0 = buildEquityMenusSync(
createEquityMenuContext({ ...baseCtx, mode: 0 })
)
const withMode1 = buildEquityMenusSync(
createEquityMenuContext({ ...baseCtx, mode: 1 })
)
assert.ok(!withMode0.some(i => i.id === 'defeat_order'))
assert.ok(withMode1.some(i => i.id === 'defeat_order'))
})
})
......@@ -50,5 +50,6 @@ WXML 通过 `permission.wxs`;JS 通过 `rolePermission.js`。同步校验:`t
```
onLoad → modalQueue 初始化、门店/日期初始化
onShow → customerOnReady(指纹)→ 待办/弹窗/看板刷新
切换门店 → invalidateMenuCache + rebuildMenus
切换门店 → SideSelect → initData → invalidateMenuCache(指纹 + invalidateSharedMenuApiCaches)→ await rebuildMenus(全量重跑 asyncProviders)
rebuildMenus → hasPerformanceConfig / getStaffTargetTask 等直调;动态日报 isNeed 见 utils/dailyReportNewVersionGate(切店必须 invalidate)
```
......@@ -47,8 +47,11 @@ export function getMenuFingerprint(userInfo = {}, extra = {}) {
userInfo.uuid,
userInfo.shopMerchantId,
userInfo.merchantId,
userInfo.default4SStoreInfo?.merchantId,
userInfo.loginRole,
userInfo.loginRoleOnSelectMerchant,
userInfo.subLoginUser?.loginRole,
userInfo.subLoginUser?.channelType,
userInfo.isSuper,
isStaff ? '1' : '0',
mentorFlag
......
......@@ -31,6 +31,7 @@ import {
buildShutDownTaskParams
} from '../../services/todoService.js'
import { runDailyChecks } from '../../services/dailyCheckService.js'
import { invalidateSharedMenuApiCaches } from '~/utils/invalidateMenuApiCaches.js'
import {
computeTableWidth,
mergeTablePage,
......@@ -838,7 +839,7 @@ Page({
}
})
},
initData(userInfo) {
async initData(userInfo) {
userInfo = userInfo ? userInfo : wx.$util.getUserInfo()
getYQInfo(userInfo).then(result => {
wx.$util.hideLoading()
......@@ -861,7 +862,7 @@ Page({
})
// 切换 4S 店后重建菜单(含动态日报、驻店目标等异步入口)
this.invalidateMenuCache()
this.rebuildMenus()
await this.rebuildMenus()
// 产品需求:强制填写(04-17版本)
this.checkDailyRecport()
......@@ -1011,9 +1012,10 @@ Page({
return true
},
/** 切换门店、导师标记变化等场景清除指纹,强制下次重建 */
/** 切换门店、导师标记变化等场景清除指纹与共用 API 缓存,强制下次重建 */
invalidateMenuCache() {
this._menuFingerprint = null
invalidateSharedMenuApiCaches()
},
/**
......
/**
* 精品切 4S 店 — 菜单/缓存补全单测
*
* 运行:npm run test:tabIndex
* 用例前缀:IT-MENU-STORE-SWITCH-*
*/
import { describe, it, beforeEach, afterEach } from 'node:test'
import assert from 'node:assert/strict'
import { invalidateSharedMenuApiCaches } from '../../utils/invalidateMenuApiCaches.js'
import {
__setApiClientForTest,
clearDailyReportNewVersionCache,
fetchDailyReportNewVersionMenuVisible
} from '../../utils/dailyReportNewVersionGate.js'
describe('tabIndexStoreSwitch', () => {
beforeEach(() => {
clearDailyReportNewVersionCache()
})
afterEach(() => {
clearDailyReportNewVersionCache()
__setApiClientForTest(null)
})
it('IT-MENU-STORE-SWITCH-001: invalidateSharedMenuApiCaches clears daily report isNeed cache', async () => {
let isNeedCalls = 0
__setApiClientForTest({
dailyReportNewVersionIsNeed: async () => {
isNeedCalls++
return { code: 0, data: true }
}
})
await fetchDailyReportNewVersionMenuVisible('store-a')
await fetchDailyReportNewVersionMenuVisible('store-a')
assert.equal(isNeedCalls, 1)
invalidateSharedMenuApiCaches()
await fetchDailyReportNewVersionMenuVisible('store-a')
assert.equal(isNeedCalls, 2)
})
})
......@@ -242,6 +242,34 @@ describe('tabIndexMenu', async () => {
assert.notEqual(base, notStaff)
})
it('IT-MENU-FP-004: getMenuFingerprint changes when default4SStoreInfo.merchantId changes', () => {
const a = getMenuFingerprint({
uuid: 'u1',
shopMerchantId: 's1',
default4SStoreInfo: { merchantId: 'store-a' }
})
const b = getMenuFingerprint({
uuid: 'u1',
shopMerchantId: 's1',
default4SStoreInfo: { merchantId: 'store-b' }
})
assert.notEqual(a, b)
})
it('IT-MENU-FP-005: getMenuFingerprint changes when loginRoleOnSelectMerchant changes', () => {
const a = getMenuFingerprint({
uuid: 'u1',
shopMerchantId: 's1',
loginRoleOnSelectMerchant: 3
})
const b = getMenuFingerprint({
uuid: 'u1',
shopMerchantId: 's1',
loginRoleOnSelectMerchant: 4
})
assert.notEqual(a, b)
})
// --- Role snapshots (sync menu ids) ---
function syncMenuIds(ctx) {
......
/**
* 切店 / invalidateMenuCache 时清理由多首页共用的菜单 API 缓存。
*/
import { clearDailyReportNewVersionCache } from './dailyReportNewVersionGate.js'
export function invalidateSharedMenuApiCaches() {
clearDailyReportNewVersionCache()
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!