zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<template >
    <a-layout class="list-container" v-loading="loading">
 
        <a-layout-content class="file-list-content" @click.native.right="handleClickRight" @dragenter="handleDragEnter"
            @dragover="handleDragOver" @dragleave="handleDragLeave" @drop="handleDrop">
            <FileTable ref="fileTable" :fileList="fileList" :searchStr="searchStr" v-if="fileModel === 0"
                @fileClick="handlerFileClick" @fileDbclick="handlerFileDbclick" @reloadPathTree="reloadPathTree"
                @refreshFavorite="refreshFavorite" @click.native.right="handleClickRight">
            </FileTable>
            <FileGrid :fileList="fileList" :searchStr="searchStr" v-if="fileModel === 1" @fileClick="handlerFileClick"
                @reloadPathTree="reloadPathTree" @fileDbclick="handlerFileDbclick" @refreshFavorite="refreshFavorite"
                @click.native.right="handleClickRight" @fileDragStart="handleDragStart">
            </FileGrid>
 
        </a-layout-content>
        <a-layout-footer class="file-list-footer">
            <div>共 {{ fileNum }} 个项目</div>
 
            <div>剩余下载限额:
                <a-progress style="width:120px" :percent="percent" :show-info="false" />
                {{ $file.calculateFileSize(flow - surplusFlow) }}/{{ $file.calculateFileSize(flow) }}
            </div>
        </a-layout-footer>
        <a-modal v-model="compareModal" mask :maskClosable="false" title="Basic Modal" @ok="handleOk" @cancel="handleOk"
            @close="handleOk" width="1100px">
            <!-- <p v-for="(item, index) in compareList" :key="index">{{ item.fileName }}</p> -->
            <a-table :columns="columns" :data-source="compareList" bordered size="small">
                <!-- <template slot="name" slot-scope="text">
                <a>{{ text }}</a>
                </template> -->
 
            </a-table>
 
        </a-modal>
    </a-layout>
</template>
 
