Files
dukang/apps/mini-user/src/lib/brand-assets.ts
T
jacy cc0c0a6ef8 feat(fulfillment): 同城运费与路由修复,配送单展示商品用户地址
同城 MANUAL/ZZXFX 按小飞侠价规计费,路由查询回退仓配凭证;HQ 配送单补商品、用户和收货地址。门店核销回跳与小程序核销码一并带上。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-25 21:12:36 +08:00

77 lines
2.4 KiB
TypeScript

import {
BRAND_LOGO_MARK_URL,
BRAND_LOGO_URL,
BRAND_LOGO_WIDE_URL,
CUSTOMER_SERVICE_PHONE,
CUSTOMER_SERVICE_WECOM_URL,
QUALIFICATION_DISCLOSURE_URL,
type ClientRuntimeConfig,
} from '@dukang/shared-types';
import { fetchClientConfig } from './pay-wechat';
export type BrandAssets = {
brandLogoUrl: string;
brandLogoWideUrl: string;
brandLogoMarkUrl: string;
qualificationDisclosureUrl: string;
customerServicePhone: string;
customerServiceWecomUrl: string;
wecomCorpId: string;
};
const FALLBACK: BrandAssets = {
brandLogoUrl: BRAND_LOGO_URL,
brandLogoWideUrl: BRAND_LOGO_WIDE_URL,
brandLogoMarkUrl: BRAND_LOGO_MARK_URL,
qualificationDisclosureUrl: QUALIFICATION_DISCLOSURE_URL,
customerServicePhone: CUSTOMER_SERVICE_PHONE,
customerServiceWecomUrl: CUSTOMER_SERVICE_WECOM_URL,
wecomCorpId: '',
};
let cached: BrandAssets | null = null;
let inflight: Promise<BrandAssets> | null = null;
function fromConfig(config: ClientRuntimeConfig | null | undefined): BrandAssets {
return {
brandLogoUrl: config?.brandLogoUrl?.trim() || FALLBACK.brandLogoUrl,
brandLogoWideUrl: config?.brandLogoWideUrl?.trim() || FALLBACK.brandLogoWideUrl,
brandLogoMarkUrl: config?.brandLogoMarkUrl?.trim() || FALLBACK.brandLogoMarkUrl,
qualificationDisclosureUrl:
config?.qualificationDisclosureUrl?.trim() || FALLBACK.qualificationDisclosureUrl,
customerServicePhone: config?.customerServicePhone?.trim() || FALLBACK.customerServicePhone,
customerServiceWecomUrl:
config?.customerServiceWecomUrl?.trim() || FALLBACK.customerServiceWecomUrl,
wecomCorpId: config?.wecomCorpId?.trim() || FALLBACK.wecomCorpId,
};
}
/** 同步读取最近一次缓存(未拉取前返回代码默认常量) */
export function getBrandAssetsSync(): BrandAssets {
return cached ?? FALLBACK;
}
/** 拉取 /common/client-config 中的品牌与客服配置并缓存 */
export async function loadBrandAssets(force = false): Promise<BrandAssets> {
if (!force && cached) return cached;
if (!force && inflight) return inflight;
inflight = fetchClientConfig()
.then((cfg) => {
cached = fromConfig(cfg);
return cached;
})
.catch(() => {
cached = FALLBACK;
return cached;
})
.finally(() => {
inflight = null;
});
return inflight;
}
export function applyBrandFromClientConfig(config: ClientRuntimeConfig | null | undefined) {
cached = fromConfig(config);
return cached;
}