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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<template>
  <div >
    <a-layout v-loading="loading" class="side">
      <a-layout-content >
        <a-tabs type="card" @change="tabsChange" class="side-tree-content" >
          <a-tab-pane key="1" tab="全部文件" >
            <a-tree
                :expandedKeys.sync="expandedKeys"
                :selectedKeys="selectedKeys"
                multiple
                show-icon
 
                :tree-data="treeData"
                @expand = "onLoadData"
                @select="selectTreeNode"
              >
 
              <a-icon slot="folder" type="folder" />
              <span slot="custom" slot-scope="item">
                <span :id="item.path" :style="item.permission==false?'': 'color:#b9b9b9'">{{item.title}}</span>
 
              </span>
              </a-tree>
          </a-tab-pane>
          <a-tab-pane key="2" tab="我的收藏">
 
            <a-list  size="small"  :data-source="favoriteData" >
              <a-list-item slot="renderItem" slot-scope="item" @click="handleItemClick(item)" style="cursor: pointer"  @contextmenu.prevent="handleStarRightClick(item,$event)">
               <a-icon type="folder" /> {{item.fileName}}
              </a-list-item>
            </a-list>
          </a-tab-pane>
        </a-tabs>
 
      </a-layout-content>
      <a-layout-footer class='side-footer'>
        <a-row>
            <a-col :span="12" class="recovery btn" @click="handleRecoveryClick">
              <a-icon type="delete" />回收站
            </a-col>
            <a-col :span="12" class="share btn" @click="handleShareClick">
              <a-icon type="share-alt" />我的分享
            </a-col>
        </a-row>
    </a-layout-footer>
    </a-layout>
  </div>
</template>
 
<script>
 
import {
  deleteAction,
  getAction,
  downFile,
  getFileAccessHttpUrl, getDeskDownloadHttpUrl
} from '@/api/manage'
import { resolve } from 'path'
 
