EnterpriseDisk.vue 6.2 KB

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