/** * 生成实时压缩图片地址 * */ export function imgResize(_imgUrl, _width, _height, _crop, _enlarge, _qulity) { if (!_imgUrl) return null; _crop = _crop || 0; _enlarge = _enlarge || false; if (_width >= 300) { _qulity = _qulity || 95; } else { _qulity = _qulity || 90; } //LOFTER-11583: 从网易摄影导入的图片,在dashboard转载时,页面不能正常显示图片,不正确 //提取_imgUrl中真正的图片地址(剔除http://imgsize.ph.126.net/) if (_imgUrl.toLowerCase().indexOf('http://imgsize.ph.126.net') >= 0) { _imgUrl = p._$getParmvalByKey(_imgUrl, 'imgurl', '?') || ''; var _index = _imgUrl.lastIndexOf('_'); if (!!_imgUrl && _index >= 0) { _imgUrl = _imgUrl.substring(0, _index); } if (!_imgUrl) return null; } if (!_width || _width < 0) return _imgUrl; if (!_height || _height < 0) _height = _width; _qulity = parseInt(_qulity) || 0; if (_qulity > 100) _qulity = 100; if (_imgUrl.indexOf('nos.netease.com') > 0 || _imgUrl.indexOf('nosdn.127.net') > 0 || _imgUrl.indexOf('nosdn0.126.net') > 0) { var resized = _imgUrl; var imageview = 'thumbnail=' + _width + (_crop == 1 ? 'y' : 'x') + _height + (!!_enlarge ? '&enlarge=1' : ''); if (/\.gif/.test(_imgUrl)) { if (_width < 500) { imageview += '&type=jpg'; } } else if(/\.png/.test(_imgUrl)){ //LOFTER-7537: PC端发布多图时解决PNG图片预览问题 imageview += '&type=png'; } else { imageview += '&type=jpg'; } if (/thumbnail=\d+[xyz]\d+/.test(_imgUrl)) { resized = _imgUrl.replace(/thumbnail=\d+[xyz]\d+/, imageview); } else if(/imageView/.test(_imgUrl)){ resized = _imgUrl.replace(/imageView/, 'imageView&' + imageview); }else if(/\?/.test(_imgUrl) && /#/.test(_imgUrl)){ resized = _imgUrl.replace(/#/, '&imageView&' + imageview + "#"); }else if(/\?/.test(_imgUrl) && !/#/.test(_imgUrl)){ resized = _imgUrl + '&imageView&' + imageview; }else{ resized = _imgUrl + '?imageView&' + imageview; } //LOFTER-21319:修复专题中裁剪nos图片引起的水印大小异常 if (/watermark&/.test(resized)) { var _dx = 8; var _dy = 10; var _fontsize = 240; if (_width >= 1680) { _dx = 32; _dy = 36; _fontsize = 680; } else if (_width > 500) { _dx = 16; _dy = 20; _fontsize = 360; } else if (_width >= 300) { _dx = 8; _dy = 10; _fontsize = 240; } resized = resized.replace(/dx=\d+/, 'dx=' + _dx); resized = resized.replace(/dy=\d+/, 'dy=' + _dy); resized = resized.replace(/fontsize=\d+/, 'fontsize=' + _fontsize); } return resized; } else { return 'http://imgsize.ph.126.net/?' + (!!_enlarge ? 'enlarge=true&' : '') + 'imgurl=' + _imgUrl + '_' + _width + 'x' + _height + 'x' + _crop + (_qulity > 0 ? ('x' + _qulity) : '') + '.jpg'; } }; // nos图片剪裁 // opts: w, h, q export function getNosThumbImg (url, opts) { if (url.indexOf('?imageView') >= 0) { return url; } url += '?imageView' Object.keys(opts).forEach((name)=>{ return url += '&' + name + '=' + opts[name] }) return url } const formatTime = function (value) { var date = new Date(parseInt(value)); let year = date.getFullYear(); let month = date.getMonth() + 1; let day = date.getDate(); return `${year}-${String(month).length < 2 ? '0' + month : month}-${String(day).length < 2 ? '0' + day : day}`; } /** * 乐乎市集优惠券显示数据映射 */ const getCouponData4Show = function (_coupon, _supplierId) { var _dataMap = {}; //优惠额度 if (_coupon.type == 2) { _dataMap.facevalue = _coupon.preferential + '折'; } else { _dataMap.facevalue = '¥' + _coupon.preferential; } //使用门槛 var _doorsill = ''; if (_coupon.rule > 0) { if (_coupon.unitType == 2) { _doorsill = '满' + _coupon.rule + '件'; _dataMap.doorsill = '满' + _coupon.rule + '件可用'; } else { _doorsill = '满¥' + _coupon.rule; _dataMap.doorsill = '满¥' + _coupon.rule + '可用'; } } else { _dataMap.doorsill = '无门槛'; } //券的核心内容 if (_coupon.rule <= 0 && (_coupon.type == 1 || _coupon.type == 4)) { //无门槛减 _dataMap.corecnt = '立减' + _coupon.preferential; } else if (_coupon.rule <= 0 && _coupon.type == 2) { //无门槛折 _dataMap.corecnt = '立享' + _coupon.preferential + '折'; } else if ((_coupon.type == 1 || _coupon.type == 4) && _coupon.unitType == 1) { //满额减 _dataMap.corecnt = '满' + _coupon.rule + '减' + _coupon.preferential; } else if (_coupon.type == 1 && _coupon.unitType == 2) { //满件减 _dataMap.corecnt = '满' + _coupon.rule + '件减' + _coupon.preferential + '元'; } else if (_coupon.type == 2 && _coupon.unitType == 1) { //满额折 _dataMap.corecnt = '满' + _coupon.rule + '享' + _coupon.preferential + '折'; } else if (_coupon.type == 2 && _coupon.unitType == 2) { //满件折 _dataMap.corecnt = '满' + _coupon.rule + '件享' + _coupon.preferential + '折'; } //名称 _dataMap.name = _coupon.name||_coupon.couponName; _dataMap.couponId = _coupon.id||_coupon.couponId; //有效期 _dataMap.startTime = formatTime(_coupon.startTime); _dataMap.endTime = formatTime(_coupon.endTime); //更多活动商品链接 _dataMap.pdlink = '/market/fe/html/addOnProduct.html?couponId=' +_coupon.couponId + '&supplierId=' + _supplierId; //剩余数量提醒 _dataMap.isShowStock = false; if (_coupon.showStock == 2) { //阀值展示 if (_coupon.stock <= _coupon.threshold) { _dataMap.isShowStock = true; } } else if (_coupon.showStock == 1) { //展示 _dataMap.isShowStock = true; } else { //不展示 } if (_dataMap.isShowStock) { if (_coupon.stock < 100) { _dataMap.stocktip = '仅剩' + _coupon.stock + '张' } else { _dataMap.stocktip = _coupon.stock + '张'; } } return _dataMap; } const getPreferentialText = function (couponInfo) { if(couponInfo.type == -100){ // 淘客优惠券 return couponInfo.name } else if ((couponInfo.type == 1 || couponInfo.type == 4) && couponInfo.rule == 0) {//无门槛减 return `立减${couponInfo.preferential}` } else if (couponInfo.type == 2 && couponInfo.rule == 0) {//无门槛折 return `立享${couponInfo.preferential}折` } else if ((couponInfo.type == 1 || couponInfo.type == 4) && couponInfo.unitType == 1) {//满额减 return `满${couponInfo.rule}减${couponInfo.preferential}` } else if (couponInfo.type == 1 && couponInfo.unitType == 2) {//满件减 return `满${couponInfo.rule}件减${couponInfo.preferential}`; } else if (couponInfo.type == 2 && couponInfo.unitType == 1) {//满额折 return `满${couponInfo.rule}享${couponInfo.preferential}折` } else if (couponInfo.type == 2 && couponInfo.unitType == 2) {//满件折 return `满${couponInfo.rule}件享${couponInfo.preferential}折` } } const getCouponFaceValue = function (coupon) { if (coupon.type == 2) { return `${coupon.preferential}折`; } else { return `¥${coupon.preferential}`; } } const couponDateFormat = formatTime; export {getCouponData4Show, getPreferentialText, getCouponFaceValue, couponDateFormat};