@ddwl/ddwl-ui 1.1.5 → 1.1.7

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,275 +1,275 @@
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'
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>
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'
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>