1a2d344e
wxy
初始化项目
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
<template>
<a-card :bordered="false">
<!-- 查询区域 -->
<!--<div class="table-page-search-wrapper">-->
<!--<a-form layout="inline" @keyup.enter.native="searchQuery">-->
<!--<a-row :gutter="24">-->
<!--<a-col :md="6" :sm="12">-->
<!--<a-form-item label="文件名">-->
<!--<!–<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>–>-->
<!--<j-input placeholder="输入文件名模糊查询" v-model="queryParam.username"></j-input>-->
<!--</a-form-item>-->
<!--</a-col>-->
<!--</a-row>-->
<!--</a-form>-->
<!--</div>-->
<!-- 操作按钮区域 -->
<div class="table-operator" style="border-top: 5px">
<a-button type="primary" icon="file" @click="fileUploadBtn">上传</a-button>
<uploader :options="options" :file-status-text="statusText" :autoStart="true" ref="uploader"
@file-added="onFileAdded" @file-progress="fileProgress" @file-error="fileError"
@file-complete="fileComplete" @complete="complete">
<uploader-unsupport></uploader-unsupport>
<uploader-btn id="file-uploader-btn" ref="uploadBtn"></uploader-btn>
<div class="uploader_box">
<div class="top_title" v-show="panelShow">
<span>文件列表</span>
<span class="close" @click="uploaderListClose">×</span>
</div>
<uploader-list v-show="panelShow"></uploader-list>
</div>
</uploader>
</div>
<!-- table区域-begin -->
<div>
<a-table
ref="table"
rowKey="id"
:columns="columns"
:dataSource="dataSource"
:pagination="ipagination"
:loading="loading"
:processResponse="processResponse"
@change="handleTableChange">
<span slot="fileSizeSlot" slot-scope="text, record">
<span>{{ record.fileSize }}M</span>
</span>
<span slot="action" slot-scope="text, record">
<a data-clipboard-action="copy" class="copyLink link" :data-clipboard-text="record.fileUrl" @click="copyLink">复制</a>
<a-divider type="vertical" />
<a target="_blank" v-if="record.fileUrl !== undefined && record.fileUrl!==''" :href="record.fileUrl"
:download="record.filename">下载</a>
<a-divider type="vertical" />
<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
<a>删除</a>
</a-popconfirm>
</span>
</a-table>
</div>
</a-card>
</template>
<script>
import { putAction, postAction, getFileAccessHttpUrl } from '@/api/manage'
import { frozenBatch } from '@/api/api'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import Clipboard from 'clipboard';
import Vue from 'vue'
import { ACCESS_TOKEN, TENANT_ID } from '@/store/mutation-types'
import qs from 'qs'
export default {
name: 'VideoFile',
mixins: [JeecgListMixin],
components: {
JEllipsis
},
data() {
return {
clipboard: null,
options: {
target: window._CONFIG['domianURL'] + '/sys/uploader/chunk',
testChunks: true,
simultaneousUploads: 3,
forceChunkSize: true,
chunkSize: 30 * 1024 * 1024,
headers: function() {
const headers = {}
const token = Vue.ls.get(ACCESS_TOKEN)
if (token) {
headers['X-Access-Token'] = token
}
let tenantid = Vue.ls.get(TENANT_ID)
if (!tenantid) {
tenantid = 0
}
headers['tenant-id'] = tenantid
return headers
},
parseTimeRemaining: function(timeRemaining, parsedTimeRemaining) {
return parsedTimeRemaining
.replace(/\syears?/, '年')
.replace(/\days?/, '天')
.replace(/\shours?/, '小时')
.replace(/\sminutes?/, '分钟')
.replace(/\sseconds?/, '秒')
}
},
attrs: {
accept: 'image/*'
},
statusText: {
success: '成功',
error: '出错',
uploading: '上传中',
paused: '暂停中',
waiting: '等待中'
},
panelShow: false,
description: '文件上传',
queryParam: {},
recycleBinVisible: false,
columns: [
/*{
title: '#',
dataIndex: '',
key:'rowIndex',
width:60,
align:"center",
customRender:function (t,r,index) {
return parseInt(index)+1;
}
},*/
{
title: '文件名',
align: 'left',
dataIndex: 'filename',
sorter: true
},
{
title: '大小',
align: 'center',
dataIndex: 'fileSize',
scopedSlots: { customRender: 'fileSizeSlot' }
},
{
title: '上传日期',
align: 'center',
dataIndex: 'createTime',
sorter: true
},
{
title: '操作',
dataIndex: 'action',
align: 'center',
fixed: 'right',
width: 160,
scopedSlots: { customRender: 'action' }
}
],
url: {
list: '/sys/file/list',
delete: '/sys/file/delete'
}
}
},
methods: {
// getTotalSize: function(totalSize) {
// const sz = totalSize / 1024 / 1204;
// console.log(totalSize,sz);
// return sz.toFixed(2) + 'M'
// },
copyLink() {
this.clipboard.on('success', e => {
console.log('文件地址已复制到剪切板');
this.$message.success('文件地址已复制到剪切板');
e.clearSelection()
this.clipboard.destroy()
this.clipboard = new Clipboard(".copyLink");
})
this.clipboard.on('error', e => {
this.$message.error('复制失败');
})
},
handleMenuClick(e) {
},
processResponse(response, cb, file, chunk) {
console.log('processResponse', response, cb, file, chunk)
},
onSyncFinally({ isToLocal }) {
// 同步到本地时刷新下数据
if (isToLocal) {
this.loadData()
}
},
fileUploadBtn() {
this.$refs.uploadBtn.$el.click()
},
onFileAdded() {
this.panelShow = true
},
uploaderListClose() {
this.$refs.uploader.uploader.files = []
this.$refs.uploader.uploader.fileList = []
this.panelShow = false
},
//文件在上传中
fileProgress(rootFile, file, chunk) {
},
//上传过程中出错了
fileError(rootFile, file, response, chunk) {
this.$message({
message: '上传失败,请重新上传',
type: 'error'
})
},
// 上传完成
complete() {
console.log('complete', arguments, this.$refs.uploader)
},
// 一个根文件(文件夹)成功上传完成。
fileComplete() {
console.log('file complete', arguments)
const file = arguments[0].file
let that = this
postAction('/sys/uploader/mergeFile', qs.stringify({
filename: file.name,
identifier: arguments[0].uniqueIdentifier,
totalSize: file.size,
type: file.type
})).then(function(response) {
console.log(response)
that.loadData()
}).catch(function(error) {
console.log(error)
that.loadData()
})
}
},
mounted() {
// this.$nextTick(() => {
// window.uploader = this.$refs.uploader.uploader
// })
this.clipboard = new Clipboard(".copyLink");
},
destroyed () {
// 销毁Clipboard实例,避免在其它页面或组件中实例化Clipboard后造成再次监听,产生重复回调
this.clipboard.destroy()
}
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>
<style>
.uploader_box {
position: fixed;
right: 12px;
bottom: 12px;
background-color: #fff;
box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
z-index: 999;
}
.top_title {
height: 50px;
padding: 0 15px;
background-color: #fff;
border-bottom: 1px solid #eee;
display: flex;
align-items: center;
justify-content: space-between;
}
.close {
color: #9e9e9e;
font-size: 28px;
cursor: pointer;
}
.uploader-list {
width: 600px;
max-height: 490px;
overflow-y: auto;
scrollbar-color: #cdcdcd #f6f6f6;
scrollbar-width: thin;
}
.uploader-file {
border-bottom: 1px solid #eee !important;
}
.uploader-list ul li:last-child .uploader-file {
border-bottom: none;
}
.uploader-file-icon {
width: 24px;
height: 24px;
display: inline-block;
vertical-align: top;
margin-top: 13px;
margin-right: 8px;
}
.uploader-file-icon::before {
content: "" !important;
display: block;
height: 100%;
}
.uploader-file-icon[icon="folder"]::before {
content: "" !important;
background: url("../../assets/folder.png");
background-size: 24px 24px;
}
.uploader-file-icon[icon="image"]::before {
content: "" !important;
background: url("../../assets/image.png");
background-size: 24px 24px;
}
.uploader-file-icon[icon="video"]::before {
content: "" !important;
background: url("../../assets/video.png");
background-size: 24px 24px;
}
.uploader-file-icon[icon="audio"]::before {
content: "" !important;
background: url("../../assets/audio.png");
background-size: 24px 24px;
}
.uploader-file-icon[icon="document"]::before {
content: "" !important;
background: url("../../assets/document.png");
background-size: 24px 24px;
}
.uploader-file-actions > span {
opacity: 0.7;
}
#file-uploader-btn {
position: absolute;
clip: rect(0, 0, 0, 0);
}
.uploader-file-progress {
background-color: #f0f6ff !important;
}
</style>
|