acdr-ui/dist/dev/mp-weixin/sheep/url/index.js.map

1 line
8.5 KiB
Plaintext
Raw Normal View History

2024-09-19 07:20:14 +08:00
{"version":3,"file":"index.js","sources":["../../../../../src/sheep/url/index.js"],"sourcesContent":["import $store from '@/sheep/store'\r\nimport { staticUrl } from '@/sheep/config'\r\n\r\nconst cdn = (url = '', cdnurl = '') => {\r\n if (!url) return ''\r\n if (url.indexOf('http') === 0) {\r\n return url\r\n }\r\n if (cdnurl === '') {\r\n cdnurl = $store('app').info.cdnurl\r\n }\r\n return cdnurl + url\r\n}\r\nexport default {\r\n // 添加cdn域名前缀\r\n cdn,\r\n // 对象存储自动剪裁缩略图\r\n thumb: (url = '', params) => {\r\n url = cdn(url)\r\n return append_thumbnail_params(url, params)\r\n },\r\n // 静态资源地址\r\n static: (url = '', staticurl = '') => {\r\n if (staticurl === '') {\r\n staticurl = staticUrl\r\n }\r\n if (staticurl !== 'local') {\r\n url = cdn(url, staticurl)\r\n }\r\n return url\r\n },\r\n // css背景图片地址\r\n css: (url = '', staticurl = '') => {\r\n if (staticurl === '') {\r\n staticurl = staticUrl\r\n }\r\n if (staticurl !== 'local') {\r\n url = cdn(url, staticurl)\r\n }\r\n // #ifdef APP-PLUS\r\n if (staticurl === 'local') {\r\n url = plus.io.convertLocalFileSystemURL(url)\r\n }\r\n // #endif\r\n return `url(${url})`\r\n },\r\n}\r\n\r\n/**\r\n * 追加对象存储自动裁剪/压缩参数\r\n *\r\n * @return string\r\n */\r\nfunction append_thumbnail_params(url, params) {\r\n const filesystem = $store('app').info.filesystem\r\n if (filesystem === 'public') {\r\n return url\r\n }\r\n const width = params.width || '200' // 宽度\r\n const height = params.height || '200' // 高度\r\n let mode = params.mode || 'lfit' // 缩放模式\r\n const quality = params.quality || 90 // 压缩质量\r\n const gravity = params.gravity || 'center' // 剪裁质量\r\n let suffix = ''\r\n let crop_str = ''\r\n let quality_str = ''\r\n let size = width + 'x' + height\r\n switch (filesystem) {\r\n case 'aliyun':\r\n // 裁剪\r\n if (!gravity && gravity != 'center') {\r\n // 指定了裁剪区域\r\n mode = 'mfit'\r\n crop_str = '/crop,g_' + gravityFormatMap('aliyun', gravity) + ',w_' + width + ',h_' + height\r\n }\r\n\r\n // 质量压缩\r\n if (quality > 0 && quality < 100) {\r\n quality_str = '/quality,q_' + quality\r\n }\r\n\r\n // 缩放参数\r\n suffix = 'x-oss-process=image/resize,m_' + mode + ',w_' + width + ',h_' + height\r\n\r\n // 拼接裁剪和质量压缩\r\n suffix += crop_str + quality_str\r\n break\r\n case 'qcloud':\r\n let mode_str = 'thumbnail'\r\n if (mode == 'fill' || (!gravity && gravity != 'center')) {\r\n // 指定了裁剪区域\r\n mode_str = 'crop'\r\n mode = 'fill'\r\n crop_str = '/gravity/' + gravityFormatMap('qcloud', gravity)\r\n }\r\n\r\n // 质量压缩\r\n if (quality > 0 && quality < 100) {\r\n quality_str = '/rquality/' + quality\r\n }\r\n\r\n switch (mode) {\r\n case 'lfit':\r\n size = '' + size + '>'\r\n break\r\n case 'mfit':\r\n size = '!' + size + 'r'\r\n case 'fill':\r\n break\r\n case 'pad':\r\n size = size + '/pad/1'\r\n break\r\n case 'fixed':\r\n size = size + '!'\r\n break\r\n }\r\n\r\n suffix = 'imageMogr2/' + mode_str + '/' + size + crop_str + quality_str\r\n break\r\n case 'qiniu':\r\n if (mode == 'fill' || (!gravity && gravity != 'center')) {\r\n // 指定了裁剪区域,全部转为 mfit\r\n mode = 'mfit'\r\n crop_str = '/gravity/' + gravityFormatMap('qiniu', gravity) + '/crop/' + size\r\n }\r\n // 质量压缩\r\n if (quality > 0 && quality < 100) {\r\n quality_str = '/quality/' + quality\r\n }\r\n\r\n switch (mode) {\r\n case 'lfit':\r\n case 'pad': // 七牛不支持在缩放之后,尺寸不足时,填充背景色,所以这里和 lfit 模式一样\r\n size =