FileGrid.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <!-- 文件平铺 -->
  3. <div class="file-grid-wrapper">
  4. <a-spin :spinning="loading" tip="文件加载中……">
  5. <ul class="file-list">
  6. <li
  7. class="file-item"
  8. v-for="(item, index) in fileListSorted"
  9. :key="index"
  10. :title="$file.getFileNameComplete(item)"
  11. :style="`width: ${gridSize + 40}px; `"
  12. :class="item.userFileId === selectedFile.userFileId ? 'active' : ''"
  13. @click="$file.handleFileNameClick(item, index, fileListSorted)"
  14. @contextmenu.prevent="handleContextMenu(item, index, $event)"
  15. >
  16. <video
  17. :style="`height:${gridSize}px; width:${gridSize}px`"
  18. v-if="$file.isVideoFile(item)"
  19. :src="$file.setFileImg(item)"
  20. ></video>
  21. <a-image
  22. class="file-img"
  23. :src="$file.setFileImg(item)"
  24. :style="`width: ${gridSize}px; height: ${gridSize}px;`"
  25. fit="cover"
  26. v-else
  27. />
  28. <div class="file-name" v-html="$file.getFileNameComplete(item, true)"></div>
  29. <MoreOutlined
  30. class="file-operate"
  31. :class="`operate-more-${index}`"
  32. v-if="screenWidth <= 768"
  33. @click.stop="handleClickMore(item, $event)"
  34. />
  35. <div
  36. class="file-checked-wrapper"
  37. :class="{ checked: item.checked }"
  38. v-show="isBatchOperation"
  39. @click.stop.self="item.checked = !item.checked"
  40. >
  41. <a-checkbox
  42. class="file-checked"
  43. v-model:checked="item.checked"
  44. @click.stop="item.checked = !item.checked"
  45. ></a-checkbox>
  46. </div>
  47. </li>
  48. </ul>
  49. </a-spin>
  50. </div>
  51. </template>
  52. <script setup>
  53. import { ref, computed, watch, inject } from 'vue'
  54. import { useMyResourceStore } from '@/store/myResource'
  55. import { MoreOutlined } from '@ant-design/icons-vue'
  56. const props = defineProps({
  57. // 文件类型
  58. fileType: {
  59. required: true,
  60. type: Number
  61. },
  62. // 文件路径
  63. filePath: {
  64. required: true,
  65. type: String
  66. },
  67. fileList: Array, // 文件列表
  68. loading: Boolean
  69. })
  70. const emit = defineEmits(['getTableDataByType'])
  71. const myResourceStore = useMyResourceStore()
  72. const fileListSorted = ref([])
  73. const officeFileType = ref(['ppt', 'pptx', 'doc', 'docx', 'xls', 'xlsx'])
  74. const selectedFile = ref({})
  75. // 注入全局方法,如果这些方法是通过 provide 提供的
  76. const $file = inject('$file')
  77. const $openBox = inject('$openBox')
  78. // 计算属性
  79. const gridSize = computed(() => myResourceStore.gridSize)
  80. const isBatchOperation = computed(() => myResourceStore.isBatchOperation)
  81. const screenWidth = computed(() => myResourceStore.screenWidth)
  82. // 文件平铺模式 排序-文件夹在前
  83. watch(
  84. () => props.fileList,
  85. (newValue) => {
  86. fileListSorted.value = [...newValue]
  87. .sort((pre, next) => {
  88. return next.isDir - pre.isDir
  89. })
  90. .map((item) => {
  91. return {
  92. ...item,
  93. checked: false
  94. }
  95. })
  96. },
  97. { immediate: true }
  98. )
  99. // 批量操作模式 - 监听被选中的文件
  100. watch(
  101. () => fileListSorted.value.filter((item) => item.checked),
  102. (newValue) => {
  103. myResourceStore.changeSelectedFiles(newValue) // 假设 Pinia store 有 changeSelectedFiles 方法
  104. myResourceStore.changeIsBatchOperation(newValue.length !== 0) // 假设 Pinia store 有 changeIsBatchOperation 方法
  105. }
  106. )
  107. /**
  108. * 文件鼠标右键事件
  109. * @param {object} item 文件信息
  110. * @param {number} index 文件索引
  111. * @param {object} event 鼠标事件信息
  112. */
  113. const handleContextMenu = (item, index, event) => {
  114. // 阻止右键事件冒泡
  115. event.cancelBubble = true
  116. // xs 以上的屏幕
  117. if (screenWidth.value > 768) {
  118. selectedFile.value = item
  119. if (!isBatchOperation.value) {
  120. event.preventDefault()
  121. $openBox
  122. .contextMenu({
  123. selectedFile: item,
  124. domEvent: event
  125. })
  126. .then((res) => {
  127. selectedFile.value = {}
  128. if (res === 'confirm') {
  129. emit('getTableDataByType') // 刷新文件列表
  130. myResourceStore.showStorage() // 刷新存储容量,假设在 common 模块
  131. }
  132. })
  133. }
  134. }
  135. }
  136. /**
  137. * 更多图标点击事件
  138. * @description 打开右键菜单
  139. * @param {object} item 当前行数据
  140. * @param {object} event 当前右键元素
  141. */
  142. const handleClickMore = (item, event) => {
  143. selectedFile.value = item
  144. if (!isBatchOperation.value) {
  145. event.preventDefault()
  146. $openBox
  147. .contextMenu({
  148. selectedFile: item,
  149. domEvent: event
  150. })
  151. .then((res) => {
  152. selectedFile.value = {}
  153. if (res === 'confirm') {
  154. emit('getTableDataByType') // 刷新文件列表
  155. myResourceStore.showStorage() // 刷新存储容量,假设在 common 模块
  156. }
  157. })
  158. }
  159. }
  160. </script>
  161. <style lang="less" scoped>
  162. @import '@/style/myResource/varibles.less';
  163. @import '@/style/myResource/mixins.less';
  164. .file-grid-wrapper {
  165. border-top: 1px solid @BorderBase;
  166. .file-list {
  167. height: calc(100vh - 206px);
  168. overflow-y: auto;
  169. display: flex;
  170. flex-wrap: wrap;
  171. align-items: flex-start;
  172. align-content: flex-start;
  173. list-style: none;
  174. .setScrollbar(6px, transparent, #C0C4CC); // 假设 setScrollbar 混合宏已转换为 less
  175. .file-item {
  176. margin: 0 16px 16px 0;
  177. position: relative;
  178. padding: 8px;
  179. text-align: center;
  180. cursor: pointer;
  181. z-index: 1;
  182. &:hover {
  183. background: @tabBackColor;
  184. .file-name {
  185. font-weight: 550;
  186. }
  187. }
  188. .file-name {
  189. margin-top: 8px;
  190. height: 44px;
  191. line-height: 22px;
  192. font-size: 12px;
  193. word-break: break-all;
  194. .setEllipsis(2); // 假设 setEllipsis 混合宏已转换为 less
  195. :deep(.keyword) {
  196. // 使用 :deep() 或 ::v-deep 替代 >>>
  197. color: @Danger;
  198. }
  199. }
  200. .file-checked-wrapper {
  201. position: absolute;
  202. top: 0;
  203. left: 0;
  204. z-index: 2;
  205. background: rgba(245, 247, 250, 0.5);
  206. width: 100%;
  207. height: 100%;
  208. .file-checked {
  209. position: absolute;
  210. top: 16px;
  211. left: 24px;
  212. }
  213. }
  214. .file-checked-wrapper.checked {
  215. background: rgba(245, 247, 250, 0);
  216. }
  217. }
  218. .file-item.active {
  219. background: @tabBackColor;
  220. }
  221. }
  222. .right-menu-list {
  223. position: fixed;
  224. display: flex;
  225. flex-direction: column;
  226. background: #fff;
  227. border: 1px solid @BorderLighter;
  228. border-radius: 4px;
  229. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  230. z-index: 2;
  231. padding: 4px 0;
  232. color: @RegularText;
  233. .right-menu-item,
  234. .unzip-item {
  235. padding: 0 16px;
  236. height: 36px;
  237. line-height: 36px;
  238. cursor: pointer;
  239. &:hover {
  240. background: @PrimaryHover;
  241. color: @Primary;
  242. }
  243. i {
  244. margin-right: 8px;
  245. }
  246. }
  247. .unzip-menu-item {
  248. position: relative;
  249. &:hover {
  250. .unzip-list {
  251. display: block;
  252. }
  253. }
  254. .unzip-list {
  255. position: absolute;
  256. display: none;
  257. .unzip-item {
  258. width: 200px;
  259. .setEllipsis(1);
  260. }
  261. }
  262. }
  263. }
  264. .right-menu-list,
  265. .unzip-list {
  266. background: #fff;
  267. border: 1px solid @BorderLighter;
  268. border-radius: 4px;
  269. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  270. z-index: 2;
  271. padding: 4px 0;
  272. color: @RegularText;
  273. }
  274. }
  275. </style>