<script>
import {
    getAction,
    postAction
} from '@/api/manage';
import {
    fileSuffixCodeModeMap,
    markdownFileType,
    officeFileType
} from '@/utils/libs/map.js';
import FileGrid from './FileGrid.vue';
import FileTable from './FileTable.vue';
export default {
    name: "fileList",
    props: ['filePath'],
    components: { FileTable, FileGrid },
    data() {
        return {
            fileSuffixCodeModeMap,
            markdownFileType,
            officeFileType,
            loading: false,
            searchStr: '',
            fileList: [],
            selectedFile: undefined,
            url: {
                list: '/document/listFile',
                search: "/document/searchFile",
                recoveryList: '/recoveryfile/list',
            },
            visible: false,
            columns: [
                {
                    title: '文件',
                    dataIndex: 'fileName',
                },
                {
                    title: '原大小',
                    dataIndex: 'fileSize',
                },
                {
                    title: '服务器大小',
                    dataIndex: 'comFileSize',
                },
                {
                    title: '原MD5',
                    dataIndex: 'identifier',
                },
 
                {
                    title: '服务器MD5',
                    dataIndex: 'comIdentifier',
                },
            ]
        }
    },
    methods: {
        // 树形目录节点点击事件,根据目录名加载文件列表
        loadPathFile(path, pathId) {
            this.loading = true
            this.$store.commit('changeFileType', 0)
            console.log("path:::", path);
            getAction(this.url.list, { "path": path, "pathId": pathId }).then(res => {
                this.loading = false
                console.log("result:::", res.result);
                this.fileList = res.result ? res.result : [];
                this.$store.commit('changeDownloadPrem', res.downloadPrem)
                this.$store.commit('changeManagePrem', res.managePrem)
                this.$store.commit('changeCreateFlag', res.create)
                this.$store.commit('changeUploadFlag', res.upload)
 
                // 清空多选
                this.selectedFileList([])
            })
        },
        // 搜索文件
        searchFileList(str) {
            this.searchStr = str
            console.log("search:File:::", this.searchStr);
            this.loading = true
            this.$store.commit('changeFileType', 10)
            getAction(this.url.search, { "name": str }).then(res => {
                this.loading = false
                console.log("result:::", res.result);
                this.fileList = res.result ? res.result : [];
                this.$store.commit('changeDownloadPrem', res.downloadPrem)
                this.$store.commit('changeManagePrem', res.managePrem)
                // 清空多选
                this.selectedFileList([])
 
            })
        },
        //加载回收站列表
        loadRecoveryFile() {
            this.loading = true
            this.$store.commit('changeFileType', 6)
            postAction(this.url.recoveryList, null).then(res => {
                this.loading = false
                console.log("recovery:result:::", res.result);
                this.fileList = res.result ? res.result : [];
                this.fileList.forEach((item, index) => {
                    item.updateTime = item.deleteTime
                })
                console.log(`output->res.result`, this.fileList)
                this.$store.commit('changeManagePrem', res.managePrem)
            })
        },
        // 加载分享文件列表
        loadShareFile() {
            // this.loading = true
            this.$store.commit('changeFileType', 8)
            // postAction(this.url.recoveryList,null).then(res => {
            //     this.loading = false
            //     console.log("recovery:result:::", res.result);
            //     this.fileList = res.result?res.result:[];
            // })
            this.fileList = []
        },
        // 转发列表中文件点击 事件
        handlerFileClick(row) {
 
 
        },
 
        handlerFileDbclick(row) {
            console.log(`output->"双击事件"`, row)
            this.selectedFile = row
            if (row.isDir == 1 && this.fileType != 6) {
                this.$emit('fileClick', row)
            }
            if (row.isDir == 0) {
                // if (this.onlineEditBtnShow) {
                //     if (this.officeFileType.includes(row.extendName)) {
                //         // office 编辑页面
                //         this.$file.getFileOnlineEditPathByOffice(row)
                //     } else if (this.markdownFileType.includes(row.extendName)) {
                //         // markdown 编辑浮层
                //         this.$openBox.markdownPreview({
                //             fileInfo: row,
                //             editable: true
                //         })
                //     } else {
                //         // 代码编辑对话框
                //         this.$openBox.codePreview({ fileInfo: row, isEdit: true })
                //     }
                // } else if (this.seeBtnShow) {
                //     this.$file.handleFileNameClick(this.selectedFile, 0, [this.selectedFile])
                // }
            }
        },
        /**
         * 文件展示区域的空白处右键事件
         * @param {Document} event 右键事件对象
         */
        handleClickRight(event) {
            event.preventDefault()
            // 只有在全部页面才可以进行以下操作
            this.$openBox
                .contextMenu({
                    selectedFile: undefined,
                    domEvent: event,
                    serviceEl: this
                })
                .then((res) => {
                    if (res === 'confirm') {
                        this.reloadPathTree()
                        //this.$store.dispatch('showStorage') //  刷新存储容量
                    }
                })
        },
        reloadPathTree() {
            console.log("reloadPathTree:::调用");
            this.$emit('reloadPathTree', this.searchStr) //  刷新文件列表
        },
        refreshFavorite() {
            this.$emit('refreshFavorite') // 刷新收藏夹
        },
        // 清空多选项
        selectedFileList(newValue) {
            if (this.fileModel === 0) {
                this.$refs.fileTable.rowSelection.selectedRowKeys = []
            }
            console.log("new value:::", newValue);
            this.$store.commit('changeSelectedFiles', newValue)
            this.$store.commit('changeIsBatchOperation', newValue.length !== 0)
        },
        handleDragEnter(event) {
            event.preventDefault();
            // Add visual feedback or styles when element is dragged over
            // event.target.classList.add("drag-over");
        },
        handleDragOver(event) {
            event.preventDefault();
            // Necessary to allow drop event to fire
        },
        handleDragLeave(event) {
            // Remove visual feedback or styles when element is dragged out
            // event.target.classList.remove("drag-over");
        },
        handleDrop(event) {
            event.preventDefault();
            console.log(`output->event.target`, event.target)
            // Remove visual feedback or styles when element is dropped
            // event.target.classList.remove("drag-over");
 
            // Handle the dropped data
            // const droppedData = event.dataTransfer.getData("text/plain");
            console.log("Dropped data:", localStorage.getItem("dragFile"));
            console.log(`output->`, this.$store.getters.filePath)
 
            let isBatch = localStorage.getItem("isBatch")
            // 本地其它标签页面可以获取文件id
            let filePathId = localStorage.getItem("dragFile")
 
            // 当前标签页可以获取,有值说明在当前页面,不复制
            let sessionFilePathId = sessionStorage.getItem("dragFile")
            console.log(`output->111111111111`, filePathId && (!sessionFilePathId || filePathId !== sessionFilePathId))
            console.log(`output->111111111112`, filePathId)
            console.log(`output->111111111113`, sessionFilePathId)
            // console.log(`output->isBatch`, isBatch)
            localStorage.removeItem("isBatch")
            localStorage.removeItem("dragFile")
            sessionStorage.removeItem("dragFile")
            if (filePathId && (!sessionFilePathId || filePathId !== sessionFilePathId)) {
 
 
 
                if (isBatch) {
                    let data = {
                        filePath: this.$store.getters.filePath,
                        files: filePathId
                    }
                    this.loading = true
                    postAction('/document/batchcopyfile', data)
                        .then((res) => {
                            this.loading = false
 
                            if (res.success) {
                                this.$message.success('复制成功')
                                this.reloadPathTree()
                            } else {
                                this.$message.error(res.message)
                            }
                        })
                        .catch(() => {
                            this.loading = false
                        })
                } else {
                    let data = {
                        filePath: this.$store.getters.filePath,
                        userFileId: JSON.parse(filePathId)
                    }
                    console.log(`output->dgdata`, data)
                    this.loading = true
                    postAction('/document/copyfile', data)
                        .then((res) => {
                            this.loading = false
                            if (res.success) {
                                this.$message.success('复制成功')
 
                                this.reloadPathTree()
                            } else {
                                this.$message.error(res.message)
                            }
                            localStorage.removeItem("dragFile")
 
                        })
                        .catch(() => {
                            this.loading = false
                        })
                }
 
 
            }
 
        },
        handleDragStart(item) {
            console.log(`output->dragitem`, item)
 
 
 
            localStorage.setItem("dragFile", JSON.stringify(item))
            sessionStorage.setItem("dragFile", JSON.stringify(item))
 
 
 
 
        },
        showModal() {
            this.$store.commit('changeCompareModal', true);
        },
        handleOk(e) {
 
            e.preventDefault();
            this.$store.commit('changeCompareModal', false);
            this.$store.commit('clearCompareList', []);
        },
 
 
    },
    computed: {
        // 是否批量操作
        isBatchOperation() {
            return this.$store.state.fileList.isBatchOperation
        },
        // 文件查看模式 0列表模式 1网格模式 2 时间线模式
        fileModel() {
            return this.$store.getters.fileModel
        },
        fileNum() {
            return this.fileList ? this.fileList.length : 0
        },
        fileType() {
            return this.$store.getters.fileType
        },
        flow() {
            return this.$store.getters.flow
        },
        compareModal() {
            return this.$store.getters.compareModal
        },
        compareList() {
            return this.$store.getters.compareList
        },
 
        surplusFlow() {
            return this.$store.getters.surplusFlow
        },
        percent() {
            return ((this.flow - this.surplusFlow) / this.flow) * 100
        },
        // 下载权限文件id集合
        downloadPrem() {
            return this.$store.getters.downloadPrem
        },
        // 查看按钮是否显示
        seeBtnShow() {
            return (this.fileType !== 6 && this.downloadPrem.includes(this.selectedFile.pathId)) || this.fileType === 8
        },
        // 在线编辑按钮是否显示
        onlineEditBtnShow() {
            return (
                ![6, 8].includes(this.fileType) &&
                (this.officeFileType.includes(this.selectedFile.extendName) ||
                    this.markdownFileType.includes(this.selectedFile.extendName) ||
                    this.fileSuffixCodeModeMap.has(this.selectedFile.extendName))
            ) && this.downloadPrem.includes(this.selectedFile.pathId)
        },
    }
}
</script >
 
<style lang="less" scoped>
.list-container {
    height: calc(100vh - 225px);
 
    .file-list-content {
        background-color: white;
        overflow: auto;
    }
 
    .file-list-footer {
        display: flex;
        justify-content: space-between;
        background-color: white;
        height: 40px !important;
        padding: 0 30px !important;
        border-top: 1px solid rgb(211, 211, 211);
        line-height: 39px;
        box-shadow: 0px 0px 20px 0px #e3e3e3;
        z-index: 19;
    }
}
</style>