@ddwl/ddwl-ui 1.1.4 → 1.1.5-beta.2

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,277 +1,275 @@
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
- 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>
1
+ <template>
2
+ <div
3
+ v-if="visible && list.length"
4
+ class="d-file-preview"
5
+ >
6
+ <div
7
+ ref="leftRef"
8
+ class="d-file-preview_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="d-file-preview_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="d-file-preview_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
+ import {imgExts, videoExts, audioExts} from './utils/constant.js'
77
+ export default {
78
+ name: 'DFilePreview',
79
+ components: { ElImageViewer },
80
+ props: {
81
+ value: {
82
+ type: Boolean,
83
+ default: false
84
+ },
85
+ list: {
86
+ type: Array,
87
+ default: () => {
88
+ return [
89
+ { name: '图片', type: 'image', urls: [] },
90
+ { name: '视频', type: 'video', urls: [] },
91
+ { name: '音频', type: 'audio', urls: [] }
92
+ ]
93
+ }
94
+ },
95
+ defaultIndex: {
96
+ type: Number,
97
+ default: 0
98
+ }
99
+ },
100
+ data () {
101
+ return {
102
+ fileList: [],
103
+ currentFileIndex: 0,
104
+ activeTab: 'image',
105
+ visible: true
106
+ }
107
+ },
108
+ computed: {
109
+ currentFileList () {
110
+ return this.fileList.find(item => item.type === this.activeTab)?.urls || []
111
+ }
112
+ },
113
+ watch: {
114
+ list: {
115
+ handler (val) {
116
+ if (val.length && typeof (val[0]) === 'string') {
117
+ let arr = [
118
+ { name: '图片', type: 'image', urls: [] },
119
+ { name: '视频', type: 'video', urls: [] },
120
+ { name: '音频', type: 'audio', urls: [] }
121
+ ]
122
+ const exts = [imgExts, videoExts, audioExts]
123
+ val.map((url, index) => {
124
+ exts.forEach((item, i) => {
125
+ if (item.includes(url.substring(url.lastIndexOf('.') + 1))) {
126
+ arr[i].urls.push(url)
127
+ // 判断初始化tab、index
128
+ if (this.defaultIndex === index) {
129
+ this.activeTab = arr[i].type
130
+ this.currentFileIndex = arr[i].urls.length - 1
131
+ }
132
+ }
133
+ })
134
+ })
135
+ this.fileList = arr.filter(item => item.urls.length)
136
+ } else {
137
+ this.fileList = val
138
+ }
139
+ },
140
+ immediate: true,
141
+ deep: true
142
+ },
143
+ visible: {
144
+ handler (val) {
145
+ if (val) {
146
+ this.addEventEventFun()
147
+ } else {
148
+ this.removeEventFun()
149
+ }
150
+ }
151
+ }
152
+ },
153
+ methods: {
154
+ deviceSupportUninstall () {
155
+ this.$refs.viewer.deviceSupportUninstall()
156
+ },
157
+ deviceSupportInstall () {
158
+ this.$refs.viewer.deviceSupportInstall()
159
+ },
160
+ addEventEventFun () {
161
+ const elRef = this.$refs.leftRef
162
+ elRef.addEventListener('mouseenter', this.deviceSupportUninstall)
163
+ elRef.addEventListener('mouseleave', this.deviceSupportInstall)
164
+ },
165
+ removeEventFun () {
166
+ const elRef = this.$refs.leftRef
167
+ elRef.removeEventListener('mouseenter', this.deviceSupportUninstall)
168
+ elRef.removeEventListener('mouseleave', this.deviceSupportInstall)
169
+ },
170
+ close () {
171
+ this.visible = false
172
+ this.$emit('close')
173
+ },
174
+ getUrl (val) {
175
+ switch (this.activeTab) {
176
+ case 'video':
177
+ return require('./static/video.png')
178
+ case 'image':
179
+ return val
180
+ case 'audio':
181
+ return require('./static/audio.png')
182
+ default:
183
+ break
184
+ }
185
+ },
186
+ handleClickLeft (url, index) {
187
+ this.currentFileIndex = index
188
+ },
189
+ handleTabClick () {
190
+ this.currentFileIndex = 0
191
+ }
192
+ }
193
+ }
194
+ </script>
195
+
196
+ <style lang="scss" scoped>
197
+ .d-file-preview {
198
+ width: 100vw;
199
+ height: 100vh;
200
+ position: fixed;
201
+ top: 0;
202
+ left: 0;
203
+ z-index: 99999;
204
+
205
+ &_box {
206
+ position: fixed;
207
+ top: 0;
208
+ left: 0;
209
+ right: 0;
210
+ bottom: 0;
211
+ z-index: 1001;
212
+ padding-left: 250px;
213
+ background-color: rgba($color: #000000, $alpha: 0.5);
214
+ display: flex;
215
+ align-items: center;
216
+ justify-content: center;
217
+ }
218
+
219
+ &_left {
220
+ position: fixed;
221
+ z-index: 3000;
222
+ width: 220px;
223
+ height: 100vh;
224
+ top: 0;
225
+ left: 0;
226
+ bottom: 0;
227
+ overflow: hidden;
228
+ padding: 12px 12px 12px 20px;
229
+ display: flex;
230
+ flex-direction: column;
231
+ background: #606266;
232
+
233
+ :deep(.el-tabs__nav-wrap::after) {
234
+ background-color: transparent;
235
+ }
236
+
237
+ :deep(.el-tabs__item) {
238
+ color: #fff;
239
+ }
240
+
241
+ :deep(.el-tabs__item.is-active) {
242
+ color: #5f9efd;
243
+ }
244
+
245
+ &_list {
246
+ flex: 1;
247
+ overflow: auto;
248
+ text-align: center;
249
+ font-size: 0;
250
+
251
+ li {
252
+ margin-bottom: 7px;
253
+ border: 2px solid transparent;
254
+ margin-right: 2px;
255
+ }
256
+
257
+ .active_left {
258
+ border: 2px solid #5f9efd;
259
+ }
260
+
261
+ &::-webkit-scrollbar {
262
+ display: none;
263
+ }
264
+ }
265
+ }
266
+
267
+ :deep(.el-image-viewer__wrapper) {
268
+ left: calc(220px);
269
+ }
270
+
271
+ :deep(.el-icon-close) {
272
+ color: #fff;
273
+ }
274
+ }
275
+ </style>