@ddwl/ddwl-ui 1.1.3 → 1.1.5-beta.1

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.
@@ -1,276 +1,277 @@
1
- <template>
2
- <div
3
- v-if="visible && list.length"
4
- class="container"
5
- >
6
- <div
7
- ref="leftRef"
8
- class="left"
9
- >
10
- <el-tabs
11
- v-model="activeTab"
12
- @tab-click="handleTabClick"
13
- >
14
- <el-tab-pane
15
- v-for="(v, i) in fileList"
16
- :key="i"
17
- :label="v.name"
18
- :name="v.type"
19
- />
20
- </el-tabs>
21
- <ul class="list">
22
- <li
23
- v-for="(url, i) in currentFileList"
24
- :key="i"
25
- :class="currentFileIndex === i ? 'active_left' : ''"
26
- @click="handleClickLeft(url, i)"
27
- >
28
- <el-image
29
- style="width: 140px; height: 140px"
30
- :src="getUrl(url)"
31
- fit="cover"
32
- />
33
- </li>
34
- </ul>
35
- </div>
36
- <el-image-viewer
37
- v-show="activeTab === 'image'"
38
- ref="viewer"
39
- :mask-closable="false"
40
- :append-to-body="false"
41
- :url-list="[activeTab === 'image' ? currentFileList[currentFileIndex] : '']"
42
- :on-close="close"
43
- />
44
- <div
45
- v-show="activeTab !== 'image'"
46
- class="box"
47
- >
48
- <span
49
- class="el-image-viewer__btn el-image-viewer__close"
50
- @click="close"
51
- >
52
- <i class="el-icon-close" />
53
- </span>
54
- <audio
55
- v-show="activeTab === 'audio'"
56
- controls
57
- style="width: 60%"
58
- >
59
- <source :src="currentFileList[currentFileIndex]">
60
- 您的浏览器不支持 audio 元素。
61
- </audio>
62
- <video
63
- v-show="activeTab === 'video'"
64
- controls
65
- style="min-width: 80%;max-height: 90%"
66
- >
67
- <source :src="currentFileList[currentFileIndex]">
68
- 您的浏览器不支持 HTML5 video 标签。
69
- </video>
70
- </div>
71
- </div>
72
- </template>
73
-
74
- <script>
75
- import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
76
- const imgExts = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg']
77
- const videoExts = ['mp4']
78
- const audioExts = ['mp3', 'wav', 'ogg']
79
- export default {
80
- name: 'DFilePreview',
81
- components: { ElImageViewer },
82
- props: {
83
- value: {
84
- type: Boolean,
85
- default: false
86
- },
87
- list: {
88
- type: Array,
89
- default: () => {
90
- return [
91
- { name: '图片', type: 'image', urls: [] },
92
- { name: '视频', type: 'video', urls: [] },
93
- { name: '音频', type: 'audio', urls: [] }
94
- ]
95
- }
96
- },
97
- defaultIndex: {
98
- type: Number,
99
- default: 0
100
- }
101
- },
102
- data () {
103
- return {
104
- fileList: [],
105
- currentFileIndex: 0,
106
- activeTab: 'image',
107
- visible: true
108
- }
109
- },
110
- computed: {
111
- currentFileList () {
112
- return this.fileList.find(item => item.type === this.activeTab)?.urls || []
113
- }
114
- },
115
- watch: {
116
- list: {
117
- handler (val) {
118
- if (val.length && typeof (val[0]) === 'string') {
119
- let arr = [
120
- { name: '图片', type: 'image', urls: [] },
121
- { name: '视频', type: 'video', urls: [] },
122
- { name: '音频', type: 'audio', urls: [] }
123
- ]
124
- const exts = [imgExts, videoExts, audioExts]
125
- val.map((url, index) => {
126
- exts.forEach((item, i) => {
127
- if (item.includes(url.substring(url.lastIndexOf('.') + 1))) {
128
- arr[i].urls.push(url)
129
- // 判断初始化tab、index
130
- if (this.defaultIndex === index) {
131
- this.activeTab = arr[i].type
132
- this.currentFileIndex = arr[i].urls.length - 1
133
- }
134
- }
135
- })
136
- })
137
- this.fileList = arr.filter(item => item.urls.length)
138
- } else {
139
- this.fileList = val
140
- }
141
- },
142
- immediate: true,
143
- deep: true
144
- },
145
- visible: {
146
- handler (val) {
147
- if (val) {
148
- this.addEventEventFun()
149
- } else {
150
- this.removeEventFun()
151
- }
152
- }
153
- }
154
- },
155
- methods: {
156
- deviceSupportUninstall () {
157
- this.$refs.viewer.deviceSupportUninstall()
158
- },
159
- deviceSupportInstall () {
160
- this.$refs.viewer.deviceSupportInstall()
161
- },
162
- addEventEventFun () {
163
- const elRef = this.$refs.leftRef
164
- elRef.addEventListener('mouseenter', this.deviceSupportUninstall)
165
- elRef.addEventListener('mouseleave', this.deviceSupportInstall)
166
- },
167
- removeEventFun () {
168
- const elRef = this.$refs.leftRef
169
- elRef.removeEventListener('mouseenter', this.deviceSupportUninstall)
170
- elRef.removeEventListener('mouseleave', this.deviceSupportInstall)
171
- },
172
- close () {
173
- this.visible = false
174
- },
175
- getUrl (val) {
176
- switch (this.activeTab) {
177
- case 'video':
178
- return require('./static/video.png')
179
- case 'image':
180
- return val
181
- case 'audio':
182
- return require('./static/audio.png')
183
- default:
184
- break
185
- }
186
- },
187
- handleClickLeft (url, index) {
188
- this.currentFileIndex = index
189
- },
190
- handleTabClick () {
191
- this.currentFileIndex = 0
192
- }
193
- }
194
- }
195
- </script>
196
-
197
- <style lang="scss" scoped>
198
- .container {
199
- width: 100vw;
200
- height: 100vh;
201
- position: fixed;
202
- top: 0;
203
- left: 0;
204
- z-index: 99999;
205
-
206
- .box {
207
- position: fixed;
208
- top: 0;
209
- left: 0;
210
- right: 0;
211
- bottom: 0;
212
- z-index: 1001;
213
- padding-left: 250px;
214
- background-color: rgba($color: #000000, $alpha: 0.5);
215
- display: flex;
216
- align-items: center;
217
- justify-content: center;
218
- }
219
-
220
- .left {
221
- position: fixed;
222
- z-index: 3000;
223
- width: 220px;
224
- height: 100vh;
225
- top: 0;
226
- left: 0;
227
- bottom: 0;
228
- overflow: hidden;
229
- padding: 12px 12px 12px 20px;
230
- display: flex;
231
- flex-direction: column;
232
- background: #606266;
233
-
234
- :deep(.el-tabs__nav-wrap::after) {
235
- background-color: transparent;
236
- }
237
-
238
- :deep(.el-tabs__item) {
239
- color: #fff;
240
- }
241
-
242
- :deep(.el-tabs__item.is-active) {
243
- color: #5f9efd;
244
- }
245
-
246
- .list {
247
- flex: 1;
248
- overflow: auto;
249
- text-align: center;
250
- font-size: 0;
251
-
252
- li {
253
- margin-bottom: 7px;
254
- border: 2px solid transparent;
255
- margin-right: 2px;
256
- }
257
-
258
- .active_left {
259
- border: 2px solid #5f9efd;
260
- }
261
-
262
- &::-webkit-scrollbar {
263
- display: none;
264
- }
265
- }
266
- }
267
-
268
- :deep(.el-image-viewer__wrapper) {
269
- left: calc(220px);
270
- }
271
-
272
- :deep(.el-icon-close) {
273
- color: #fff;
274
- }
275
- }
276
- </style>
1
+ <template>
2
+ <div
3
+ v-if="visible && list.length"
4
+ class="container add"
5
+ >
6
+ <div
7
+ ref="leftRef"
8
+ class="left"
9
+ >
10
+ <el-tabs
11
+ v-model="activeTab"
12
+ @tab-click="handleTabClick"
13
+ >
14
+ <el-tab-pane
15
+ v-for="(v, i) in fileList"
16
+ :key="i"
17
+ :label="v.name"
18
+ :name="v.type"
19
+ />
20
+ </el-tabs>
21
+ <ul class="list">
22
+ <li
23
+ v-for="(url, i) in currentFileList"
24
+ :key="i"
25
+ :class="currentFileIndex === i ? 'active_left' : ''"
26
+ @click="handleClickLeft(url, i)"
27
+ >
28
+ <el-image
29
+ style="width: 140px; height: 140px"
30
+ :src="getUrl(url)"
31
+ fit="cover"
32
+ />
33
+ </li>
34
+ </ul>
35
+ </div>
36
+ <el-image-viewer
37
+ v-show="activeTab === 'image'"
38
+ ref="viewer"
39
+ :mask-closable="false"
40
+ :append-to-body="false"
41
+ :url-list="[activeTab === 'image' ? currentFileList[currentFileIndex] : '']"
42
+ :on-close="close"
43
+ />
44
+ <div
45
+ v-show="activeTab !== 'image'"
46
+ class="box"
47
+ >
48
+ <span
49
+ class="el-image-viewer__btn el-image-viewer__close"
50
+ @click="close"
51
+ >
52
+ <i class="el-icon-close" />
53
+ </span>
54
+ <audio
55
+ v-show="activeTab === 'audio'"
56
+ controls
57
+ style="width: 60%"
58
+ >
59
+ <source :src="currentFileList[currentFileIndex]">
60
+ 您的浏览器不支持 audio 元素。
61
+ </audio>
62
+ <video
63
+ v-show="activeTab === 'video'"
64
+ controls
65
+ style="min-width: 80%;max-height: 90%"
66
+ >
67
+ <source :src="currentFileList[currentFileIndex]">
68
+ 您的浏览器不支持 HTML5 video 标签。
69
+ </video>
70
+ </div>
71
+ </div>
72
+ </template>
73
+
74
+ <script>
75
+ import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
76
+ const imgExts = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg']
77
+ const videoExts = ['mp4']
78
+ const audioExts = ['mp3', 'wav', 'ogg']
79
+ export default {
80
+ name: 'DFilePreview',
81
+ components: { ElImageViewer },
82
+ props: {
83
+ value: {
84
+ type: Boolean,
85
+ default: false
86
+ },
87
+ list: {
88
+ type: Array,
89
+ default: () => {
90
+ return [
91
+ { name: '图片', type: 'image', urls: [] },
92
+ { name: '视频', type: 'video', urls: [] },
93
+ { name: '音频', type: 'audio', urls: [] }
94
+ ]
95
+ }
96
+ },
97
+ defaultIndex: {
98
+ type: Number,
99
+ default: 0
100
+ }
101
+ },
102
+ data () {
103
+ return {
104
+ fileList: [],
105
+ currentFileIndex: 0,
106
+ activeTab: 'image',
107
+ visible: true
108
+ }
109
+ },
110
+ computed: {
111
+ currentFileList () {
112
+ return this.fileList.find(item => item.type === this.activeTab)?.urls || []
113
+ }
114
+ },
115
+ watch: {
116
+ list: {
117
+ handler (val) {
118
+ if (val.length && typeof (val[0]) === 'string') {
119
+ let arr = [
120
+ { name: '图片', type: 'image', urls: [] },
121
+ { name: '视频', type: 'video', urls: [] },
122
+ { name: '音频', type: 'audio', urls: [] }
123
+ ]
124
+ const exts = [imgExts, videoExts, audioExts]
125
+ val.map((url, index) => {
126
+ exts.forEach((item, i) => {
127
+ if (item.includes(url.substring(url.lastIndexOf('.') + 1))) {
128
+ arr[i].urls.push(url)
129
+ // 判断初始化tab、index
130
+ if (this.defaultIndex === index) {
131
+ this.activeTab = arr[i].type
132
+ this.currentFileIndex = arr[i].urls.length - 1
133
+ }
134
+ }
135
+ })
136
+ })
137
+ this.fileList = arr.filter(item => item.urls.length)
138
+ } else {
139
+ this.fileList = val
140
+ }
141
+ },
142
+ immediate: true,
143
+ deep: true
144
+ },
145
+ visible: {
146
+ handler (val) {
147
+ if (val) {
148
+ this.addEventEventFun()
149
+ } else {
150
+ this.removeEventFun()
151
+ }
152
+ }
153
+ }
154
+ },
155
+ methods: {
156
+ deviceSupportUninstall () {
157
+ this.$refs.viewer.deviceSupportUninstall()
158
+ },
159
+ deviceSupportInstall () {
160
+ this.$refs.viewer.deviceSupportInstall()
161
+ },
162
+ addEventEventFun () {
163
+ const elRef = this.$refs.leftRef
164
+ elRef.addEventListener('mouseenter', this.deviceSupportUninstall)
165
+ elRef.addEventListener('mouseleave', this.deviceSupportInstall)
166
+ },
167
+ removeEventFun () {
168
+ const elRef = this.$refs.leftRef
169
+ elRef.removeEventListener('mouseenter', this.deviceSupportUninstall)
170
+ elRef.removeEventListener('mouseleave', this.deviceSupportInstall)
171
+ },
172
+ close () {
173
+ this.visible = false
174
+ this.$emit('close')
175
+ },
176
+ getUrl (val) {
177
+ switch (this.activeTab) {
178
+ case 'video':
179
+ return require('./static/video.png')
180
+ case 'image':
181
+ return val
182
+ case 'audio':
183
+ return require('./static/audio.png')
184
+ default:
185
+ break
186
+ }
187
+ },
188
+ handleClickLeft (url, index) {
189
+ this.currentFileIndex = index
190
+ },
191
+ handleTabClick () {
192
+ this.currentFileIndex = 0
193
+ }
194
+ }
195
+ }
196
+ </script>
197
+
198
+ <style lang="scss" scoped>
199
+ .container {
200
+ width: 100vw;
201
+ height: 100vh;
202
+ position: fixed;
203
+ top: 0;
204
+ left: 0;
205
+ z-index: 99999;
206
+
207
+ .box {
208
+ position: fixed;
209
+ top: 0;
210
+ left: 0;
211
+ right: 0;
212
+ bottom: 0;
213
+ z-index: 1001;
214
+ padding-left: 250px;
215
+ background-color: rgba($color: #000000, $alpha: 0.5);
216
+ display: flex;
217
+ align-items: center;
218
+ justify-content: center;
219
+ }
220
+
221
+ .left {
222
+ position: fixed;
223
+ z-index: 3000;
224
+ width: 220px;
225
+ height: 100vh;
226
+ top: 0;
227
+ left: 0;
228
+ bottom: 0;
229
+ overflow: hidden;
230
+ padding: 12px 12px 12px 20px;
231
+ display: flex;
232
+ flex-direction: column;
233
+ background: #606266;
234
+
235
+ :deep(.el-tabs__nav-wrap::after) {
236
+ background-color: transparent;
237
+ }
238
+
239
+ :deep(.el-tabs__item) {
240
+ color: #fff;
241
+ }
242
+
243
+ :deep(.el-tabs__item.is-active) {
244
+ color: #5f9efd;
245
+ }
246
+
247
+ .list {
248
+ flex: 1;
249
+ overflow: auto;
250
+ text-align: center;
251
+ font-size: 0;
252
+
253
+ li {
254
+ margin-bottom: 7px;
255
+ border: 2px solid transparent;
256
+ margin-right: 2px;
257
+ }
258
+
259
+ .active_left {
260
+ border: 2px solid #5f9efd;
261
+ }
262
+
263
+ &::-webkit-scrollbar {
264
+ display: none;
265
+ }
266
+ }
267
+ }
268
+
269
+ :deep(.el-image-viewer__wrapper) {
270
+ left: calc(220px);
271
+ }
272
+
273
+ :deep(.el-icon-close) {
274
+ color: #fff;
275
+ }
276
+ }
277
+ </style>