@aochuang/common 1.0.136 → 1.0.138
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/icon/icon.vue
CHANGED
|
@@ -15,13 +15,15 @@
|
|
|
15
15
|
@error="handleImageError"
|
|
16
16
|
:style="imageStyle"
|
|
17
17
|
/>
|
|
18
|
-
<ui-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
<div v-if="status === 'error'" class="ui-image__error" :class="{'has-slot': $slots.error}">
|
|
19
|
+
<slot name="error">
|
|
20
|
+
<ui-icon
|
|
21
|
+
name="image-error-line"
|
|
22
|
+
:size="iconSize"
|
|
23
|
+
color="#aaa"
|
|
24
|
+
></ui-icon>
|
|
25
|
+
</slot>
|
|
26
|
+
</div>
|
|
25
27
|
<div class="ui-image__preview" v-if="previewable && status === 'success'" @click="handlePreviewClick">
|
|
26
28
|
<ui-icon name="sousuo" :size="30" color="#fff"></ui-icon>
|
|
27
29
|
</div>
|
|
@@ -215,7 +217,7 @@ export default {
|
|
|
215
217
|
if (!this.source) {
|
|
216
218
|
return
|
|
217
219
|
}
|
|
218
|
-
const clickFn = getImageClickFn()
|
|
220
|
+
const clickFn = getImageClickFn()
|
|
219
221
|
if (clickFn) {
|
|
220
222
|
clickFn({
|
|
221
223
|
alt: this.alt,
|
|
@@ -318,7 +320,7 @@ export default {
|
|
|
318
320
|
img {
|
|
319
321
|
display: none!important;
|
|
320
322
|
}
|
|
321
|
-
.ui-image__error{
|
|
323
|
+
.ui-image__error:not(.has-slot){
|
|
322
324
|
position: absolute;
|
|
323
325
|
left: 50%;
|
|
324
326
|
top: 50%;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import Image from './image'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
setImageClickFn,
|
|
4
|
+
getThumbnailSrc as _getThumbnailSrc,
|
|
5
|
+
removeThumbnailSrc as _removeThumbnailSrc
|
|
6
|
+
} from './util'
|
|
3
7
|
|
|
4
8
|
Image.install = (Vue, options) => {
|
|
5
9
|
options = Object.assign({
|
package/components/image/util.js
CHANGED
|
@@ -106,6 +106,39 @@ export function getThumbnailSrc (url, width) {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
function decodeUrlParam (value) {
|
|
110
|
+
try {
|
|
111
|
+
return decodeURIComponent(value.replace(/\+/g, ' '))
|
|
112
|
+
} catch (e) {
|
|
113
|
+
return value
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function removeThumbnailQuery (url) {
|
|
118
|
+
const hashIndex = url.indexOf('#')
|
|
119
|
+
const hash = hashIndex > -1 ? url.substr(hashIndex) : ''
|
|
120
|
+
const urlWithoutHash = hashIndex > -1 ? url.substr(0, hashIndex) : url
|
|
121
|
+
const queryIndex = urlWithoutHash.indexOf('?')
|
|
122
|
+
|
|
123
|
+
if (queryIndex < 0) {
|
|
124
|
+
return url
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const baseUrl = urlWithoutHash.substr(0, queryIndex)
|
|
128
|
+
const query = urlWithoutHash.substr(queryIndex + 1)
|
|
129
|
+
const nextQuery = query.split('&').filter(param => {
|
|
130
|
+
const equalIndex = param.indexOf('=')
|
|
131
|
+
const key = decodeUrlParam(equalIndex > -1 ? param.substr(0, equalIndex) : param)
|
|
132
|
+
const value = decodeUrlParam(equalIndex > -1 ? param.substr(equalIndex + 1) : '')
|
|
133
|
+
const isAliyunThumbnail = key === 'x-oss-process' && /^image\/resize,w_[^/]+$/.test(value)
|
|
134
|
+
const isTencentThumbnail = /^imageMogr2\/thumbnail\/[^/]+$/.test(key) && !value
|
|
135
|
+
|
|
136
|
+
return !isAliyunThumbnail && !isTencentThumbnail
|
|
137
|
+
}).join('&')
|
|
138
|
+
|
|
139
|
+
return baseUrl + (nextQuery ? '?' + nextQuery : '') + hash
|
|
140
|
+
}
|
|
141
|
+
|
|
109
142
|
/**
|
|
110
143
|
* 移除图片缩略图裁剪参数,保留其他查询参数及 hash
|
|
111
144
|
*/
|
|
@@ -115,27 +148,29 @@ export function removeThumbnailSrc (url) {
|
|
|
115
148
|
}
|
|
116
149
|
|
|
117
150
|
const hashIndex = url.indexOf('#')
|
|
118
|
-
const hash = hashIndex
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
151
|
+
const hash = hashIndex > -1 ? url.substr(hashIndex) : ''
|
|
152
|
+
const urlWithoutHash = hashIndex > -1 ? url.substr(0, hashIndex) : url
|
|
153
|
+
let proxyPath = ''
|
|
154
|
+
|
|
155
|
+
if (urlWithoutHash.indexOf('/oss/view') > -1) {
|
|
156
|
+
proxyPath = '/oss/view'
|
|
157
|
+
} else if (urlWithoutHash.indexOf('/oss/') > -1) {
|
|
158
|
+
proxyPath = '/oss/'
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!proxyPath) {
|
|
162
|
+
return removeThumbnailQuery(url)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const urlParams = getUrlParams(urlWithoutHash)
|
|
166
|
+
if (!urlParams.url) {
|
|
167
|
+
return url
|
|
132
168
|
}
|
|
133
169
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return source + hash
|
|
170
|
+
return buildUrl(
|
|
171
|
+
urlWithoutHash.substr(0, urlWithoutHash.indexOf(proxyPath) + proxyPath.length),
|
|
172
|
+
Object.assign({}, urlParams, {
|
|
173
|
+
url: removeThumbnailSrc(urlParams.url)
|
|
174
|
+
})
|
|
175
|
+
) + hash
|
|
141
176
|
}
|