web-component-gallery 2.3.25 → 2.3.26

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.
@@ -4,6 +4,17 @@ import { IconFont } from '../index'
4
4
  // 引入文件处理工具函数:格式化数据、获取文件类型、预览文件
5
5
  import { formatFileData, getFileType, previewFile } from '../../utils/File'
6
6
 
7
+ import { Spin, Icon } from 'ant-design-vue'
8
+
9
+ // 默认显示加载器
10
+ Spin.setDefaultIndicator({
11
+ indicator: {
12
+ render() {
13
+ return <Icon type="loading" />
14
+ }
15
+ }
16
+ })
17
+
7
18
  const BrowseProps = {
8
19
  // 数据源,支持字符串、数组或对象,默认为空数组
9
20
  data: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]).def([]),
@@ -46,10 +57,12 @@ const renderContent = function (h, file, images) {
46
57
 
47
58
  if (!url) return
48
59
 
49
- const { isThumb, astrictH } = this
60
+ const { isThumb, astrictH, iframeLoadingState } = this
50
61
  const tag = getPreviewType(url)
51
62
  const isImage = tag === 'img'
52
63
  const isMedia = ['audio', 'video'].includes(tag)
64
+ const isIframe = tag === 'iframe'
65
+ const fileId = file.id || url // 使用唯一标识作为 key
53
66
 
54
67
  // 点击处理函数:如果是图片或缩略图模式,则触发预览
55
68
  const handleClick = () => {
@@ -69,9 +82,7 @@ const renderContent = function (h, file, images) {
69
82
  // 构建基础标签属性
70
83
  const attrs = {
71
84
  src: url,
72
- // 音视频和 iframe 显示控制条
73
- ...((isMedia || tag === 'iframe') && { controls: true }),
74
- // 音视频自动播放配置
85
+ ...((isMedia || isIframe) && { controls: true }),
75
86
  ...(isMedia && { autoplay: true, muted: true, playsinline: true })
76
87
  }
77
88
 
@@ -80,6 +91,28 @@ const renderContent = function (h, file, images) {
80
91
  ...(astrictH && { width: 'auto', height: `${astrictH}px` })
81
92
  }
82
93
 
94
+ // iframe 类型添加加载遮罩
95
+ if (isIframe) {
96
+
97
+ // 初始化加载状态(仅当该文件未记录状态时)
98
+ if (!(fileId in iframeLoadingState)) {
99
+ this.$set(this.iframeLoadingState, fileId, true)
100
+
101
+ // 超时兜底:5秒后强制关闭加载状态
102
+ setTimeout(() => {
103
+ if (this.iframeLoadingState[fileId]) {
104
+ this.$set(this.iframeLoadingState, fileId, false)
105
+ }
106
+ }, 5000)
107
+ }
108
+
109
+ const updateState = () => this.$set(this.iframeLoadingState, fileId, false)
110
+
111
+ return <Spin spinning={iframeLoadingState[fileId]} tip="加载中...">
112
+ <tag {...{ attrs, style }} onLoad={updateState} onError={updateState} />
113
+ </Spin>
114
+ }
115
+
83
116
  // 渲染实际的媒体标签
84
117
  return <tag {...{ attrs, style }} onClick={handleClick} />
85
118
  }
@@ -88,6 +121,18 @@ const renderContent = function (h, file, images) {
88
121
  const Browse = {
89
122
  name: 'Browse',
90
123
  props: BrowseProps,
124
+ data() {
125
+ return {
126
+ iframeLoadingState: {}
127
+ }
128
+ },
129
+ watch: {
130
+ // 数据源变化时重置所有加载状态
131
+ data: {
132
+ handler() { this.iframeLoadingState = {} },
133
+ deep: true
134
+ }
135
+ },
91
136
  render(h) {
92
137
  const { data, $https, httpsUrl } = this
93
138
  // 格式化文件数据,合并 HTTPS 配置
@@ -9,4 +9,20 @@ img {
9
9
  max-height: 100%;
10
10
  object-fit: contain;
11
11
  .square(auto);
12
+ }
13
+
14
+ .ant-spin-nested-loading,
15
+ .ant-spin-container {
16
+ .layout();
17
+ }
18
+
19
+ .ant-spin-nested-loading > div > .ant-spin {
20
+ .ant-spin-dot {
21
+ font-size: 48px;
22
+ }
23
+ .ant-spin-text.ant-spin-text {
24
+ top: 60%;
25
+ padding-left: 36px;
26
+ font-size: @font-size-lg;
27
+ }
12
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-gallery",
3
- "version": "2.3.25",
3
+ "version": "2.3.26",
4
4
  "description": "基础vue、antdvue、less实现的私有组件库",
5
5
  "main": "dist/index.umd.js",
6
6
  "files": [