@aochuang/common 1.0.133 → 1.0.135

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.
@@ -52,7 +52,7 @@
52
52
  v-for="(item, index) in data"
53
53
  :key="index"
54
54
  >
55
- <img :src="handleFormatSrc(item.thumbSrc || item.src)" :data-original="handleFormatSrc(item.src)" :alt="item.alt" @error="handleThumbImageError(item, $event)" />
55
+ <img :src="handleFormatSrc(item.thumbSrc || item.src)" :data-original="handleFormatSrc(item.src, false)" :alt="item.alt" @error="handleThumbImageError(item, $event)" />
56
56
  </li>
57
57
  </ul>
58
58
  </div>
@@ -66,6 +66,7 @@ import { downloadFile, getNameByFileUrl } from '../../utils/file'
66
66
  import { closest } from '../../utils/dom'
67
67
  import { setViewerImageData, setViewerCurrentImage, getDownloadMethod, getFormatterNameMethod } from './util'
68
68
  import { formatOssPath } from '@aochuang/common/utils/oss'
69
+ import { removeThumbnailSrc } from '../../components/image/util'
69
70
  import { PopupManager } from 'element-ui/lib/utils/popup';
70
71
 
71
72
  export default {
@@ -413,11 +414,15 @@ export default {
413
414
  window.document.removeEventListener('keydown', this.handleDocumentKeydown)
414
415
  this.$emit('close')
415
416
  },
416
- handleFormatSrc (src) {
417
+ handleFormatSrc (src, isCrop) {
417
418
  if (!src) {
418
419
  return
419
420
  }
420
- return formatOssPath(src)
421
+ if (isCrop !== false) {
422
+ return formatOssPath(src)
423
+ } else {
424
+ return formatOssPath(removeThumbnailSrc(src))
425
+ }
421
426
  }
422
427
  },
423
428
  beforeDestroy () {
@@ -218,6 +218,7 @@ export default {
218
218
  const clickFn = getImageClickFn()
219
219
  if (clickFn) {
220
220
  clickFn({
221
+ alt: this.alt,
221
222
  src: formatOssPath(this.source)
222
223
  })
223
224
  }
@@ -1,5 +1,5 @@
1
1
  import Image from './image'
2
- import { setImageClickFn, getThumbnailSrc as _getThumbnailSrc } from './util'
2
+ import { setImageClickFn, getThumbnailSrc as _getThumbnailSrc, removeThumbnailSrc as _removeThumbnailSrc } from './util'
3
3
 
4
4
  Image.install = (Vue, options) => {
5
5
  options = Object.assign({
@@ -10,5 +10,6 @@ Image.install = (Vue, options) => {
10
10
  }
11
11
 
12
12
  export const getThumbnailSrc = _getThumbnailSrc
13
+ export const removeThumbnailSrc = _removeThumbnailSrc
13
14
 
14
15
  export default Image
@@ -105,3 +105,37 @@ export function getThumbnailSrc (url, width) {
105
105
  return url
106
106
  }
107
107
  }
108
+
109
+ /**
110
+ * 移除图片缩略图裁剪参数,保留其他查询参数及 hash
111
+ */
112
+ export function removeThumbnailSrc (url) {
113
+ if (!url) {
114
+ return url
115
+ }
116
+
117
+ const hashIndex = url.indexOf('#')
118
+ const hash = hashIndex >= 0 ? url.substr(hashIndex) : ''
119
+ let source = hashIndex >= 0 ? url.substr(0, hashIndex) : url
120
+
121
+ // /oss/view 和 /oss/ 地址的真实图片在 url 参数中,递归处理后再重新编码
122
+ if (source.indexOf('/oss/view') > -1 || source.indexOf('/oss/') > -1) {
123
+ const marker = source.indexOf('/oss/view') > -1 ? '/oss/view' : '/oss/'
124
+ const markerIndex = source.indexOf(marker)
125
+ const prefix = source.substr(0, markerIndex + marker.length)
126
+ const params = getUrlParams(source)
127
+ if (params.url) {
128
+ params.url = removeThumbnailSrc(params.url)
129
+ source = buildUrl(prefix, params)
130
+ return source + hash
131
+ }
132
+ }
133
+
134
+ // 阿里云参数是普通 query 参数;腾讯云参数是无等号的 query path
135
+ source = source
136
+ .replace(/([?&])x-oss-process=image\/resize(?:,[^&#]*)?(?=&|$)/ig, '$1')
137
+ .replace(/([?&])imageMogr2\/thumbnail\/[^&#]*(?=&|$)/ig, '$1')
138
+ .replace('?&', '?')
139
+ .replace(/[?&]$/, '')
140
+ return source + hash
141
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/common",
3
- "version": "1.0.133",
3
+ "version": "1.0.135",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {