优化下单流程

This commit is contained in:
2025-07-30 00:40:38 +08:00
parent 11729876ca
commit 19fe9b4775
18 changed files with 8252 additions and 169 deletions

View File

@@ -89,3 +89,42 @@ export function showShareGuide() {
confirmText: '知道了'
});
}
/**
* 截取字符串,确保不超过指定的汉字长度
* @param text 原始文本
* @param maxLength 最大汉字长度默认30
* @returns 截取后的文本
*/
export function truncateText(text: string, maxLength: number = 30): string {
if (!text) return '';
// 如果长度不超过限制,直接返回
if (text.length <= maxLength) {
return text;
}
// 超过长度则截取
return text.substring(0, maxLength);
}
/**
* 生成订单标题
* @param goodsNames 商品名称数组
* @param maxLength 最大长度默认30
* @returns 订单标题
*/
export function generateOrderTitle(goodsNames: string[], maxLength: number = 30): string {
if (!goodsNames || goodsNames.length === 0) {
return '商品订单';
}
let title = '';
if (goodsNames.length === 1) {
title = goodsNames[0];
} else {
title = `${goodsNames[0]}${goodsNames.length}件商品`;
}
return truncateText(title, maxLength);
}