You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

98 lines
2.7 KiB

var formateRichText = function(str) {
if (!str) {
return ""; // 正确:函数内部的return
}
// 处理img标签
var reg = getRegExp("<img", "g");
str = str.replace(reg, '<img class="sz-xcx-fwb-img" style="width:100%!important;height:auto!important;"');
reg = getRegExp("<IMG", "g");
str = str.replace(reg, '<img class="sz-xcx-fwb-img" style="width:100%!important;height:auto!important;"');
// widthheight
reg = getRegExp('width="[^"]*"', "gi");
str = str.replace(reg, "");
reg = getRegExp('height="[^"]*"', "gi");
str = str.replace(reg, "");
// style
reg = getRegExp('width:[^;]+;', "gi");
str = str.replace(reg, "");
reg = getRegExp('height:[^;]+;', "gi");
str = str.replace(reg, "");
reg = getRegExp('width:[^;]+', "gi");
str = str.replace(reg, "");
reg = getRegExp('height:[^;]+', "gi");
str = str.replace(reg, "");
//
reg = getRegExp("&nbsp;", "g");
str = str.replace(reg, '<span style="width: 8rpx;display: inline-block;"></span>');
reg = getRegExp("section", "g");
str = str.replace(reg, "div");
reg = getRegExp("↵", "g");
str = str.replace(reg, "<br />");
return str;
};
var gotoUrl = function(item){
var str = "/pages/info/"
if(item.frontShowModel=='multisku'){
str += "skuProductInfo"
}
else {
str += "productInfo"
}
str += "/index?id="+item.id;
return str;
}
// 价格日历显示返回
var showAllSeldDate = function (date, index,today,tomorrow,afterTom) {
// return date.substring(5, 10)
console.log('tool的',date,today,tomorrow,afterTom);
if (date == today) {
return '今天' + date.substring(5, 10)
}else if (date == tomorrow) {
return '明天' + date.substring(5, 10)
}else if (date == afterTom) {
return '后天' + date.substring(5, 10)
}else {
return date.substring(5, 10)
}
// switch (index) {
// case 0:
// return '今天' + date.substring(5, 10)
// case 1:
// return '明天' + date.substring(5, 10)
// case 2:
// return '后天' + date.substring(5, 10)
// default:
// return date.substring(5, 10)
// }
}
var toFix = function(value) {
return (value / 100).toFixed(2);
};
var filterTag = function (tagStr, splitStr = "," ,arrNum = 2, needArr=false) {
if (!tagStr) return ''; // 处理空值
var arr = tagStr.split(splitStr); // 拆分字符串
var limited = arr.slice(0, arrNum); // 只取前2个
if (needArr) {
return limited
}
return limited.join(' | '); // 拼接成字符串
};
module.exports = {
formateRichText:formateRichText,
gotoUrl:gotoUrl,
toFix:toFix,
showAllSeldDate:showAllSeldDate,
filterTag: filterTag
};