gaoshp
2024-06-16 5be78f8d80e78ad76f5f322a0ea1f47105fffe6f
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
<!--
 * @Date: 2024-06-12 22:07:23
 * @LastEditors: Sneed
 * @LastEditTime: 2024-06-16 16:18:43
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/dnc/craft/document/File.vue
-->
<template>
    <div>
        <scDialog style="min-height: 400px;" v-model="visible">
            <el-tabs v-model="activeName" type="card" class="demo-tabs" @tab-click="handleClick">
                <el-tab-pane label="我的文档" name="1">
                    <el-container v-if="activeName == '1'">
                        <el-aside width="220px">
                            <el-row>
                                <el-col>
                                    <el-input style="width: 180px;" v-model="filterText" placeholder="请输入关键词进行过滤" />
                                </el-col>
                                <el-col style="margin-top: 8px;">
                                    <el-tree ref="treeRef" :expand-on-click-node="false" default-expand-all
                                        node-key="id" :data="treeData" :props="{
                                            label: 'name',
                                        }" @node-click="nodeClick" :filter-node-method="filterNode" highlight-current
                                        :current-node-key="selectNode?.id">
                                        <template #default="{ node, data }">
                                            <span :class="data.isGroup ? 'active' : ''" class="custom-tree-node">
                                                <span>{{
                                                    node.label || data.code }}</span>
                                            </span>
                                        </template>
                                    </el-tree>
                                </el-col>
                            </el-row>
 
                        </el-aside>
                        <el-container>
                            <el-header>
                                <el-input style="width: 180px;" v-model="searchKey" placeholder="请输入关键词进行过滤" />
                            </el-header>
                            <el-main v-if="selectNode?.id !== ''">
                                <scTable highlight-current-row ref="table" :apiObj="apiObj1"
                                    @selection-change="selectionChange" stripe>
                                    <el-table-column type="selection" width="50"></el-table-column>
                                    <el-table-column label="文件名称" prop="name">
                                    </el-table-column>
                                    <el-table-column label="文件路径" prop="allPathName"></el-table-column>
                                    <el-table-column label="大小" prop="contentLength"></el-table-column>
                                    <el-table-column label="版本" prop="version"></el-table-column>
                                    <el-table-column label="文件类型" prop="suffix"></el-table-column>
                                    <el-table-column label="更新时间" prop="updateTime"></el-table-column>
                                </scTable>
                            </el-main>
                        </el-container>
 
 
                    </el-container>
                </el-tab-pane>
                <el-tab-pane label="工位文件" name="2">
                    <el-container v-if="activeName == '2'">
                        <el-aside width="220px">
                            <el-row>
                                <el-col>
                                    <el-input style="width: 180px;" v-model="filterText" placeholder="请输入关键词进行过滤" />
                                </el-col>
                                <el-col style="margin-top: 8px;">
                                    <el-tree :expand-on-click-node="false" :load="loadNode" ref="treeRef"
                                        default-expand-all node-key="id" :props="{
                                            label: 'name',
                                            hasChildren: 'id'
                                        }" @node-click="nodeClick" :filter-node-method="filterNode" highlight-current
                                        :current-node-key="selectNode?.id" lazy>
                                        <template #default="{ node, data }">
                                            <span :class="data.isGroup ? 'active' : ''" class="custom-tree-node">
                                                <span>{{
                                                    node.label || data.code }}</span>
                                            </span>
                                        </template>
                                    </el-tree>
                                </el-col>
                            </el-row>
                        </el-aside>
                        <el-container>
                            <el-header>
                                <el-input style="width: 180px;" v-model="searchKey" placeholder="请输入关键词进行过滤" />
                            </el-header>
                            <el-main v-if="selectNode?.id !== ''">
                                <scTable highlight-current-row ref="table" :apiObj="apiObj2"
                                    @selection-change="selectionChange" stripe>
                                    <el-table-column type="selection" width="50"></el-table-column>
                                    <el-table-column label="文件名称" prop="filename">
                                    </el-table-column>
                                    <el-table-column label="大小" prop="contentLength"></el-table-column>
                                    <el-table-column label="版本" prop="version"></el-table-column>
                                    <el-table-column label="文件类型" prop="suffix"></el-table-column>
                                    <el-table-column label="文件归属" prop="documentOwnershipDesc"></el-table-column>
                                    <el-table-column label="存储时间" prop="storageSpaceDec"></el-table-column>
                                </scTable>
                            </el-main>
                        </el-container>
                    </el-container>
                </el-tab-pane>
                <el-tab-pane label="归档文件" name="3">
                    <el-container v-if="activeName == '3'">
                        <el-aside width="220px">
                            <el-row>
                                <el-col>
                                    <el-input style="width: 180px;" v-model="filterText" placeholder="请输入关键词进行过滤" />
                                </el-col>
                                <el-col style="margin-top: 8px;">
                                    <el-tree :expand-on-click-node="false" :load="loadNode1" ref="treeRef"
                                        default-expand-all node-key="id" :props="{
                                            label: 'name',
                                            hasChildren: 'id'
                                        }" @node-click="nodeClick" :filter-node-method="filterNode" highlight-current
                                        :current-node-key="selectNode?.id" lazy>
                                        <template #default="{ node, data }">
                                            <span :class="data.isGroup ? 'active' : ''" class="custom-tree-node">
                                                <span>{{
                                                    node.label || data.name }}</span>
                                            </span>
                                        </template>
                                    </el-tree>
                                </el-col>
                            </el-row>
                        </el-aside>
                        <el-container>
                            <el-header>
                                <el-input style="width: 180px;" v-model="searchKey" placeholder="请输入关键词进行过滤" />
                            </el-header>
                            <el-main v-if="selectNode?.id !== ''">
                                <scTable highlight-current-row ref="table" :apiObj="apiObj3"
                                    @selection-change="selectionChange" stripe>
                                    <el-table-column type="selection" width="50"></el-table-column>
                                    <el-table-column label="文件名称" prop="filename">
                                    </el-table-column>
                                    <el-table-column label="大小" prop="contentLength"></el-table-column>
                                    <el-table-column label="版本" prop="version"></el-table-column>
                                    <el-table-column label="文件类型" prop="suffix"></el-table-column>
                                </scTable>
                            </el-main>
                        </el-container>
                    </el-container>
                </el-tab-pane>
                <el-tab-pane label="本地上传" name="4">
                    <el-upload style="margin-left: 8px;" :show-file-list="false" class="upload" :http-request="request">
                        <el-button type="primary">上传文件</el-button>
                    </el-upload>
                </el-tab-pane>
            </el-tabs>
            <template #footer>
                <el-button type="primary" @click="save">确定</el-button>
            </template>
        </scDialog>
    </div>
