jufubao-base 1.0.12 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/getBusinessImageUrl.js +36 -0
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description 字符串转数字
|
|
5
|
+
* @param str {String} 字符串
|
|
6
|
+
* @returns {number} 返回数字
|
|
7
|
+
*/
|
|
8
|
+
function stringToNumber(str) {
|
|
9
|
+
let result = 0;
|
|
10
|
+
let len = str.length;
|
|
11
|
+
for (let i = 0; i < len; i++) {
|
|
12
|
+
result = result + str.charCodeAt(i) + i;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @description 全局获取图片全路径方法
|
|
20
|
+
* @param path
|
|
21
|
+
* @param size {String} 压缩比例,支持值:size1 - size8
|
|
22
|
+
* @returns {String}
|
|
23
|
+
*/
|
|
24
|
+
function getBusinessImageUrl(path, size = 'size8') {
|
|
25
|
+
if (Object.prototype.toString.call(path)!== '[object String]' || path === '') {
|
|
26
|
+
console.error('传入的路径(path)非字符串类型,请确认路径是否正确');
|
|
27
|
+
throw new Error('传入的路径(path)非字符串类型,请确认路径是否正确');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let index = stringToNumber(path) % 6;
|
|
31
|
+
let doMain = '//sandbox-img@index@.jufubao.cn/'.replace('@index@', index === 0 ? '': index);
|
|
32
|
+
let src = 'business/';
|
|
33
|
+
return `${doMain}${src}${path}?x-oss-process=style/${size}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default getBusinessImageUrl;
|