Commit 47af1f2b by 张立顺

Merge branch 'saas+v5.8.2' of http://192.168.3.233:8090/saas_plus/dj-car-boutiqu…

…e-work-wechat into SAAS+V5.8.2.1
2 parents 2b60ea74 90f4d11b
......@@ -2,7 +2,7 @@
import api from '~/pages/tabMine/api'
const app = getApp()
import constantData from '../../pages/constant/data'
import { withTabRefreshInFlight } from '../../packageEquity/services/tabRefreshService.js'
import { withTabRefreshInFlight } from '~/utils/tabRefreshService.js'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/mine/'
Component({
/**
......
/**
* 权益 Tab 子页(Tab1–4)刷新 in-flight 合并。
*
* 设计原则:
* - **每次** `show=true` 都会执行刷新(与 Tab0 对齐)
* - 仅合并同一 key 下同一 tick 的并发调用(如 observer + 其它入口叠加)
* - **不做 TTL**,切走再切回应重新请求
*
* @module packageEquity/services/tabRefreshService
*/
/** @type {Map<string, Promise<void>>} key → 进行中的刷新 */
const inFlightByKey = new Map()
/**
* 清空单测/调试用的 in-flight 状态。
*/
export function clearTabRefreshState() {
inFlightByKey.clear()
}
/**
* 在 in-flight 去重下执行子 Tab 刷新。
*
* @param {'quotation'|'equityList'|'materials'|'mine'} key - Tab 业务隔离键
* @param {() => Promise<void>|void} fn - 实际刷新函数(如 refreshQuotationTab)
* @returns {Promise<void>}
*/
export async function withTabRefreshInFlight(key, fn) {
if (inFlightByKey.has(key)) {
return inFlightByKey.get(key)
}
const promise = Promise.resolve()
.then(fn)
.finally(() => {
if (inFlightByKey.get(key) === promise) {
inFlightByKey.delete(key)
}
})
inFlightByKey.set(key, promise)
return promise
}
export { withTabRefreshInFlight, clearTabRefreshState } from '../../utils/tabRefreshService.js'
......@@ -3,7 +3,7 @@ import assert from 'node:assert/strict'
import {
withTabRefreshInFlight,
clearTabRefreshState
} from '../services/tabRefreshService.js'
} from '../../utils/tabRefreshService.js'
describe('tabRefreshService', () => {
beforeEach(() => {
......
/**
* Tab 子页刷新 in-flight 合并(主包共享,供各场景 TabBar 子页使用)。
*
* 设计原则:
* - **每次** `show=true` 都会执行刷新(与 Tab0 对齐)
* - 仅合并同一 key 下同一 tick 的并发调用(如 observer + 其它入口叠加)
* - **不做 TTL**,切走再切回应重新请求
*
* @module utils/tabRefreshService
*/
/** @type {Map<string, Promise<void>>} key → 进行中的刷新 */
const inFlightByKey = new Map()
/**
* 清空单测/调试用的 in-flight 状态。
*/
export function clearTabRefreshState() {
inFlightByKey.clear()
}
/**
* 在 in-flight 去重下执行子 Tab 刷新。
*
* @param {'quotation'|'equityList'|'materials'|'mine'} key - Tab 业务隔离键
* @param {() => Promise<void>|void} fn - 实际刷新函数(如 refreshQuotationTab)
* @returns {Promise<void>}
*/
export async function withTabRefreshInFlight(key, fn) {
if (inFlightByKey.has(key)) {
return inFlightByKey.get(key)
}
const promise = Promise.resolve()
.then(fn)
.finally(() => {
if (inFlightByKey.get(key) === promise) {
inFlightByKey.delete(key)
}
})
inFlightByKey.set(key, promise)
return promise
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!