Files
dukang/apps/h5-user/src/lib/customer-service.ts
T
jacy a2abbb6169 feat(v3.4.14): mini-user store UX, brand config, client settings
Store list/detail package flow, configurable WeChat mini brand assets and customer service, shop H5 home refresh.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 15:21:59 +08:00

44 lines
1.4 KiB
TypeScript

import { CUSTOMER_SERVICE_PHONE, CUSTOMER_SERVICE_WECOM_URL } from '@dukang/shared-types';
import { fetchClientConfig } from './pay-wechat';
import { isWechatEnv } from './weixin';
let cachedPhone = CUSTOMER_SERVICE_PHONE;
/** 企微客服链接:优先 Vite env,否则 shared-types 默认 */
export function getCustomerServiceWecomUrl(): string {
const fromEnv = import.meta.env.VITE_CS_WECOM_URL?.trim();
return fromEnv || CUSTOMER_SERVICE_WECOM_URL;
}
export function getCustomerServicePhone(): string {
return cachedPhone;
}
/** 从系统设置拉取客服电话(失败则保持默认常量) */
export async function loadCustomerServicePhone(): Promise<string> {
try {
const cfg = await fetchClientConfig();
const phone = cfg.customerServicePhone?.trim();
if (phone) cachedPhone = phone;
} catch {
/* keep fallback */
}
return cachedPhone;
}
/**
* 打开企业微信客服会话(须在微信内;需用户点击手势)。
* @returns true 已跳转;false 非微信环境已提示
*/
export function openWecomCustomerService(): boolean {
if (!isWechatEnv()) {
window.alert('请在微信中打开以联系在线客服');
return false;
}
window.location.href = getCustomerServiceWecomUrl();
return true;
}
/** @deprecated 请用 getCustomerServicePhone(),保留兼容旧引用 */
export { CUSTOMER_SERVICE_PHONE };