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
<template>
    <a-table :columns="columns" :data-source="fileList" rowKey="pathId" :row-selection="rowSelection" size="middle"
        :customRow="customClick" :pagination="false" :scroll="scrollY">
        <span slot="fileName" slot-scope="text, record">
            <span style="cursor: pointer" @click="handleClickFileName(record)" @dblclick="handDbclickFileName(record)">
 
                {{ record.isDir == 1 ? text : text + "." + record.extendName }}
            </span>
        </span>
        <span slot="fileImage" slot-scope="text, record">
            <img :src="$file.setFileImg(record)" :title="`${record.isDir ? '' : ''}`"
                @dblclick="handDbclickFileName(record)" style="width: 30px; max-height: 30px; cursor: pointer" />
        </span>
        <span slot="fileSize" slot-scope="text,record">
            {{
                record.isDir === 0
                ? $file.calculateFileSize(record.fileSize)
                : ''
            }}
        </span>
    </a-table>
</template>
<script>
 
 
 
export default {
    props: ['fileList', 'searchStr'],
    data() {
        return {
            treeKeys: "",
            customClick: record => ({
                on: {
                    contextmenu: e => {
                        console.log("tablecustomclickContextMenu", e);
                        this.handleContextMenu(record, e);
                    }
                }
            }),
 
            columns: [
                {
                    title: '',
                    dataIndex: 'isDir',
                    key: 'isDir',
                    align: 'center',
                    width: 50,
                    scopedSlots: { customRender: 'fileImage' },
 
                },
                {
                    title: '文件名',
                    dataIndex: 'fileName',
                    key: 'fileName',
                    scopedSlots: { customRender: 'fileName' },
 
                    sorter: (a, b) => {
                        if (a.fileName > b.fileName) {
                            return 1
                        } else if (a.fileName < b.fileName) {
                            return -1
                        } else {
                            return 0
                        }
                    },
                    sortDirections: ['descend', 'ascend'],
                    customHeaderCell: column => {
                        return {
                            style: {
                                'min-width': '200px',
 
                            }
                        }
                    },
                    customCell: column => {
                        return {
                            style: {
                                'min-width': '200px',
 
                            }
                        }
                    }
 
                },
 
                {
                    title: '文件类型',
                    dataIndex: 'extendName',
                    key: 'extendName',
                    width: 120,
                    sorter: (a, b) => {
                        if (a.extendName > b.extendName) {
                            return 1
                        } else if (a.extendName < b.extendName) {
                            return -1
                        } else {
                            return 0
                        }
                    },
                    sortDirections: ['descend', 'ascend'],
                },
                {
                    title: '大小',
                    dataIndex: 'fileSize',
                    key: 'fileSize',
                    width: 100,
                    scopedSlots: { customRender: 'fileSize' },
                    sorter: (a, b) => a.fileSize - b.fileSize,
                    sortDirections: ['descend', 'ascend'],
                    align: 'right'
                },
                {
                    title: '修改日期',
                    key: 'updateTime',
                    dataIndex: 'updateTime',
                    width: 180,
                    sorter: true,
                    sortDirections: ['descend', 'ascend'],
 
                },
 
            ],
            rowSelection: {
                selectedRowKeys: [],
                onChange: this.tableRowChange
            },
            //selectedRowKeys: [],
            scrollY: {},
 
        };
    },
    mounted() {
        this.scrollY = { x: true, y: window.innerHeight - 311 }
        window.onresize = () => {
            this.scrollY = { x: true, y: window.innerHeight - 311 }
        }
    },
    methods: {
 
        // 文件名点击事件
        handleClickFileName(record) {
            console.log("fileNameclick", record)
            this.$emit('fileClick', record)
            let ele = document.getElementById(record.filePath + '/' + record.fileName);
            ele && ele.scrollIntoView({ block: 'end', behavior: 'smooth' });
        },
        handDbclickFileName(record) {
            clearTimeout(this.timer)
            this.timer = null;
            console.log(`output->双击`)
            this.$emit('fileDbclick', record)
 
        },
 
        tableRowChange(keys, rows) {
            console.log("tableRowChange:::", keys);
            this.rowSelection.selectedRowKeys = keys
            this.$store.commit('changeSelectedFiles', rows)
            this.$store.commit('changeIsBatchOperation', rows.length !== 0)
        },
        /**
             * 表格某一行右键事件
             * @description 打开右键菜单
             * @param {object} row 当前行数据
             * @param {object} column 当前列数据
             * @param {object} event 当前右键元素
             */
        handleContextMenu(row, event) {
            // 阻止右键事件冒泡
            event.cancelBubble = true
            // xs 以上的屏幕
            event.preventDefault()
            let keys = [];
            keys.push(row.id)
            //this.selectedRowKeys=keys //  选中当前行
            this.$openBox
                .contextMenu({
                    selectedFile: row,
                    domEvent: event
                })
                .then((res) => {
                    //this.selectedRowKeys = [] //  取消当前选中行
                    if (res === 'confirm') {
                        this.$emit('reloadPathTree', this.searchStr) //  刷新文件列表
                    } else if (res === 'open') {
                        this.handleClickFileName(row);
                    } else if (res === 'refreshFavorite') {
                        this.$emit("refreshFavorite")
                        this.$message.success('收藏成功')
                    }
                })
        },
    },
    computed: {
        screenWidth() {
            return document.body.clientWidth
        },
        targetOffset() {
            console.log("window.innerHeight", window.innerHeight);
            return window.innerHeight;
        },
    }
};
</script>
 
<style lang="less">
.file_name {
    cursor: pointer
}
 
.ant-table-body,
.ant-table-header {
    overflow: auto !important;
}
</style>