@netang/quasar 0.1.98 → 0.1.99
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/utils/getImage.js +46 -14
package/package.json
CHANGED
package/utils/getImage.js
CHANGED
|
@@ -20,13 +20,6 @@ export default function getImage(src, options) {
|
|
|
20
20
|
|
|
21
21
|
if (src) {
|
|
22
22
|
|
|
23
|
-
// 如果是字符串
|
|
24
|
-
if ($n_isValidString(src)) {
|
|
25
|
-
|
|
26
|
-
// 则按照逗号隔开转为数租
|
|
27
|
-
src = $n_split(src, ',')
|
|
28
|
-
}
|
|
29
|
-
|
|
30
23
|
// 如果为数组, 则获取第一个
|
|
31
24
|
if ($n_isValidArray(src)) {
|
|
32
25
|
src = src[0]
|
|
@@ -44,10 +37,35 @@ export default function getImage(src, options) {
|
|
|
44
37
|
}
|
|
45
38
|
}
|
|
46
39
|
|
|
40
|
+
// 如果是字符串
|
|
47
41
|
if ($n_isValidString(src)) {
|
|
48
42
|
|
|
49
|
-
//
|
|
50
|
-
if (/^(
|
|
43
|
+
// data: 或 blob: 开头的地址
|
|
44
|
+
if (/^(data:|blob:)/i.test(src)) {
|
|
45
|
+
return src
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 如果是 http(s):// 开头
|
|
49
|
+
if (/^(http(s)?:\/\/)/i.test(src)) {
|
|
50
|
+
src = $n_split(
|
|
51
|
+
src.replace(/,https:\/\//gi, '___https://')
|
|
52
|
+
.replace(/,http:\/\//gi, '___http://')
|
|
53
|
+
, '___'
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
// 否则则按照逗号隔开转为数组
|
|
57
|
+
} else {
|
|
58
|
+
src = $n_split(src, ',')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 如果为数组, 则获取第一个
|
|
62
|
+
if ($n_isValidArray(src)) {
|
|
63
|
+
src = src[0]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// http(s):// 开头的地址
|
|
67
|
+
// /^(http(s)?:\/\/|data:|blob:)/i.test(src)
|
|
68
|
+
if (/^(http(s)?:\/\/)/i.test(src)) {
|
|
51
69
|
return src
|
|
52
70
|
}
|
|
53
71
|
|
|
@@ -63,8 +81,8 @@ export default function getImage(src, options) {
|
|
|
63
81
|
zoom,
|
|
64
82
|
} = options
|
|
65
83
|
|
|
66
|
-
//
|
|
67
|
-
options.w = 0
|
|
84
|
+
// 先设为最大宽度
|
|
85
|
+
options.w = maxWidth || 0
|
|
68
86
|
|
|
69
87
|
// 如果有宽度
|
|
70
88
|
if (w) {
|
|
@@ -86,7 +104,7 @@ export default function getImage(src, options) {
|
|
|
86
104
|
// 获取设备像素比
|
|
87
105
|
const devicePixelRatio = window.devicePixelRatio || 1
|
|
88
106
|
if (devicePixelRatio > 2) {
|
|
89
|
-
w *=
|
|
107
|
+
w *= (devicePixelRatio > 3 ? 3 : devicePixelRatio)
|
|
90
108
|
}
|
|
91
109
|
}
|
|
92
110
|
/* #endif */
|
|
@@ -98,7 +116,7 @@ export default function getImage(src, options) {
|
|
|
98
116
|
}
|
|
99
117
|
|
|
100
118
|
// 如果有最大宽度
|
|
101
|
-
if (maxWidth &&
|
|
119
|
+
if (maxWidth && w > maxWidth) {
|
|
102
120
|
w = maxWidth
|
|
103
121
|
}
|
|
104
122
|
|
|
@@ -121,25 +139,34 @@ export default function getImage(src, options) {
|
|
|
121
139
|
switch (type) {
|
|
122
140
|
|
|
123
141
|
// 七牛云
|
|
142
|
+
// 文档: https://developer.qiniu.com/dora/1279/basic-processing-images-imageview2
|
|
124
143
|
case 'qiniu':
|
|
125
144
|
// minio
|
|
126
145
|
case 'minio':
|
|
127
146
|
|
|
128
147
|
const {
|
|
129
148
|
compress,
|
|
149
|
+
mode,
|
|
130
150
|
w,
|
|
131
151
|
h,
|
|
132
152
|
q,
|
|
153
|
+
ignoreError,
|
|
133
154
|
format,
|
|
134
155
|
} = Object.assign({
|
|
135
156
|
// 是否压缩
|
|
136
157
|
compress: true,
|
|
158
|
+
// 模式
|
|
159
|
+
mode: '2',
|
|
137
160
|
// 宽
|
|
138
161
|
w: 0,
|
|
139
162
|
// 高
|
|
140
163
|
h: 0,
|
|
141
164
|
// 质量
|
|
142
165
|
q: 75,
|
|
166
|
+
// 是否忽略错误
|
|
167
|
+
// 主要针对图片兼容性的问题导致无法处理, 取值为 1 时, 则处理失败时返回原图
|
|
168
|
+
// 不设置此参数, 默认处理失败时返回错误信息
|
|
169
|
+
ignoreError: false,
|
|
143
170
|
// 格式
|
|
144
171
|
format: 'webp',
|
|
145
172
|
}, options)
|
|
@@ -148,7 +175,7 @@ export default function getImage(src, options) {
|
|
|
148
175
|
if (compress) {
|
|
149
176
|
|
|
150
177
|
// 裁剪图片方式
|
|
151
|
-
src +=
|
|
178
|
+
src += `?imageView2/${mode}`
|
|
152
179
|
|
|
153
180
|
// 质量
|
|
154
181
|
if (q) {
|
|
@@ -165,6 +192,11 @@ export default function getImage(src, options) {
|
|
|
165
192
|
src += '/h/' + h
|
|
166
193
|
}
|
|
167
194
|
|
|
195
|
+
// 是否忽略错误
|
|
196
|
+
if (ignoreError) {
|
|
197
|
+
src += '/ignore-error/1'
|
|
198
|
+
}
|
|
199
|
+
|
|
168
200
|
// 格式
|
|
169
201
|
if (format) {
|
|
170
202
|
src += '/format/' + format
|