</template>
 
<script>
export default {
    watch: {
        filterText(val) {
            this.$refs.treeRef.filter(val)
        },
        'selectNode.id'(val) {
            this.$refs.table.reload()
        },
        activeName(val) {
            this.selection = []
            if (val === '1') {
                this.init()
            }
        }
    },
    data() {
        return {
            activeName: '1',
            visible: false,
            filterText: '',
            selectNode: {
                id: ''
            },
            treeData: [],
            fileType: 1,
            searchKey: '',
            selection: [],
            apiObj1: {
                get: async (data) => {
                    let params = {
                        ...data,
                        fileType: this.fileType,
                        parent: this.selectNode.id,
                        searchKey: this.searchKey
                        // ...this.params
                    }
                    return await this.$HTTP.get(`/api/blade-dnc/folder/file-page`, {}, { params }).then(res => {
                        return res
                    })
                }
            },
            apiObj2: {
                get: async (data) => {
                    let params = {
                        ...data,
                    }
                    let newData = {
                        fileType: `${this.fileType}`,
                        keywords: this.searchKey,
                        workstationId: this.selectNode.id
                    }
                    return await this.$HTTP.post(`/api/blade-dnc/transfer-directory/page`, {}, { params, data: newData }).then(res => {
                        return {
                            success: true,
                            code: 200,
                            data: {
                                ...res
                            }
 
                        }
 
                    })
                }
            },
            apiObj3: {
                get: async (data) => {
                    let params = {
                        ...data,
                    }
                    let newData = {
                        fileType: `${this.fileType}`,
                        keywords: this.searchKey,
                        arId: this.selectNode.id
                    }
                    return await this.$HTTP.post(`/api/blade-dnc/dnc-archive-directory-file/page`, {}, { params, data: newData }).then(res => {
                        return res
                    })
                }
            },
            id: ''
        }
    },
    created() {
    },
    methods: {
        open(fileType, id) {
            this.visible = true
            this.fileType = fileType
            this.activeName = '1'
            this.id = id
            this.init()
        },
        filterNode(value, data) {
            console.log(value, data)
            if (!value) return true
            return data.name.includes(value)
        },
        nodeClick(node) {
            this.selectNode = node
        },
        init() {
            this.$HTTP.get(`/api/blade-dnc/folder/folder-tree`).then(res => {
                this.treeData = [{
                    group: true,
                    id: 0,
                    name: '我的文档',
                    children: res.data
                }]
                this.selectNode = {
                    group: true,
                    id: 0,
                    name: '我的文档',
                }
            })
        },
        loadNode(node, resolve) {
            let id = node.level === 0 ? '' : node.data.id
            if (node.level === 0) {
                return this.$HTTP.get(`/api/blade-cps/group/getRootNode?groupCategory=1&groupType=group_workstation`).then(res => {
                    this.nodeClick(res.data)
                    resolve([res.data].map(v => {
                        return {
                            ...v,
                            name: v.name,
                            id: v.id
                        }
                    }))
                })
            } else {
                this.$HTTP.get(`/api/blade-cps/group/groupWorkstation/lazy?groupId=${id}`).then(res => {
                    resolve(res.data.map(v => {
                        return {
                            ...v,
                            name: v.title
                        }
                    }))
                })
            }
        },
        loadNode1(node, resolve) {
            let id = node.level === 0 ? '' : node.data.id
            this.$HTTP.get(`/api/blade-dnc/dnc-archive-directory/list?parentId=${id}`).then(res => {
                resolve(res.data.map(v => {
                    return {
                        ...v,
                    }
                }))
            })
        },
        selectionChange(selection) {
            this.selection = selection
        },
        request(options) {
            const formData = new FormData()
            formData.append('file', options.file)
            console.log(options)
            this.$HTTP.post(`/api/blade-resource/oss/endpoint/put-file`, formData).then(resFile => {
                this.$HTTP.post(`/api/blade-dnc/dnc-art-file/duplicate-validation-file`, {
                    artBagId: this.id, artFileAddVOList: [{
                        fileType: `${this.fileType}`,
                        filename: resFile.data.originalName,
                        objectKey: resFile.data.name
                    }]
                }).then(res => {
                    if (res.success) {
                        this.$HTTP.post(`/api/blade-dnc/dnc-art-file/insert`, [{
                            artBagId: this.id,
                            fileType: `${this.fileType}`,
                            contentLength: options.file.size,
                            filename: options.file.name,
                            link: resFile.data.link,
                            objectKey: resFile.data.name,
                            originalFilename: options.file.name,
                            sourceType: 3,
                            suffix: resFile.data.originalName.split('.').pop(),
                        }]).then(res => {
                            this.success(res)
                        })
                    } else {
                        this.$message.error(res.msg)
                    }
                })
 
            })
        },
        save() {
            console.log(this.selection)
            if (this.selection.length == 0) {
                this.visible = false
            } else {
                this.$HTTP.post(`/api/blade-dnc/dnc-art-file/duplicate-validation-file`, {
                    artBagId: this.id, artFileAddVOList: this.selection.map(v => {
                        return {
                            contentMd5: v.contentMd5,
                            fileType: `${this.fileType}`,
                            filename: v.filename,
                            objectKey: v.objectKey
                        }
                    })
                }).then(res => {
                    if (res.success) {
                        this.$HTTP.post(`/api/blade-dnc/dnc-art-file/insert`, this.selection.map(v => {
                            return {
                                artBagId: this.id,
                                contentLength: v.contentLength,
                                contentMd5: v.contentMd5,
                                contentType: v.contentType,
                                fileId: v.id,
                                fileType: `${this.fileType}`,
                                filename: v.filename,
                                link: v.link,
                                objectKey: v.objectKey,
                                suffix: v.suffix
                            }
                        })).then(res => {
                            this.success(res)
                        })
                    } else {
                        this.$message.error(res.msg)
                    }
                })
            }
        },
        success(res) {
            if (res.success) {
                this.visible = false
                this.$emit('success')
                this.$message.success(res.msg)
            }
        }
    },
}
</script>
 
<style lang="scss" scoped></style>