@netang/quasar 0.1.97 → 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/components/search-item/index.vue +0 -2
- package/package.json +1 -1
- package/utils/getImage.js +58 -15
- package/utils/uploader.js +1 -1
package/package.json
CHANGED
package/utils/getImage.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import $n_get from 'lodash/get'
|
|
1
2
|
import $n_has from 'lodash/has'
|
|
2
3
|
import $n_isString from 'lodash/isString'
|
|
3
4
|
|
|
@@ -6,6 +7,7 @@ import $n_isValidObject from '@netang/utils/isValidObject'
|
|
|
6
7
|
import $n_isValidString from '@netang/utils/isValidString'
|
|
7
8
|
import $n_isNumeric from '@netang/utils/isNumeric'
|
|
8
9
|
import $n_split from '@netang/utils/split'
|
|
10
|
+
import $n_slash from '@netang/utils/slash'
|
|
9
11
|
|
|
10
12
|
import $n_uploader from './uploader'
|
|
11
13
|
|
|
@@ -18,13 +20,6 @@ export default function getImage(src, options) {
|
|
|
18
20
|
|
|
19
21
|
if (src) {
|
|
20
22
|
|
|
21
|
-
// 如果是字符串
|
|
22
|
-
if ($n_isValidString(src)) {
|
|
23
|
-
|
|
24
|
-
// 则按照逗号隔开转为数租
|
|
25
|
-
src = $n_split(src, ',')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
23
|
// 如果为数组, 则获取第一个
|
|
29
24
|
if ($n_isValidArray(src)) {
|
|
30
25
|
src = src[0]
|
|
@@ -42,10 +37,35 @@ export default function getImage(src, options) {
|
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
39
|
|
|
40
|
+
// 如果是字符串
|
|
45
41
|
if ($n_isValidString(src)) {
|
|
46
42
|
|
|
47
|
-
//
|
|
48
|
-
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)) {
|
|
49
69
|
return src
|
|
50
70
|
}
|
|
51
71
|
|
|
@@ -61,8 +81,8 @@ export default function getImage(src, options) {
|
|
|
61
81
|
zoom,
|
|
62
82
|
} = options
|
|
63
83
|
|
|
64
|
-
//
|
|
65
|
-
options.w = 0
|
|
84
|
+
// 先设为最大宽度
|
|
85
|
+
options.w = maxWidth || 0
|
|
66
86
|
|
|
67
87
|
// 如果有宽度
|
|
68
88
|
if (w) {
|
|
@@ -84,7 +104,7 @@ export default function getImage(src, options) {
|
|
|
84
104
|
// 获取设备像素比
|
|
85
105
|
const devicePixelRatio = window.devicePixelRatio || 1
|
|
86
106
|
if (devicePixelRatio > 2) {
|
|
87
|
-
w *=
|
|
107
|
+
w *= (devicePixelRatio > 3 ? 3 : devicePixelRatio)
|
|
88
108
|
}
|
|
89
109
|
}
|
|
90
110
|
/* #endif */
|
|
@@ -96,7 +116,7 @@ export default function getImage(src, options) {
|
|
|
96
116
|
}
|
|
97
117
|
|
|
98
118
|
// 如果有最大宽度
|
|
99
|
-
if (maxWidth &&
|
|
119
|
+
if (maxWidth && w > maxWidth) {
|
|
100
120
|
w = maxWidth
|
|
101
121
|
}
|
|
102
122
|
|
|
@@ -113,31 +133,40 @@ export default function getImage(src, options) {
|
|
|
113
133
|
const {
|
|
114
134
|
type,
|
|
115
135
|
domain,
|
|
116
|
-
} = $n_uploader.getUpload()
|
|
136
|
+
} = $n_uploader.getUpload(null, $n_get(options, 'upload', ''))
|
|
117
137
|
|
|
118
138
|
// 判断图片上传方式
|
|
119
139
|
switch (type) {
|
|
120
140
|
|
|
121
141
|
// 七牛云
|
|
142
|
+
// 文档: https://developer.qiniu.com/dora/1279/basic-processing-images-imageview2
|
|
122
143
|
case 'qiniu':
|
|
123
144
|
// minio
|
|
124
145
|
case 'minio':
|
|
125
146
|
|
|
126
147
|
const {
|
|
127
148
|
compress,
|
|
149
|
+
mode,
|
|
128
150
|
w,
|
|
129
151
|
h,
|
|
130
152
|
q,
|
|
153
|
+
ignoreError,
|
|
131
154
|
format,
|
|
132
155
|
} = Object.assign({
|
|
133
156
|
// 是否压缩
|
|
134
157
|
compress: true,
|
|
158
|
+
// 模式
|
|
159
|
+
mode: '2',
|
|
135
160
|
// 宽
|
|
136
161
|
w: 0,
|
|
137
162
|
// 高
|
|
138
163
|
h: 0,
|
|
139
164
|
// 质量
|
|
140
165
|
q: 75,
|
|
166
|
+
// 是否忽略错误
|
|
167
|
+
// 主要针对图片兼容性的问题导致无法处理, 取值为 1 时, 则处理失败时返回原图
|
|
168
|
+
// 不设置此参数, 默认处理失败时返回错误信息
|
|
169
|
+
ignoreError: false,
|
|
141
170
|
// 格式
|
|
142
171
|
format: 'webp',
|
|
143
172
|
}, options)
|
|
@@ -146,7 +175,7 @@ export default function getImage(src, options) {
|
|
|
146
175
|
if (compress) {
|
|
147
176
|
|
|
148
177
|
// 裁剪图片方式
|
|
149
|
-
src +=
|
|
178
|
+
src += `?imageView2/${mode}`
|
|
150
179
|
|
|
151
180
|
// 质量
|
|
152
181
|
if (q) {
|
|
@@ -163,6 +192,11 @@ export default function getImage(src, options) {
|
|
|
163
192
|
src += '/h/' + h
|
|
164
193
|
}
|
|
165
194
|
|
|
195
|
+
// 是否忽略错误
|
|
196
|
+
if (ignoreError) {
|
|
197
|
+
src += '/ignore-error/1'
|
|
198
|
+
}
|
|
199
|
+
|
|
166
200
|
// 格式
|
|
167
201
|
if (format) {
|
|
168
202
|
src += '/format/' + format
|
|
@@ -171,6 +205,15 @@ export default function getImage(src, options) {
|
|
|
171
205
|
break
|
|
172
206
|
}
|
|
173
207
|
|
|
208
|
+
// 【调试模式】
|
|
209
|
+
// --------------------------------------------------
|
|
210
|
+
// #ifdef IS_DEBUG
|
|
211
|
+
if ($n_get(options, 'upload')) {
|
|
212
|
+
return $n_slash(domain, 'end', true) + src
|
|
213
|
+
}
|
|
214
|
+
// #endif
|
|
215
|
+
// --------------------------------------------------
|
|
216
|
+
|
|
174
217
|
return useFileUrl(domain, src)
|
|
175
218
|
}
|
|
176
219
|
}
|
package/utils/uploader.js
CHANGED
|
@@ -1604,7 +1604,7 @@ function create(options) {
|
|
|
1604
1604
|
*/
|
|
1605
1605
|
export function getUpload(userConfig = null, defaultUpload = '') {
|
|
1606
1606
|
const uploadConfig = $n_get((userConfig ? userConfig : configs.userConfig), 'uploader.upload', {})
|
|
1607
|
-
const type = defaultUpload ? defaultUpload : uploadConfig.default
|
|
1607
|
+
const type = $n_isValidString(defaultUpload) ? defaultUpload : uploadConfig.default
|
|
1608
1608
|
return Object.assign(
|
|
1609
1609
|
{},
|
|
1610
1610
|
$n_get(uploadConfig, type, {}),
|