feat(mini-user): v3.5.10 同城配送提示可配置并支持换行

承运商 HTML 按收货市下发;textarea 回车在 C 端转成换行。含门店去掉分享按钮与小程序企微客服。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-25 14:29:48 +08:00
parent fed8ff3d3a
commit 797b20979d
29 changed files with 758 additions and 28 deletions
@@ -1,5 +1,9 @@
import { useEffect, useState } from 'react';
import { Button, Text } from '@tarojs/components';
import type { ReactNode } from 'react';
import { toast } from '../lib/api';
import { getBrandAssetsSync, loadBrandAssets } from '../lib/brand-assets';
import { openWecomCustomerServiceChat } from '../lib/wecom-cs';
export type ContactCsSessionContext = {
orderId?: string;
@@ -16,7 +20,7 @@ type ContactCsButtonProps = {
const isWeapp = process.env.TARO_ENV === 'weapp';
/** 组装 session-from(微信限制约 1000 字符) */
/** 组装 session-from(微信限制约 1000 字符;原生小程序客服兜底用 */
export function buildCsSessionFrom(session?: ContactCsSessionContext): string {
if (!session) return 'dukang|from=mini-user';
const parts = ['dukang'];
@@ -26,16 +30,59 @@ export function buildCsSessionFrom(session?: ContactCsSessionContext): string {
return parts.join('|');
}
function canOpenWecom(url: string, corpId: string) {
return !!url.trim() && !!corpId.trim();
}
/**
* 微信小程序客服入口(open-type=contact)。
* weapp 环境不渲染,由调用方走电话等兜底。
* C 端在线客服:
* - weapp 且已配置 CorpID + kfid:调起企业微信「微信客服」
* - weapp 未配 CorpID:回退 open-type=contact
* - H5:有 kfid 则打开企微客服链接
*/
export default function ContactCsButton({
className = '',
children = '联系在线客服',
session,
}: ContactCsButtonProps) {
if (!isWeapp) return null;
const [cs, setCs] = useState(() => getBrandAssetsSync());
useEffect(() => {
void loadBrandAssets().then(setCs);
}, []);
const wecomChatReady = canOpenWecom(cs.customerServiceWecomUrl, cs.wecomCorpId);
const wecomWebReady = !!cs.customerServiceWecomUrl.trim();
if (!isWeapp && !wecomWebReady) return null;
async function openWecom() {
try {
if (isWeapp && wecomChatReady) {
await openWecomCustomerServiceChat({
url: cs.customerServiceWecomUrl,
corpId: cs.wecomCorpId,
session,
});
return;
}
if (typeof window !== 'undefined' && cs.customerServiceWecomUrl) {
window.location.href = cs.customerServiceWecomUrl;
return;
}
toast('请在微信内打开后联系客服');
} catch (e) {
toast(e instanceof Error ? e.message : '无法打开客服');
}
}
if (wecomChatReady || (!isWeapp && wecomWebReady)) {
return (
<Button className={className} hoverClass="none" onClick={() => void openWecom()}>
{typeof children === 'string' ? <Text>{children}</Text> : children}
</Button>
);
}
return (
<Button