Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
dj-car-boutique-work-wechat
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 099eebaf
authored
Jul 20, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat 功能优化修改
1 parent
bd5ce321
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
351 additions
and
15 deletions
packageDynamicForm/api/negotiationDailyReport.js
packageDynamicForm/api/negotiationDailyReportAdapters.js
packageDynamicForm/api/staffDailyReport.js
packageDynamicForm/api/staffDailyReportAdapters.js
packageDynamicForm/api/storeDailyReport.js
packageDynamicForm/api/storeDailyReportAdapters.js
packageDynamicForm/docs/ARCHITECTURE.md
packageDynamicForm/pages/behaviors/dailyReportPageMethods.js
packageDynamicForm/pages/negotiationDetail/negotiationDetail.js
packageDynamicForm/pages/staffDailyReport/staffDailyReport.js
packageDynamicForm/pages/storeDailyReport/storeDailyReport.js
packageDynamicForm/tests/staffDailyReportAdapters.test.mjs
packageDynamicForm/tests/storeDailyReportAdapters.test.mjs
packageDynamicForm/api/negotiationDailyReport.js
View file @
099eeba
...
@@ -532,6 +532,44 @@ async function submitForm(payload = {}) {
...
@@ -532,6 +532,44 @@ async function submitForm(payload = {}) {
}
}
}
}
/**
* 首屏渲染后后台刷新 brand/scene/schema 进程内缓存(不更新当前页 UI)
* @param {Object} [options={}]
* @param {Object} [options.userContext] 用户上下文(merchantId、staffUuid 等)
* @param {string} [options.baseSceneCode] 门店场景编码
* @param {number|string} [options.reportTemplateId] 模板 ID
* @returns {Promise<void>}
*/
async
function
revalidateCachedMetadata
({
userContext
=
{},
baseSceneCode
,
reportTemplateId
}
=
{})
{
if
(
isNegotiationMockMode
(
'brand'
)
&&
isNegotiationMockMode
(
'scene'
)
&&
isNegotiationMockMode
(
'schema'
)
)
{
return
}
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
}
=
userContext
if
(
!
merchantId
)
{
return
}
const
refreshOptions
=
{
skipCacheRead
:
true
}
await
Promise
.
allSettled
([
fetchBrandAdapter
({
merchantId
},
refreshOptions
),
fetchSceneAdapter
(
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
},
refreshOptions
),
fetchSchemaRootAdapter
(
{
reportTemplateId
,
baseSceneCode
,
merchantId
},
refreshOptions
)
])
}
module
.
exports
=
{
module
.
exports
=
{
fetchMerchantBrandIds
,
fetchMerchantBrandIds
,
fetchMerchantScene
,
fetchMerchantScene
,
...
@@ -545,5 +583,6 @@ module.exports = {
...
@@ -545,5 +583,6 @@ module.exports = {
fetchTodayPlanStoreList
,
fetchTodayPlanStoreList
,
submitForm
,
submitForm
,
buildPageContextFromSources
,
buildPageContextFromSources
,
normalizeUserInfo
normalizeUserInfo
,
revalidateCachedMetadata
}
}
packageDynamicForm/api/negotiationDailyReportAdapters.js
View file @
099eeba
...
@@ -108,22 +108,27 @@ async function fetchDetailAdapter(params = {}) {
...
@@ -108,22 +108,27 @@ async function fetchDetailAdapter(params = {}) {
/**
/**
* 拉取洽谈 schema 根节点(mock fixture 或配置中心 negotiation-details-template + schemaCache)
* 拉取洽谈 schema 根节点(mock fixture 或配置中心 negotiation-details-template + schemaCache)
* @param {Object} [params={}] reportTemplateId、baseSceneCode、merchantId
* @param {Object} [params={}] reportTemplateId、baseSceneCode、merchantId
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Object}>}
* @returns {Promise<{code: number, message: string, data: Object}>}
*/
*/
async
function
fetchSchemaRootAdapter
(
params
=
{})
{
async
function
fetchSchemaRootAdapter
(
params
=
{}
,
options
=
{}
)
{
const
{
reportTemplateId
,
baseSceneCode
,
merchantId
}
=
params
const
{
reportTemplateId
,
baseSceneCode
,
merchantId
}
=
params
const
{
skipCacheRead
=
false
}
=
options
if
(
isNegotiationMockMode
(
'schema'
))
{
if
(
isNegotiationMockMode
(
'schema'
))
{
return
resolveSchemaRootResult
(
requireNegotiationSchemaTemplate
())
return
resolveSchemaRootResult
(
requireNegotiationSchemaTemplate
())
}
}
const
moduleUrl
=
DYNAMIC_FORM_TEMPLATE_MODULE
.
negotiation
const
moduleUrl
=
DYNAMIC_FORM_TEMPLATE_MODULE
.
negotiation
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedSchema
(
moduleUrl
,
baseSceneCode
)
const
cached
=
getCachedSchema
(
moduleUrl
,
baseSceneCode
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
result
=
await
fetchConfigCenterTemplate
(
moduleUrl
)
const
result
=
await
fetchConfigCenterTemplate
(
moduleUrl
,
{
useCache
:
!
skipCacheRead
}
)
const
resolved
=
resolveSchemaRootResult
(
result
.
data
)
const
resolved
=
resolveSchemaRootResult
(
result
.
data
)
setCachedSchema
(
moduleUrl
,
baseSceneCode
,
resolved
)
setCachedSchema
(
moduleUrl
,
baseSceneCode
,
resolved
)
return
resolved
return
resolved
...
@@ -132,11 +137,14 @@ async function fetchSchemaRootAdapter(params = {}) {
...
@@ -132,11 +137,14 @@ async function fetchSchemaRootAdapter(params = {}) {
/**
/**
* 拉取门店场景列表(mock 或 getUserScene + sceneCache)
* 拉取门店场景列表(mock 或 getUserScene + sceneCache)
* @param {Object} [params={}] merchantId、shopMerchantId、phone、sceneType
* @param {Object} [params={}] merchantId、shopMerchantId、phone、sceneType
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Array}>}
* @returns {Promise<{code: number, message: string, data: Array}>}
*/
*/
async
function
fetchSceneAdapter
(
params
=
{})
{
async
function
fetchSceneAdapter
(
params
=
{}
,
options
=
{}
)
{
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
}
=
params
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
}
=
params
const
resolvedSceneType
=
resolveSceneType
({
sceneType
})
const
resolvedSceneType
=
resolveSceneType
({
sceneType
})
const
{
skipCacheRead
=
false
}
=
options
if
(
isNegotiationMockMode
(
'scene'
))
{
if
(
isNegotiationMockMode
(
'scene'
))
{
return
{
return
{
...
@@ -146,10 +154,12 @@ async function fetchSceneAdapter(params = {}) {
...
@@ -146,10 +154,12 @@ async function fetchSceneAdapter(params = {}) {
}
}
}
}
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedScene
(
staffUuid
,
merchantId
,
resolvedSceneType
)
const
cached
=
getCachedScene
(
staffUuid
,
merchantId
,
resolvedSceneType
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
{
getUserScene
}
=
getDynamicDailyReportApi
()
const
{
getUserScene
}
=
getDynamicDailyReportApi
()
const
result
=
await
getUserScene
({
const
result
=
await
getUserScene
({
...
@@ -168,9 +178,12 @@ async function fetchSceneAdapter(params = {}) {
...
@@ -168,9 +178,12 @@ async function fetchSceneAdapter(params = {}) {
/**
/**
* 拉取门店经营品牌(mock 注入 carBrandApi 或 real + brandCache;key=merchantId,进程内复用)
* 拉取门店经营品牌(mock 注入 carBrandApi 或 real + brandCache;key=merchantId,进程内复用)
* @param {Object} [params={}] merchantId
* @param {Object} [params={}] merchantId
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Array}>}
* @returns {Promise<{code: number, message: string, data: Array}>}
*/
*/
async
function
fetchBrandAdapter
(
params
=
{})
{
async
function
fetchBrandAdapter
(
params
=
{},
options
=
{})
{
const
{
skipCacheRead
=
false
}
=
options
const
runFetch
=
async
()
=>
{
const
runFetch
=
async
()
=>
{
const
fetcher
=
const
fetcher
=
fetchMerchantOperatingBrandListOverride
||
fetchMerchantOperatingBrandListOverride
||
...
@@ -186,10 +199,12 @@ async function fetchBrandAdapter(params = {}) {
...
@@ -186,10 +199,12 @@ async function fetchBrandAdapter(params = {}) {
}
}
const
{
merchantId
}
=
params
const
{
merchantId
}
=
params
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedBrand
(
merchantId
)
const
cached
=
getCachedBrand
(
merchantId
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
result
=
await
runFetch
()
const
result
=
await
runFetch
()
setCachedBrand
(
merchantId
,
result
)
setCachedBrand
(
merchantId
,
result
)
return
result
return
result
...
...
packageDynamicForm/api/staffDailyReport.js
View file @
099eeba
...
@@ -466,6 +466,44 @@ async function submitForm(payload = {}) {
...
@@ -466,6 +466,44 @@ async function submitForm(payload = {}) {
}
}
}
}
/**
* 首屏渲染后后台刷新 brand/scene/schema 进程内缓存(不更新当前页 UI)
* @param {Object} [options={}]
* @param {Object} [options.userContext] 用户上下文(merchantId、staffUuid 等)
* @param {string} [options.baseSceneCode] 门店场景编码
* @param {number|string} [options.reportTemplateId] 模板 ID
* @returns {Promise<void>}
*/
async
function
revalidateCachedMetadata
({
userContext
=
{},
baseSceneCode
,
reportTemplateId
}
=
{})
{
if
(
isStaffMockMode
(
'brand'
)
&&
isStaffMockMode
(
'scene'
)
&&
isStaffMockMode
(
'schema'
)
)
{
return
}
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
}
=
userContext
if
(
!
merchantId
)
{
return
}
const
refreshOptions
=
{
skipCacheRead
:
true
}
await
Promise
.
allSettled
([
fetchBrandAdapter
({
merchantId
},
refreshOptions
),
fetchSceneAdapter
(
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
},
refreshOptions
),
fetchSchemaRootAdapter
(
{
reportTemplateId
,
baseSceneCode
,
merchantId
},
refreshOptions
)
])
}
module
.
exports
=
{
module
.
exports
=
{
fetchMerchantBrandIds
,
fetchMerchantBrandIds
,
fetchMerchantScene
,
fetchMerchantScene
,
...
@@ -476,5 +514,6 @@ module.exports = {
...
@@ -476,5 +514,6 @@ module.exports = {
fetchWeeklyList
,
fetchWeeklyList
,
submitForm
,
submitForm
,
buildPageContextFromSources
,
buildPageContextFromSources
,
normalizeUserInfo
normalizeUserInfo
,
revalidateCachedMetadata
}
}
packageDynamicForm/api/staffDailyReportAdapters.js
View file @
099eeba
...
@@ -100,22 +100,27 @@ async function fetchDetailAdapter(params = {}) {
...
@@ -100,22 +100,27 @@ async function fetchDetailAdapter(params = {}) {
/**
/**
* 拉取驻店 schema 根节点(mock fixture 或配置中心 + schemaCache)
* 拉取驻店 schema 根节点(mock fixture 或配置中心 + schemaCache)
* @param {Object} [params={}] baseSceneCode 等
* @param {Object} [params={}] baseSceneCode 等
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Object}>}
* @returns {Promise<{code: number, message: string, data: Object}>}
*/
*/
async
function
fetchSchemaRootAdapter
(
params
=
{})
{
async
function
fetchSchemaRootAdapter
(
params
=
{}
,
options
=
{}
)
{
const
{
baseSceneCode
}
=
params
const
{
baseSceneCode
}
=
params
const
{
skipCacheRead
=
false
}
=
options
if
(
isStaffMockMode
(
'schema'
))
{
if
(
isStaffMockMode
(
'schema'
))
{
return
resolveSchemaRootResult
(
requireStaffSchemaTemplate
())
return
resolveSchemaRootResult
(
requireStaffSchemaTemplate
())
}
}
const
moduleUrl
=
DYNAMIC_FORM_TEMPLATE_MODULE
.
staff
const
moduleUrl
=
DYNAMIC_FORM_TEMPLATE_MODULE
.
staff
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedSchema
(
moduleUrl
,
baseSceneCode
)
const
cached
=
getCachedSchema
(
moduleUrl
,
baseSceneCode
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
result
=
await
fetchConfigCenterTemplate
(
moduleUrl
)
const
result
=
await
fetchConfigCenterTemplate
(
moduleUrl
,
{
useCache
:
!
skipCacheRead
}
)
const
resolved
=
resolveSchemaRootResult
(
result
.
data
)
const
resolved
=
resolveSchemaRootResult
(
result
.
data
)
setCachedSchema
(
moduleUrl
,
baseSceneCode
,
resolved
)
setCachedSchema
(
moduleUrl
,
baseSceneCode
,
resolved
)
return
resolved
return
resolved
...
@@ -124,11 +129,14 @@ async function fetchSchemaRootAdapter(params = {}) {
...
@@ -124,11 +129,14 @@ async function fetchSchemaRootAdapter(params = {}) {
/**
/**
* 拉取门店场景列表(mock 或 getUserScene + sceneCache)
* 拉取门店场景列表(mock 或 getUserScene + sceneCache)
* @param {Object} [params={}] merchantId、shopMerchantId、phone、sceneType
* @param {Object} [params={}] merchantId、shopMerchantId、phone、sceneType
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Array}>}
* @returns {Promise<{code: number, message: string, data: Array}>}
*/
*/
async
function
fetchSceneAdapter
(
params
=
{})
{
async
function
fetchSceneAdapter
(
params
=
{}
,
options
=
{}
)
{
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
}
=
params
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
}
=
params
const
resolvedSceneType
=
resolveSceneType
({
sceneType
})
const
resolvedSceneType
=
resolveSceneType
({
sceneType
})
const
{
skipCacheRead
=
false
}
=
options
if
(
isStaffMockMode
(
'scene'
))
{
if
(
isStaffMockMode
(
'scene'
))
{
return
{
return
{
...
@@ -138,10 +146,12 @@ async function fetchSceneAdapter(params = {}) {
...
@@ -138,10 +146,12 @@ async function fetchSceneAdapter(params = {}) {
}
}
}
}
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedScene
(
staffUuid
,
merchantId
,
resolvedSceneType
)
const
cached
=
getCachedScene
(
staffUuid
,
merchantId
,
resolvedSceneType
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
{
getUserScene
}
=
getDynamicDailyReportApi
()
const
{
getUserScene
}
=
getDynamicDailyReportApi
()
const
result
=
await
getUserScene
({
const
result
=
await
getUserScene
({
...
@@ -160,9 +170,12 @@ async function fetchSceneAdapter(params = {}) {
...
@@ -160,9 +170,12 @@ async function fetchSceneAdapter(params = {}) {
/**
/**
* 拉取门店经营品牌(mock 或 carBrandApi + brandCache,key=merchantId,切日期复用)
* 拉取门店经营品牌(mock 或 carBrandApi + brandCache,key=merchantId,切日期复用)
* @param {Object} [params={}] merchantId
* @param {Object} [params={}] merchantId
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Array}>}
* @returns {Promise<{code: number, message: string, data: Array}>}
*/
*/
async
function
fetchBrandAdapter
(
params
=
{})
{
async
function
fetchBrandAdapter
(
params
=
{},
options
=
{})
{
const
{
skipCacheRead
=
false
}
=
options
const
runFetch
=
async
()
=>
{
const
runFetch
=
async
()
=>
{
const
fetcher
=
const
fetcher
=
fetchMerchantOperatingBrandListOverride
||
fetchMerchantOperatingBrandListOverride
||
...
@@ -186,10 +199,12 @@ async function fetchBrandAdapter(params = {}) {
...
@@ -186,10 +199,12 @@ async function fetchBrandAdapter(params = {}) {
}
}
const
{
merchantId
}
=
params
const
{
merchantId
}
=
params
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedBrand
(
merchantId
)
const
cached
=
getCachedBrand
(
merchantId
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
result
=
await
runFetch
()
const
result
=
await
runFetch
()
setCachedBrand
(
merchantId
,
result
)
setCachedBrand
(
merchantId
,
result
)
return
result
return
result
...
...
packageDynamicForm/api/storeDailyReport.js
View file @
099eeba
...
@@ -600,6 +600,44 @@ async function fetchMonthlyPendingCount({ merchantId, reportDate, sceneType } =
...
@@ -600,6 +600,44 @@ async function fetchMonthlyPendingCount({ merchantId, reportDate, sceneType } =
return
normalizeMonthlyPendingCountResponse
(
result
)
return
normalizeMonthlyPendingCountResponse
(
result
)
}
}
/**
* 首屏渲染后后台刷新 brand/scene/schema 进程内缓存(不更新当前页 UI)
* @param {Object} [options={}]
* @param {Object} [options.userContext] 用户上下文(merchantId、staffUuid 等)
* @param {string} [options.baseSceneCode] 门店场景编码
* @param {number|string} [options.reportTemplateId] 模板 ID
* @returns {Promise<void>}
*/
async
function
revalidateCachedMetadata
({
userContext
=
{},
baseSceneCode
,
reportTemplateId
}
=
{})
{
if
(
isStoreMockMode
(
'brand'
)
&&
isStoreMockMode
(
'scene'
)
&&
isStoreMockMode
(
'schema'
)
)
{
return
}
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
}
=
userContext
if
(
!
merchantId
)
{
return
}
const
refreshOptions
=
{
skipCacheRead
:
true
}
await
Promise
.
allSettled
([
fetchBrandAdapter
({
merchantId
},
refreshOptions
),
fetchSceneAdapter
(
{
merchantId
,
shopMerchantId
,
staffUuid
,
phone
,
sceneType
},
refreshOptions
),
fetchSchemaRootAdapter
(
{
reportTemplateId
,
baseSceneCode
,
merchantId
},
refreshOptions
)
])
}
module
.
exports
=
{
module
.
exports
=
{
fetchMerchantBrandIds
,
fetchMerchantBrandIds
,
fetchMerchantScene
,
fetchMerchantScene
,
...
@@ -613,5 +651,6 @@ module.exports = {
...
@@ -613,5 +651,6 @@ module.exports = {
saveDraftForm
,
saveDraftForm
,
normalizeDetailResponse
,
normalizeDetailResponse
,
buildPageContextFromSources
,
buildPageContextFromSources
,
normalizeUserInfo
normalizeUserInfo
,
revalidateCachedMetadata
}
}
packageDynamicForm/api/storeDailyReportAdapters.js
View file @
099eeba
...
@@ -100,22 +100,27 @@ async function fetchDetailAdapter(params = {}) {
...
@@ -100,22 +100,27 @@ async function fetchDetailAdapter(params = {}) {
/**
/**
* 拉取门店 schema 根节点(mock fixture 或配置中心 + schemaCache)
* 拉取门店 schema 根节点(mock fixture 或配置中心 + schemaCache)
* @param {Object} [params={}] reportTemplateId、baseSceneCode、merchantId
* @param {Object} [params={}] reportTemplateId、baseSceneCode、merchantId
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Object}>}
* @returns {Promise<{code: number, message: string, data: Object}>}
*/
*/
async
function
fetchSchemaRootAdapter
(
params
=
{})
{
async
function
fetchSchemaRootAdapter
(
params
=
{}
,
options
=
{}
)
{
const
{
reportTemplateId
,
baseSceneCode
,
merchantId
}
=
params
const
{
reportTemplateId
,
baseSceneCode
,
merchantId
}
=
params
const
{
skipCacheRead
=
false
}
=
options
if
(
isStoreMockMode
(
'schema'
))
{
if
(
isStoreMockMode
(
'schema'
))
{
return
resolveSchemaRootResult
(
requireStoreSchemaTemplate
())
return
resolveSchemaRootResult
(
requireStoreSchemaTemplate
())
}
}
const
moduleUrl
=
DYNAMIC_FORM_TEMPLATE_MODULE
.
store
const
moduleUrl
=
DYNAMIC_FORM_TEMPLATE_MODULE
.
store
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedSchema
(
moduleUrl
,
baseSceneCode
)
const
cached
=
getCachedSchema
(
moduleUrl
,
baseSceneCode
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
result
=
await
fetchConfigCenterTemplate
(
moduleUrl
)
const
result
=
await
fetchConfigCenterTemplate
(
moduleUrl
,
{
useCache
:
!
skipCacheRead
}
)
const
resolved
=
resolveSchemaRootResult
(
result
.
data
)
const
resolved
=
resolveSchemaRootResult
(
result
.
data
)
setCachedSchema
(
moduleUrl
,
baseSceneCode
,
resolved
)
setCachedSchema
(
moduleUrl
,
baseSceneCode
,
resolved
)
return
resolved
return
resolved
...
@@ -124,11 +129,14 @@ async function fetchSchemaRootAdapter(params = {}) {
...
@@ -124,11 +129,14 @@ async function fetchSchemaRootAdapter(params = {}) {
/**
/**
* 拉取门店场景列表(mock 或 findByMerchantIdAndSceneType + sceneCache)
* 拉取门店场景列表(mock 或 findByMerchantIdAndSceneType + sceneCache)
* @param {Object} [params={}] merchantId、shopMerchantId、sceneType
* @param {Object} [params={}] merchantId、shopMerchantId、sceneType
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Array}>}
* @returns {Promise<{code: number, message: string, data: Array}>}
*/
*/
async
function
fetchSceneAdapter
(
params
=
{})
{
async
function
fetchSceneAdapter
(
params
=
{}
,
options
=
{}
)
{
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
sceneType
}
=
params
const
{
merchantId
,
shopMerchantId
,
staffUuid
,
sceneType
}
=
params
const
resolvedSceneType
=
resolveSceneType
({
sceneType
})
const
resolvedSceneType
=
resolveSceneType
({
sceneType
})
const
{
skipCacheRead
=
false
}
=
options
if
(
isStoreMockMode
(
'scene'
))
{
if
(
isStoreMockMode
(
'scene'
))
{
return
{
return
{
...
@@ -138,10 +146,12 @@ async function fetchSceneAdapter(params = {}) {
...
@@ -138,10 +146,12 @@ async function fetchSceneAdapter(params = {}) {
}
}
}
}
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedScene
(
staffUuid
,
merchantId
,
resolvedSceneType
)
const
cached
=
getCachedScene
(
staffUuid
,
merchantId
,
resolvedSceneType
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
{
findSceneByMerchantIdAndSceneType
}
=
getDynamicDailyReportApi
()
const
{
findSceneByMerchantIdAndSceneType
}
=
getDynamicDailyReportApi
()
const
result
=
await
findSceneByMerchantIdAndSceneType
({
const
result
=
await
findSceneByMerchantIdAndSceneType
({
...
@@ -159,9 +169,12 @@ async function fetchSceneAdapter(params = {}) {
...
@@ -159,9 +169,12 @@ async function fetchSceneAdapter(params = {}) {
/**
/**
* 拉取门店经营品牌(mock 或 carBrandApi + brandCache,key=merchantId,同门店切日期不重复请求)
* 拉取门店经营品牌(mock 或 carBrandApi + brandCache,key=merchantId,同门店切日期不重复请求)
* @param {Object} [params={}] merchantId
* @param {Object} [params={}] merchantId
* @param {Object} [options={}]
* @param {boolean} [options.skipCacheRead=false] 为 true 时跳过读缓存但仍写回(后台 SWR 刷新)
* @returns {Promise<{code: number, message: string, data: Array}>}
* @returns {Promise<{code: number, message: string, data: Array}>}
*/
*/
async
function
fetchBrandAdapter
(
params
=
{})
{
async
function
fetchBrandAdapter
(
params
=
{},
options
=
{})
{
const
{
skipCacheRead
=
false
}
=
options
const
runFetch
=
async
()
=>
{
const
runFetch
=
async
()
=>
{
const
fetcher
=
const
fetcher
=
fetchMerchantOperatingBrandListOverride
||
fetchMerchantOperatingBrandListOverride
||
...
@@ -185,10 +198,12 @@ async function fetchBrandAdapter(params = {}) {
...
@@ -185,10 +198,12 @@ async function fetchBrandAdapter(params = {}) {
}
}
const
{
merchantId
}
=
params
const
{
merchantId
}
=
params
if
(
!
skipCacheRead
)
{
const
cached
=
getCachedBrand
(
merchantId
)
const
cached
=
getCachedBrand
(
merchantId
)
if
(
cached
)
{
if
(
cached
)
{
return
cached
return
cached
}
}
}
const
result
=
await
runFetch
()
const
result
=
await
runFetch
()
setCachedBrand
(
merchantId
,
result
)
setCachedBrand
(
merchantId
,
result
)
return
result
return
result
...
...
packageDynamicForm/docs/ARCHITECTURE.md
View file @
099eeba
...
@@ -133,6 +133,8 @@ sequenceDiagram
...
@@ -133,6 +133,8 @@ sequenceDiagram
| schemaCache | moduleUrl + baseSceneCode | 同场景 schema 复用 |
| schemaCache | moduleUrl + baseSceneCode | 同场景 schema 复用 |
| brandCache | merchantId | 切日期不重复打 merchant.info |
| brandCache | merchantId | 切日期不重复打 merchant.info |
首屏仍读缓存快速展示;
`applyEngineView`
后由页面
`scheduleMetadataCacheRevalidate`
空闲后台
`skipCacheRead`
刷新三缓存,
**不热更新当前页 UI**
(下次进页/切日期用新数据)。
三页各自
`*DailyReportCache.js`
;单测
`beforeEach`
需
`clear*DailyReportCache()`
。
三页各自
`*DailyReportCache.js`
;单测
`beforeEach`
需
`clear*DailyReportCache()`
。
## 相关单测模块
## 相关单测模块
...
...
packageDynamicForm/pages/behaviors/dailyReportPageMethods.js
View file @
099eeba
...
@@ -175,6 +175,38 @@ const dailyReportPageMethods = {
...
@@ -175,6 +175,38 @@ const dailyReportPageMethods = {
...
pageContext
,
...
pageContext
,
initialValues
:
initialValues
||
{}
initialValues
:
initialValues
||
{}
})
})
},
/**
* 首屏 applyEngineView 后,空闲时后台刷新 brand/scene/schema 缓存(不热更新 UI)
* @param {Object} api 日报 API 门面(须含 revalidateCachedMetadata)
* @param {Object} params userContext、baseSceneCode、reportTemplateId
* @param {number} loadSeq 当前 loadSeq,过期则放弃
* @returns {void}
*/
scheduleMetadataCacheRevalidate
(
api
,
params
,
loadSeq
)
{
if
(
this
.
_metadataRevalidateTimer
)
{
clearTimeout
(
this
.
_metadataRevalidateTimer
)
this
.
_metadataRevalidateTimer
=
null
}
const
run
=
()
=>
{
this
.
_metadataRevalidateTimer
=
null
if
(
this
.
isStaleLoad
(
loadSeq
))
{
return
}
if
(
!
api
||
typeof
api
.
revalidateCachedMetadata
!==
'function'
)
{
return
}
api
.
revalidateCachedMetadata
(
params
).
catch
(()
=>
{})
}
const
schedule
=
()
=>
{
this
.
_metadataRevalidateTimer
=
setTimeout
(
run
,
0
)
}
if
(
typeof
wx
!==
'undefined'
&&
typeof
wx
.
nextTick
===
'function'
)
{
wx
.
nextTick
(
schedule
)
}
else
{
schedule
()
}
}
}
}
}
...
...
packageDynamicForm/pages/negotiationDetail/negotiationDetail.js
View file @
099eeba
...
@@ -511,6 +511,15 @@ Page({
...
@@ -511,6 +511,15 @@ Page({
loadError
:
''
loadError
:
''
})
})
this
.
applyEngineView
(
finalViewState
,
{
structureChanged
:
true
})
this
.
applyEngineView
(
finalViewState
,
{
structureChanged
:
true
})
this
.
scheduleMetadataCacheRevalidate
(
negotiationApi
,
{
userContext
,
baseSceneCode
:
pageContext
.
baseSceneCode
,
reportTemplateId
:
this
.
reportTemplateId
},
seq
)
if
(
this
.
data
.
isTodayReport
)
{
if
(
this
.
data
.
isTodayReport
)
{
this
.
refreshTodayPlanCustomerCount
()
this
.
refreshTodayPlanCustomerCount
()
}
else
{
}
else
{
...
...
packageDynamicForm/pages/staffDailyReport/staffDailyReport.js
View file @
099eeba
...
@@ -385,6 +385,15 @@ Page({
...
@@ -385,6 +385,15 @@ Page({
loadError
:
''
loadError
:
''
})
})
this
.
applyEngineView
(
finalViewState
,
{
structureChanged
:
true
})
this
.
applyEngineView
(
finalViewState
,
{
structureChanged
:
true
})
this
.
scheduleMetadataCacheRevalidate
(
staffDailyApi
,
{
userContext
,
baseSceneCode
:
pageContext
.
baseSceneCode
,
reportTemplateId
:
this
.
reportTemplateId
},
seq
)
}
catch
(
error
)
{
}
catch
(
error
)
{
if
(
this
.
isStaleLoad
(
seq
))
return
if
(
this
.
isStaleLoad
(
seq
))
return
console
.
error
(
error
)
console
.
error
(
error
)
...
...
packageDynamicForm/pages/storeDailyReport/storeDailyReport.js
View file @
099eeba
...
@@ -438,6 +438,15 @@ Page({
...
@@ -438,6 +438,15 @@ Page({
loadError
:
''
loadError
:
''
})
})
this
.
applyEngineView
(
finalViewState
,
{
structureChanged
:
true
})
this
.
applyEngineView
(
finalViewState
,
{
structureChanged
:
true
})
this
.
scheduleMetadataCacheRevalidate
(
storeDailyApi
,
{
userContext
,
baseSceneCode
:
pageContext
.
baseSceneCode
,
reportTemplateId
:
this
.
reportTemplateId
},
seq
)
await
this
.
applyMonthlyPendingCountIfNeeded
(
seq
)
await
this
.
applyMonthlyPendingCountIfNeeded
(
seq
)
await
this
.
applyStoreStaffCountIfNeeded
(
seq
)
await
this
.
applyStoreStaffCountIfNeeded
(
seq
)
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
packageDynamicForm/tests/staffDailyReportAdapters.test.mjs
View file @
099eeba
...
@@ -346,6 +346,66 @@ describe('staffDailyReportAdapters', () => {
...
@@ -346,6 +346,66 @@ describe('staffDailyReportAdapters', () => {
}
}
})
})
it('IT-STAFF-CACHE-REVALIDATE-001: skipCacheRead forces network and updates brand cache', async () => {
const original = STAFF_DAILY_API_SWITCH.brand
STAFF_DAILY_API_SWITCH.brand = 'real'
let callCount = 0
let version = 1
adapters.__setFetchMerchantOperatingBrandList(async () => {
callCount += 1
const name = version === 1 ? '岚图汽车' : '岚图汽车新版'
version += 1
return {
code: 0,
message: 'ok',
data: [
{
id: 30671,
name,
brandId: 30671,
firstBrandId: 3067
}
]
}
})
try {
const res1 = await adapters.fetchBrandAdapter({ merchantId: 'm1' })
const res2 = await adapters.fetchBrandAdapter(
{ merchantId: 'm1' },
{ skipCacheRead: true }
)
const res3 = await adapters.fetchBrandAdapter({ merchantId: 'm1' })
assert.equal(callCount, 2)
assert.equal(res1.data[0].name, '岚图汽车')
assert.equal(res2.data[0].name, '岚图汽车新版')
assert.equal(res3.data[0].name, '岚图汽车新版')
} finally {
adapters.__setFetchMerchantOperatingBrandList(null)
STAFF_DAILY_API_SWITCH.brand = original
}
})
it('IT-STAFF-CACHE-REVALIDATE-002: skipCacheRead bypasses schema and config center cache', async () => {
const original = STAFF_DAILY_API_SWITCH.schema
STAFF_DAILY_API_SWITCH.schema = 'real'
let calls = 0
__setConfigCenterRequest(() => {
calls += 1
return Promise.resolve({
data: { 0: { key: `F${calls}`, type: 'radio', label: 'x' } }
})
})
try {
const params = { reportTemplateId: 10001, baseSceneCode: 100101, merchantId: 'm1' }
await adapters.fetchSchemaRootAdapter(params)
await adapters.fetchSchemaRootAdapter(params, { skipCacheRead: true })
assert.equal(calls, 2)
} finally {
__setConfigCenterRequest(null)
STAFF_DAILY_API_SWITCH.schema = original
}
})
it('fetchWeeklyAdapter real mode uses dailyReportWeeklyList', async () => {
it('fetchWeeklyAdapter real mode uses dailyReportWeeklyList', async () => {
const original = STAFF_DAILY_API_SWITCH.weekly
const original = STAFF_DAILY_API_SWITCH.weekly
STAFF_DAILY_API_SWITCH.weekly = 'real'
STAFF_DAILY_API_SWITCH.weekly = 'real'
...
...
packageDynamicForm/tests/storeDailyReportAdapters.test.mjs
View file @
099eeba
...
@@ -256,6 +256,59 @@ describe('storeDailyReportAdapters', () => {
...
@@ -256,6 +256,59 @@ describe('storeDailyReportAdapters', () => {
}
}
})
})
it('IT-STORE-CACHE-REVALIDATE-001: skipCacheRead forces network and updates brand cache', async () => {
const original = STORE_DAILY_API_SWITCH.brand
STORE_DAILY_API_SWITCH.brand = 'real'
let callCount = 0
let version = 1
adapters.__setFetchMerchantOperatingBrandList(async () => {
callCount += 1
const name = version === 1 ? 'AITO' : 'AITO新版'
version += 1
return {
code: 0,
message: 'ok',
data: [{ id: 34541, name, brandId: 34541, firstBrandId: 3454 }]
}
})
try {
const res1 = await adapters.fetchBrandAdapter({ merchantId: 'store-1' })
const res2 = await adapters.fetchBrandAdapter(
{ merchantId: 'store-1' },
{ skipCacheRead: true }
)
const res3 = await adapters.fetchBrandAdapter({ merchantId: 'store-1' })
assert.equal(callCount, 2)
assert.equal(res1.data[0].name, 'AITO')
assert.equal(res2.data[0].name, 'AITO新版')
assert.equal(res3.data[0].name, 'AITO新版')
} finally {
adapters.__setFetchMerchantOperatingBrandList(null)
STORE_DAILY_API_SWITCH.brand = original
}
})
it('IT-STORE-CACHE-REVALIDATE-002: skipCacheRead bypasses schema and config center cache', async () => {
const original = STORE_DAILY_API_SWITCH.schema
STORE_DAILY_API_SWITCH.schema = 'real'
let calls = 0
__setConfigCenterRequest(() => {
calls += 1
return Promise.resolve({
data: { 0: { key: `F${calls}`, type: 'radio', label: 'x' } }
})
})
try {
const params = { reportTemplateId: 10002, baseSceneCode: 110201, merchantId: 'm1' }
await adapters.fetchSchemaRootAdapter(params)
await adapters.fetchSchemaRootAdapter(params, { skipCacheRead: true })
assert.equal(calls, 2)
} finally {
__setConfigCenterRequest(null)
STORE_DAILY_API_SWITCH.schema = original
}
})
it('IT-NEG-DETAIL-MOCK-001: fetchDetailAdapter mock mode returns empty detail without detail.get', async () => {
it('IT-NEG-DETAIL-MOCK-001: fetchDetailAdapter mock mode returns empty detail without detail.get', async () => {
const original = NEGOTIATION_DAILY_API_SWITCH.detail
const original = NEGOTIATION_DAILY_API_SWITCH.detail
NEGOTIATION_DAILY_API_SWITCH.detail = 'mock'
NEGOTIATION_DAILY_API_SWITCH.detail = 'mock'
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment