File size: 2,564 Bytes
0070fce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<script lang="ts" setup>
// @ts-ignore
import { RecycleScroller } from '@zanllp/vue-virtual-scroller'
import '@zanllp/vue-virtual-scroller/dist/vue-virtual-scroller.css'
import FileItem from '@/components/FileItem.vue'
import { useFilesDisplay, useHookShareState } from '@/page/fileTransfer/hook'
import { getFileTransferDataFromDragEvent, toRawFileUrl, uniqueFile } from '@/util/file'
import { ref, watchEffect, toRaw } from 'vue'
import { GridViewFile, useGlobalStore } from '@/store/useGlobalStore'
import { useTagStore } from '@/store/useTagStore'

const g = useGlobalStore()
const { stackViewEl } = useHookShareState().toRefs()
const { itemSize, gridItems, cellWidth } = useFilesDisplay()
const tag = useTagStore()

const props = defineProps<{
  tabIdx: number
  paneIdx: number
  id: string,
  removable?: boolean
  allowDragAndDrop?: boolean,
  files: GridViewFile[]
  paneKey: string
}>()


const files = ref(props.files ?? [])
const onDrop = async (e: DragEvent) => {
  const data = getFileTransferDataFromDragEvent(e)
  if (props.allowDragAndDrop && data) {
    files.value = uniqueFile([...files.value, ...data.nodes])
  }
}

const onDeleteClick = (idx: number) => {
  files.value.splice(idx, 1)
}


watchEffect(() => {
  g.pageFuncExportMap.set(props.paneKey, {
    getFiles: () => toRaw(files.value),
    setFiles: (_files: GridViewFile[]) => files.value = _files
  })
})

</script>
<template>
  <div class="container" ref="stackViewEl" @drop="onDrop">
    <RecycleScroller ref="scroller" class="file-list" :items="files.slice()" :item-size="itemSize.first"
      key-field="fullpath" :item-secondary-size="itemSize.second" :gridItems="gridItems">
      <template v-slot="{ item: file, index: idx }">
        <file-item :idx="idx" :file="file" :cell-width="cellWidth" :enable-close-icon="props.removable"
          @close-icon-click="onDeleteClick(idx)" :full-screen-preview-image-url="toRawFileUrl(file)"
          :extra-tags="file?.tags?.map(tag.tagConvert)" :enable-right-click-menu="false" />
      </template>
    </RecycleScroller>
  </div>
</template>
<style scoped lang="scss">
.container {
  background: var(--zp-secondary-background);

  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;

  .actions-panel {
    padding: 8px;
    background-color: var(--zp-primary-background);
  }

  .file-list {
    flex: 1;
    list-style: none;
    padding: 8px;
    height: var(--pane-max-height);
    width: 100%;

    .hint {
      text-align: center;
      font-size: 2em;
      padding: 30vh 128px 0;
    }
  }
}
</style>