forked from gxwebsoft/mp-10550
优化下单流程
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user