1 line
8.5 KiB
Plaintext
1 line
8.5 KiB
Plaintext
{"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 = size + '>'\r\n break\r\n case 'mfit':\r\n size = '!' + size + 'r'\r\n break\r\n case 'fill':\r\n // 会被转为 mfit\r\n break\r\n case 'fixed':\r\n size = size + '!'\r\n break\r\n }\r\n\r\n suffix = 'imageMogr2/thumbnail/' + size + crop_str + quality_str\r\n break\r\n }\r\n return url + '?' + suffix\r\n}\r\n\r\n/**\r\n * 裁剪区域格式转换\r\n *\r\n * @param string $type aliyun|qcloud|qiniu\r\n * @param string $gravity 统一的裁剪区域字符\r\n *\r\n * @return string\r\n */\r\nfunction gravityFormatMap(type, gravity) {\r\n const gravityFormat = {\r\n aliyun: {\r\n north_west: 'nw', // 左上\r\n north: 'north', // 中上\r\n north_east: 'ne', // 右上\r\n west: 'west', // 左中\r\n center: 'center', // 中部\r\n east: 'east', // 右中\r\n south_west: 'sw', // 左下\r\n south: 'south', // 中下\r\n south_east: 'se', // 右下\r\n },\r\n qcloud: {\r\n northwest: 'nw', // 左上\r\n north: 'north', // 中上\r\n northeast: 'ne', // 右上\r\n west: 'west', // 左中\r\n center: 'center', // 中部\r\n east: 'east', // 右中\r\n southwest: 'sw', // 左下\r\n south: 'south', // 中下\r\n southeast: 'se', // 右下\r\n },\r\n qiniu: {\r\n NorthWest: 'nw', // 左上\r\n North: 'north', // 中上\r\n NorthEast: 'ne', // 右上\r\n West: 'west', // 左中\r\n Center: 'center', // 中部\r\n East: 'east', // 右中\r\n SouthWest: 'sw', // 左下\r\n South: 'south', // 中下\r\n SouthEast: 'se', // 右下\r\n },\r\n }\r\n\r\n return gravityFormat[type][gravity]\r\n}\r\n"],"names":["$store","staticUrl"],"mappings":";;;AAGA,MAAM,MAAM,CAAC,MAAM,IAAI,SAAS,OAAO;AACrC,MAAI,CAAC;AAAK,WAAO;AACjB,MAAI,IAAI,QAAQ,MAAM,MAAM,GAAG;AAC7B,WAAO;AAAA,EACR;AACD,MAAI,WAAW,IAAI;AACjB,aAASA,kBAAM,OAAC,KAAK,EAAE,KAAK;AAAA,EAC7B;AACD,SAAO,SAAS;AAClB;AACA,MAAe,OAAA;AAAA;AAAA,EAEb;AAAA;AAAA,EAEA,OAAO,CAAC,MAAM,IAAI,WAAW;AAC3B,UAAM,IAAI,GAAG;AACb,WAAO,wBAAwB,KAAK,MAAM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