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
<template>
    <!-- 复制文件-选择目标路径 -->
    <el-dialog title="选择目标路径" :visible.sync="visible" :close-on-click-modal="false" @open="handleDialogOpen"
        @close="handleDialogClose">
        <div class="el-dialog-div">
            <!-- 选择的目标路径 -->
            <div class="target-path">
                <span class="label">目标路径:</span>
                <el-input class="content" v-model="targetPath" readonly size="small"></el-input>
            </div>
            <!-- 文件目录树 -->
            <el-tree :props="{
                children: 'children',
                label: 'title',
                isLeaf: 'isLeaf',
                permission: 'permission'
 
            }" :highlight-current="true" :expand-on-click-node="false" :default-expanded-keys="defaultExpandedKeys"
                node-key="key" v-loading="loading" lazy @node-click="handleNodeClick" :load="onLoadData">
                <span class="custom-tree-node" slot-scope="{ node, data }">
                    <span class="label" :style="data.permission == false ? '' : 'color:#b9b9b9'">{{ node.label }}</span>
                    <!-- <el-button
                        class="add-folder-btn"
                        type="text"
                        size="mini"
                        v-if="!data.permission"
                        @click.stop="handleAddFolderBtnClick(data)"
                    >
                        新建文件夹
                    </el-button> -->
                </span>
            </el-tree>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button @click="handleDialogClose">取 消</el-button>
            <el-button type="primary" :loading="sureBtnLoading" @click="handleDialogSure">确 定</el-button>
        </div>
    </el-dialog>
</template>
 
<script>
//import { getFoldTree, copyFile } from '_r/file.js'
import {
    getAction,
    postAction
} from '@/api/manage'
export default {
    name: 'CopyFileDialog',
    data() {
        return {
            visible: false, //  对话框是否可见
            targetPath: '/', //  目标路径
            fileTree: [], //  文件夹目录树
            loading: false, //  文件夹目录树 loading 状态
            defaultExpandedKeys: [],
            sureBtnLoading: false //  确定按钮 loading 状态
        }
    },
 
    methods: {
        /**
         * 取消按钮点击事件 & 对话框关闭的回调
         */
        handleDialogClose() {
            this.visible = false
            this.callback('cancel')
        },
        /**
         * 对话框打开的回调
         */
        handleDialogOpen() {
            this.initFileTree()
        },
        /**
         * 初始化文件目录树
         */
        initFileTree(id) {
            this.defaultExpandedKeys = id ? [id] : []
            // this.loading = true
            // getAction('/document/getAsyncTree').then((res) => {
            //     this.loading = false
            //     if (res.success) {
            //         this.fileTree = res.result.children
            //         console.log("fileTree::::", this.fileTree);
            //         this.defaultExpandedKeys = id ? [id] : []
            //     } else {
            //         this.$message.error(res.message)
            //     }
            // })
        },
        /**
         * 目录树节点点击回调函数
         * @description 将当前节点中的文件夹路径传递给父组件
         * @param {object} data 当前点击的节点信息
         */
        handleNodeClick(data) {
            console.log("复制:DATA:", data);
            if (data.permission) {
                this.$message.warning("暂无权限!")
                return
            }
            getAction("/pathPermission/hasManagePrem", { filePath: data.path }).then(res => {
 
                console.log(res);
                if (!res) {
                    this.$message.warning("暂无权限")
                    return
                } else {
                    this.targetPath = data.path ? data.path : '/'
                }
            })
 
        },
 
 
        // 异步加载展开节点
        onLoadData(node, resolve) {
            console.log("node:::", node);
            var param = null;
            var res;
            if (node.level === 0) {
 
            } else {
                param = node.data
            }
 
            getAction('/document/getAsyncTree', param).then(res => {
                console.log("异步加载内容::", res)
                res = res.result.children
                return resolve(res);
            })
        },
 
        /**
         * 新建文件夹按钮点击事件
         * @description 调用新建文件夹服务,并在弹窗确认回调事件中刷新文件夹树
         */
        handleAddFolderBtnClick(data) {
            this.$openDialog
                .addFolder({
                    filePath: data.path || '/'
                })
                .then(() => {
                    this.initFileTree(data.key)
                })
        },
        /**
         * 确定按钮点击事件
         * @description 调用复制文件接口
         */
        handleDialogSure() {
 
            if (this.targetPath === '/') {
                this.$message.warning("不可复制到根目录")
                return
            }
            this.sureBtnLoading = true
            if (this.isBatchOperation) {
                //  批量移动
                let data = {
                    filePath: this.targetPath,
                    files: JSON.stringify(this.fileInfo)
                }
                postAction('/document/batchcopyfile', data)
                    .then((res) => {
                        this.sureBtnLoading = false
                        if (res.success) {
                            this.$message.success('复制成功')
                            this.visible = false
                            this.fileInfo = {}
                            this.callback('confirm')
                        } else {
                            this.$message.error(res.message)
                        }
                    })
                    .catch(() => {
                        this.sureBtnLoading = false
                    })
            } else {
                let data = {
                    filePath: this.targetPath,
                    userFileId: this.fileInfo.pathId
                }
                postAction('/document/copyfile', data)
                    .then((res) => {
                        this.sureBtnLoading = false
                        if (res.success) {
                            this.$message.success('复制成功')
                            this.visible = false
                            this.callback('confirm')
                        } else {
                            this.$message.error(res.message)
                        }
                    })
                    .catch(() => {
                        this.sureBtnLoading = false
                    })
            }
 
        }
    }
}
</script>
 
<style lang="less" scoped>
@import '~@assets/file/less/varibles.less';
@import '~@assets/file/less/mixins.less';
 
/deep/ .el-dialog {
    .el-dialog__header {
        display: flex;
    }
 
    .el-dialog__body {
        padding: 10px 30px;
 
        .el-dialog-div {
            height: 300px;
            overflow: auto;
            .setScrollbar(6px);
 
            .target-path {
                display: flex;
                align-items: center;
 
                .label {
                    width: 80px;
                }
 
                .content {
                    flex: 1;
                }
            }
 
            .el-tree {
                .el-tree-node__content {
                    height: 34px;
                    font-size: 16px;
 
                    .el-icon-caret-right {
                        font-size: 18px;
                    }
 
                    .custom-tree-node {
                        flex: 1;
                        display: flex;
                        align-items: center;
                        justify-content: space-between;
                        font-size: 14px;
                        padding-right: 8px;
                    }
 
                    .add-folder-btn {
                        display: none;
                    }
 
                    &:hover {
                        .add-folder-btn {
                            display: block;
                        }
                    }
                }
 
                .el-tree-node.is-current>.el-tree-node__content {
                    color: @Primary;
                }
            }
        }
    }
}
</style>