export default {
  name: 'fileSide',
 
  data() {
    return {
      result: null,
      expandedKeys: [],
      selectedKeys: [],
      selectedNode: null,
      dirMap: [],
      treeData: [],
      loading: false,
      url: {
        docTree: "/document/getAsyncTree",
        init: "/document/init"
      },
      favoriteData: []
    }
  },
  methods: {
    // 加载树形目录
    loadDocTree(treeNode) {
      console.log("左侧菜单:::加载树:::调用", new Date().getMinutes() + ":" + new Date().getSeconds())
      var param = null;
      console.log("点击的右侧列表:::", treeNode);
      console.log("选择的节点:::",this.selectedNode);
      var target = undefined;
      var path;
 
      if (treeNode){  // 点击右侧列表或左侧收藏夹列表
        var var_filePath = treeNode.filePath+"/" + treeNode.fileName
        console.log("var_filePath::", var_filePath);
        if (this.selectedNode.pathId == treeNode.pathId) {  // 点击的当前文件夹
            target = treeNode.pathId;
            path = var_filePath;
        } else {
          this.selectedNode.children.forEach((item)=>{ // 循环判断点击的是否是当前文件夹的子文件
            console.log("item.pathId == treeNode.pahtId",item.pathId , treeNode.pathId);
 
            if (item.pathId == treeNode.pathId || var_filePath.startsWith(item.path+"/")) { // 点击的为当前选择节点的子文件或后代文件
              console.log("点击右侧后得到的节点:::",item);
              this.selectedNode = item;
              target = treeNode.pathId;
              path = var_filePath;
              return;
            }
 
          })
        }
        // 点击的收藏列表和当前选择节点没有任何关系,刚将当前选择节点定位到根节点;后台从根节点遍历直到找到点击的文件。
        if (target==undefined) {
          this.selectedNode = this.result
          target = treeNode.pathId
          path = var_filePath
        }
 
      }  else if(this.selectedNode != null) {
        target = this.selectedNode.pathId
        path = this.selectedNode.path
      }
 
      console.log("target:::", target);
      //console.log("点击右侧后得到的节点:::",this.selectedNode);
      if (this.selectedNode ) {
 
        param = {id: this.selectedNode.id,
        key: this.selectedNode.key,
        parentId: this.selectedNode.parentId,
        path: path,
        pathId: this.selectedNode.pathId,
        title: this.selectedNode.title,
        isLeaf: this.selectedNode.isLeaf,
        targetId: target}
      }
 
      console.log("params:::", param);
      this.loading = true
      this.$emit("onLoading",true)
      getAction(this.url.docTree, param).then(res=>{ // 发送请求到后台进行查询
 
        console.log("后台加载到的左侧树数据:::",res);
        console.log("选择的节点KEYS::", this.selectedKeys);
        if(this.selectedNode == null) {
        //  this.treeData = res.result?res.result.children:[];
          this.result = res.result;
          this.selectedNode = res.result
        } else {
          this.selectedNode.children = res.result.children
 
        }
        this.treeData = this.result.children;
        console.log("左侧菜单:::构造树:::", new Date().getMinutes() + ":" + new Date().getSeconds())
        // 构造key-node Map
        this.buildDirMap(this.treeData);
 
        var favNode = res.target
        console.log("favNode:::", favNode);
        this.selectKeys(favNode.key)
        if (this.fileType === 0) {  // 文件夹,查询子文件
          //this.$emit('selectPath',this.selectedNode.path,this.selectedNode.key, this.selectedNode.pathId)
        }
        console.log("左侧菜单:::完成树:::", new Date().getMinutes() + ":" + new Date().getSeconds())
      }).finally(()=>{
        this.loading = false
        this.$emit("onLoading",false)
      })
    },
 
 
    // 加载下载量使用情况
    loadFlow() {
      getAction('/document/loadFlow').then( res => {
        console.log("loadFlow::::", res);
        if (res.success) {
          this.$store.commit('changeFlow', res.result.flow)
          this.$store.commit('changeSurplusFlow', res.result.surplusFlow)
        }
      })
    },
 
 
 
    // 异步加载展开节点
    onLoadData(a,treeNode) {
      console.log("展开:",a ,"treeNode:" , treeNode);
       //if (!treeNode.expanded) return
       return new Promise(resolve => {
        console.log("异步加载的treeNode:" , treeNode);
        if (treeNode.node.dataRef.children.length > 0) {
          resolve()
          return
        }
         this.loading = true
         this.$emit("onLoading",true)
        getAction(this.url.docTree, treeNode.node.dataRef).then(res=>{
          console.log("异步加载内容::", res)
          treeNode.node.dataRef.children = res.result.children
          this.treeData = [...this.treeData]
          treeNode.expanded = false
          resolve()
        }).finally(() => {
          this.loading = false;
          this.$emit("onLoading",false)
        })
       })
    },
 
    refrushCurrentNode() {
 
    },
 
    // 构造文件夹map
    buildDirMap(tree) {
      tree.forEach((item, index) => {
        this.dirMap[item.path] = item.key
        this.buildDirMap(item.children)
      })
    },
 
 
 
    // 加载收藏夹文件
    loadFavorite() {
      this.favoriteData = []
      getAction("/favorite/list",null).then(res => {
        if (res.success) {
          this.favoriteData = res.result?res.result:[]
        }
 
      })
 
    },
 
 
    // 初始化本地文件目录到服务器数据库
    initDocTree() {
      getAction(this.url.init, null).then(res => {
        console.log("初始化完成");
      })
    },
    // 节点点击事件
    selectTreeNode(keys,e) {
      //this.onLoadData(keys,e);
 
      console.log("keys:::" , keys);
      console.log("e::",e.node);
      this.selectedNode = e.node.dataRef;
      this.loadDocTree()
      this.$emit('selectPath',this.selectedNode.path,this.selectedNode.key,this.selectedNode.pathId)
      this.pushExpandedKeys(this.selectedNode.key)
      this.pushSelectedKeys(this.selectedNode.key)
 
    },
 
    // 展开节点及前置节点
    pushExpandedKeys(key) {
      console.log("key____",key);
 
      let index = key.indexOf("-")
      while (index != -1) {
        //console.log("KEY::index:::",index);
         let subKey = key.substring(0,index);
          //console.log("subkey",subKey);
          if (this.expandedKeys.indexOf(subKey) < 0) {
            this.expandedKeys.push(subKey)
        }
        index = key.indexOf("-",index + 1)
      }
      // let KeyArr = key.split("-")
 
      // for(let i = 0; i<= keyArr.length; i++){
      //   let subKey = key.substring(0,i);
      //     console.log("subkey",subKey);
      //   if (this.expandedKeys.indexOf(subKey) < 0) {
      //       this.expandedKeys.push(subKey)
      //   }
      // }
 
    },
    pushSelectedKeys(key) {
      this.selectedKeys.shift()
      this.selectedKeys.push(key);
    },
 
    // 点击面包屑时定位到点击的树节点
    selectKeys(key) {
      console.log("emitKey:::",key);
      this.pushSelectedKeys(key);
      // 从展开的节点列表中删除点击的KEY及其父节点之外的节点,只展开点击的节点及其父节点
      for (var i=0; i< this.expandedKeys.length; i++) {
        let sub = this.expandedKeys[i]+"-";
        let parent = key+"-"
        if(parent.indexOf(sub) <0 ) {
          this.expandedKeys.splice(i,1);
          i--
        }
      }
      this.pushExpandedKeys(key)
      this.findNodeByKey(key)
      if (this.fileType == 6) {
        this.$emit('selectPath','/回收站',this.selectedNode.key,this.selectedNode.pathId)
      } else {
        this.$emit('selectPath',this.selectedNode.path,this.selectedNode.key,this.selectedNode.pathId)
      }
 
       console.log("展开的节点列表:::", this.expandedKeys)
        let ele = document.getElementById(this.selectedNode.path);
        ele && ele.scrollIntoView({block: 'end', behavior: 'smooth'});
 
    },
    // // 根据文件名在当前目录下查询节点
    // findTreeNode(fileName) {
    //   console.log("this.node222",this.selectedNode);
    //   this.findNodeByKey(this.selectedNode.key)
    //   this.selectedNode.children.forEach(element => {
    //     if(element.title == fileName) {
    //       console.log("element:::",element);
    //       this.selectedNode = element;
    //       this.$emit('selectPath',element.path, element.key)
 
    //       this.pushSelectedKeys(element.key)
 
    //       this.expandedKeys.push(element.key);
    //       console.log("findExpandedKeys::::", this.expandedKeys);
    //     }
 
    //   });
    //   this.pushExpandedKeys(this.selectedNode.key)
    //   console.log("thisFilePath::",this.selectedNode.path);
    //   this.$nextTick(()=>{
    //     let ele = document.getElementById(this.selectedNode.path);
    //     ele && ele.scrollIntoView({block: 'end', behavior: 'smooth'});
    //   })
 
    // },
    // 根据key找到原始节点
    findNodeByKey(key) {
       let indexArr = key.split('-');
     // indexArr.shift();
      indexArr.forEach((ele,arrIndex) => {
        //console.log("index:::" , ele);
        if(arrIndex >= 1)  {
          this.selectedNode = this.selectedNode.children[ele]
        } else {
          this.selectedNode = this.result
        }
        //console.log("this.node111",this.selectedNode);
      })
 
    },
    // 点击回收站事件
    handleRecoveryClick() {
      console.log("回收站");
      this.$emit('recoveryFile')
      //this.$emit('recoveryFile')
    },
    // 点击我的分享事件
    handleShareClick() {
      this.$emit('selectPath','/我的分享',"")
      console.log("我的分享");
    },
    // 标签点击事件
    tabsChange(key) {
      console.log("tabKEY::",key);
    },
    // 列表或收藏列表文件点击事件
    handleItemClick(item) {
      console.log("FileItemClick::",item);
      //let starPath = (item.filePath === "/"?"":item.filePath)+"/"+item.fileName
      this.loadDocTree(item)
      // let starKey = this.dirMap[starPath]
      // console.log("starPath::",starPath);
      // this.selectKeys(starKey)
      // this.$emit('selectPath',starPath,starKey,item.pathId)
 
    },
    // 收藏列表右键事件
    handleStarRightClick(item,event) {
      event.preventDefault()
                    this.$openBox
                        .contextMenu({
                            selectedFile: item,
              callType: 'star',
                            domEvent: event
                        })
                        .then((res) => {
              console.log("CALLBACK::::",res);
                            if (res === 'confirm') {
                                this.loadFavorite()
 
              }
 
                        })
    }
  },
  created() {
 
   // this.initDocTree();
    this.loadDocTree()
    this.loadFavorite()
    this.loadFlow()
  },
  computed: {
    fileType() {
      return this.$store.getters.fileType
    }
  }
 
}
</script>
 
<style lang="less" scoped>
 
 
  .side {
 
    height: calc(100vh - 225px);
    background-color: white;
    /deep/ .ant-tabs-bar  {
  margin: 0px !important;
}
    /deep/ .ant-tabs-content {
        width: 100%;
        height: calc(100vh - 309px);
        overflow: auto;
        padding: 0 5px;
    }
    /deep/ .ant-list {
      padding: 0 10px;
    }
 
    .side-footer{
      background-color: white;
      height: 40px !important;
      padding: 0px 0px !important;
      border-top: 1px solid rgb(211, 211, 211);
      line-height: 39px;
      box-shadow: 0px 0px 20px 0px #e3e3e3;
      text-align: center;
      cursor: pointer;
      .btn{
        &:hover{
          background-color:#F5F7FA;
        }
      }
      .recovery{
        border-right: 1px solid #cecece;
      }
    }
  }
</style>