web-component-gallery 2.0.18 → 2.0.19
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/dist/js.umd.js +1 -1
- package/lib/browse/index.jsx +72 -37
- package/package.json +1 -1
- package/utils/Utils.js +28 -18
package/lib/browse/index.jsx
CHANGED
|
@@ -2,67 +2,102 @@ import PropTypes from 'ant-design-vue/es/_util/vue-types'
|
|
|
2
2
|
|
|
3
3
|
import { Base64 } from '../../utils/Base64'
|
|
4
4
|
|
|
5
|
-
import { getPictureAttrs } from '../../utils/Utils'
|
|
6
|
-
|
|
7
|
-
const pictureType = [ "gif", "jpeg", "png", "jpg", "bmp", "tif", "svg", "psd", "raw", "WMF", "webp", "apng" ]
|
|
8
|
-
const audioType = [ "mp3", "wma", "flac", "aac", "mmf", "amr", "m4a", "m4r", "ogg", "mp2", "wav" ]
|
|
9
|
-
const videoType = [ "avi", "flv", "mpg", "mpeg", "mpe", "m1v", "m2v", "mpv2", "mp2v", "dat", "ts", "tp", "tpr", "pva", "pss", "mp4", "m4v",
|
|
10
|
-
"m4p", "m4b", "3gp", "3gpp", "3g2", "3gp2", "ogg", "mov", "qt", "amr", "rm", "ram", "rmvb", "rpm" ]
|
|
11
|
-
|
|
12
5
|
const BrowseProps = {
|
|
13
6
|
data: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]).def([]),
|
|
14
7
|
/** 支持http地址可配置 */
|
|
15
8
|
httpsUrl: PropTypes.object.def({}),
|
|
16
9
|
/** 限制高度 */
|
|
17
|
-
astrictH: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
10
|
+
astrictH: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// 文件类型常量
|
|
14
|
+
const FILE_TYPES = {
|
|
15
|
+
PICTURE: ["gif", "jpeg", "png", "jpg", "bmp", "tif", "svg", "psd", "raw", "WMF", "webp", "apng"],
|
|
16
|
+
AUDIO: ["mp3", "wma", "flac", "aac", "mmf", "amr", "m4a", "m4r", "ogg", "mp2", "wav"],
|
|
17
|
+
VIDEO: ["avi", "flv", "mpg", "mpeg", "mpe", "m1v", "m2v", "mpv2", "mp2v", "dat", "ts", "tp", "tpr", "pva", "pss", "mp4", "m4v", "m4p", "m4b", "3gp", "3gpp", "3g2", "3gp2", "ogg", "mov", "qt", "amr", "rm", "ram", "rmvb", "rpm"]
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// 初始化数据
|
|
21
|
+
const setInnerData = (data, https) => {
|
|
22
|
+
|
|
23
|
+
let innerData = data
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
if (typeof(data) === 'string') {
|
|
26
|
+
try {
|
|
27
|
+
innerData = JSON.parse(data)
|
|
28
|
+
} catch(error) { innerData = [] }
|
|
29
|
+
}
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
const { FILEURL, KKFILEURL, OVERVIEWFILEURL } = https
|
|
32
|
+
|
|
33
|
+
innerData = Array.isArray(innerData) ? innerData : [innerData]
|
|
34
|
+
|
|
35
|
+
innerData.forEach(dataItem => {
|
|
36
|
+
if (!dataItem.url.startsWith('http')) {
|
|
37
|
+
dataItem.url =
|
|
38
|
+
getCustomTag(dataItem.url) === 'iframe'
|
|
39
|
+
? KKFILEURL + encodeURIComponent( Base64.encode( OVERVIEWFILEURL + dataItem.url ) )
|
|
40
|
+
: FILEURL + dataItem.url
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return innerData
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 不同类型不同容器承载
|
|
48
|
+
const getCustomTag = (url) => {
|
|
49
|
+
const ext = url.slice(url.lastIndexOf('.') + 1).toLowerCase()
|
|
50
|
+
if (FILE_TYPES.PICTURE.includes(ext)) return 'img'
|
|
51
|
+
if (FILE_TYPES.AUDIO.includes(ext)) return 'audio'
|
|
52
|
+
if (FILE_TYPES.VIDEO.includes(ext)) return 'video'
|
|
53
|
+
return 'iframe'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function renderContent(h, url, images) {
|
|
57
|
+
const { astrictH, $viewerApi } = this
|
|
58
|
+
|
|
59
|
+
const CustomTag = getCustomTag(url)
|
|
28
60
|
|
|
29
61
|
const attrs = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
62
|
+
src: url,
|
|
63
|
+
...(astrictH && { style: `width: auto; height: ${astrictH}px; objectFit: contain;` })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (CustomTag === 'iframe') attrs['controls'] = true
|
|
33
67
|
|
|
34
|
-
|
|
35
|
-
|
|
68
|
+
const handleClick = () => {
|
|
69
|
+
if (CustomTag !== 'img') return
|
|
36
70
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
71
|
+
try {
|
|
72
|
+
$viewerApi({
|
|
73
|
+
options: {
|
|
74
|
+
url: 'url',
|
|
75
|
+
toolbar: true,
|
|
76
|
+
initialViewIndex: images.findIndex(file => file.url == url)
|
|
77
|
+
},
|
|
78
|
+
images
|
|
79
|
+
})
|
|
80
|
+
} catch(error){ console.error('未安装v-viewer@1.6.4组件库') }
|
|
40
81
|
}
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
<CustomTag {...{ attrs }} />
|
|
44
|
-
)
|
|
82
|
+
|
|
83
|
+
return <CustomTag {...{ attrs }} onClick={handleClick} />
|
|
45
84
|
}
|
|
46
85
|
|
|
47
86
|
const Browse = {
|
|
48
87
|
name: 'Browse',
|
|
49
88
|
props: BrowseProps,
|
|
50
89
|
render(h, content) {
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
data = JSON.parse(data)
|
|
56
|
-
} catch(error) { data = [] }
|
|
57
|
-
}
|
|
90
|
+
const {data, $https, httpsUrl} = this
|
|
91
|
+
const innerData = setInnerData(data, {...$https, ...httpsUrl})
|
|
92
|
+
|
|
58
93
|
return (
|
|
59
94
|
<div class="Browse">
|
|
60
95
|
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
96
|
+
innerData.map( dataItem =>
|
|
97
|
+
renderContent.call(this, h, dataItem.url, innerData)
|
|
98
|
+
)
|
|
64
99
|
}
|
|
65
|
-
</div>
|
|
100
|
+
</div>
|
|
66
101
|
)
|
|
67
102
|
}
|
|
68
103
|
}
|
package/package.json
CHANGED
package/utils/Utils.js
CHANGED
|
@@ -29,23 +29,33 @@ export function downLoadFn( response, name, type = "application/vnd.ms-excel" )
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* 获取图片宽高 (如超出限制高度,则根据高度比计算出对应的宽度比)
|
|
33
|
+
* @param {string} url - 图片地址
|
|
34
|
+
* @param {number} astrictH - 限制高度
|
|
35
|
+
* @returns {Object} 包含width和height属性的对象
|
|
35
36
|
*/
|
|
36
|
-
export function getPictureAttrs(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
export function getPictureAttrs(url, astrictH) {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
const image = new Image()
|
|
40
|
+
image.src = url
|
|
41
|
+
|
|
42
|
+
// 确保图片加载完成
|
|
43
|
+
image.onload = () => {
|
|
44
|
+
const { width, height } = image
|
|
45
|
+
|
|
46
|
+
if (height > astrictH) {
|
|
47
|
+
const scale = astrictH / height
|
|
48
|
+
resolve({
|
|
49
|
+
width: width * scale,
|
|
50
|
+
height: astrictH
|
|
51
|
+
})
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
resolve({ width, height })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 错误处理
|
|
59
|
+
image.onerror = () => resolve({ width: 0, height: 0 })
|
|
60
|
+
})
|
|
51
61
|
}
|