@aochuang/common 1.0.137 → 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
|
@@ -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
|
}
|