FileTable.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div class="file-table-wrapper">
  3. <!-- 文件表格 -->
  4. <a-table
  5. class="file-table"
  6. :class="['file-type-' + fileType, routeName === 'Share' ? 'share' : '']"
  7. ref="multipleTableRef"
  8. :loading="loading"
  9. :data-source="fileList"
  10. :columns="columns"
  11. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  12. :pagination="false"
  13. :custom-row="customRow"
  14. @change="handleTableChange"
  15. >
  16. <template #bodyCell="{ column, record, index }">
  17. <template v-if="column.key === 'isDir'">
  18. <video
  19. style="width: 30px; max-height: 30px; cursor: pointer"
  20. v-if="$file.isVideoFile(record)"
  21. :src="$file.setFileImg(record)"
  22. ></video>
  23. <img
  24. :src="$file.setFileImg(record)"
  25. :title="`${record.isDir || fileType == '6' ? '' : '点击预览'}`"
  26. style="width: 30px; max-height: 30px; cursor: pointer"
  27. @click="$file.handleFileNameClick(record, index, sortedFileList)"
  28. v-else
  29. />
  30. </template>
  31. <template v-else-if="column.key === 'fileName'">
  32. <span @click="$file.handleFileNameClick(record, index, sortedFileList)">
  33. <span
  34. class="file-name"
  35. style="cursor: pointer"
  36. :title="`${record.isDir || fileType == '6' ? '' : '点击预览'}`"
  37. v-html="$file.getFileNameComplete(record, true)"
  38. ></span>
  39. <div class="file-info" v-if="screenWidth <= 768">
  40. {{ record.uploadTime }}
  41. <span class="file-size">
  42. {{ record.isDir === 0 ? $file.calculateFileSize(record.fileSize) : '' }}
  43. </span>
  44. </div>
  45. </span>
  46. </template>
  47. <template v-else-if="column.key === 'filePath'">
  48. <span
  49. style="cursor: pointer"
  50. title="点击跳转"
  51. @click="
  52. router.push({
  53. query: { filePath: record.filePath, fileType: 0 }
  54. })
  55. "
  56. >{{ record.filePath }}</span
  57. >
  58. </template>
  59. <template v-else-if="column.key === 'extendName'">
  60. <span>{{ $file.getFileType(record) }}</span>
  61. </template>
  62. <template v-else-if="column.key === 'fileSize'">
  63. {{ record.isDir === 0 ? $file.calculateFileSize(record.fileSize) : '' }}
  64. </template>
  65. <template v-else-if="column.key === 'shareType'">
  66. {{ record.shareType === 1 ? '私密' : '公共' }}
  67. </template>
  68. <template v-else-if="column.key === 'endTime'">
  69. <div>
  70. <WarningOutlined v-if="$file.getFileShareStatus(record.endTime)" />
  71. <ClockCircleOutlined v-else />
  72. {{ record.endTime }}
  73. </div>
  74. </template>
  75. <template v-else-if="column.key === 'operation'">
  76. <MoreOutlined
  77. class="file-operate"
  78. :class="`operate-more-${index}`"
  79. @click="handleClickMore(record, $event)"
  80. />
  81. </template>
  82. </template>
  83. </a-table>
  84. </div>
  85. </template>
  86. <script setup>
  87. import { ref, computed, watch, onMounted } from 'vue'
  88. import { useRoute, useRouter } from 'vue-router'
  89. import { storeToRefs } from 'pinia'
  90. import { useMyResourceStore } from '@/store/myResource'
  91. import {
  92. WarningOutlined,
  93. ClockCircleOutlined,
  94. MoreOutlined,
  95. PlusCircleOutlined,
  96. MinusCircleOutlined
  97. } from '@ant-design/icons-vue'
  98. const props = defineProps({
  99. // 文件类型
  100. fileType: {
  101. required: true,
  102. type: Number
  103. },
  104. // 文件路径
  105. filePath: {
  106. required: true,
  107. type: String
  108. },
  109. // 文件列表
  110. fileList: {
  111. required: true,
  112. type: Array
  113. },
  114. // 文件加载状态
  115. loading: {
  116. required: true,
  117. type: Boolean
  118. }
  119. })
  120. console.log('fileList-----: ', props)
  121. const emit = defineEmits(['getTableDataByType'])
  122. const route = useRoute()
  123. const router = useRouter()
  124. const myResourceStore = useMyResourceStore()
  125. const { proxy } = getCurrentInstance()
  126. const multipleTableRef = ref(null)
  127. const officeFileType = ref(['ppt', 'pptx', 'doc', 'docx', 'xls', 'xlsx'])
  128. const sortedFileList = ref([]) // 排序后的表格数据
  129. const selectedRowKeys = ref([])
  130. console.log('1111111111', route.query)
  131. console.log('props.fileType', props.fileType)
  132. const { getSelectedColumnList } = storeToRefs(myResourceStore)
  133. console.log('getSelectedColumnList:---- ', getSelectedColumnList.value)
  134. const selectedColumnList = computed({
  135. get: () => getSelectedColumnList.value
  136. })
  137. // 路由名称
  138. const routeName = computed(() => route.name)
  139. // 屏幕宽度
  140. const screenWidth = computed(() => myResourceStore.screenWidth)
  141. // 定义表格列
  142. const columns = computed(() => {
  143. const cols = [
  144. {
  145. dataIndex: 'isDir',
  146. key: 'isDir',
  147. width: screenWidth.value <= 768 ? 40 : 56,
  148. align: 'center',
  149. className: 'file-icon-column'
  150. },
  151. {
  152. title: '文件名',
  153. dataIndex: 'fileName',
  154. key: 'fileName',
  155. sorter: (a, b) => {
  156. if (a.isDir !== b.isDir) return b.isDir - a.isDir
  157. return a.fileName.localeCompare(b.fileName)
  158. },
  159. showOverflowTooltip: true
  160. }
  161. ]
  162. if (![0, 8].includes(Number(route.query.fileType)) && routeName.value !== 'Share' && screenWidth.value > 768) {
  163. cols.push({
  164. title: props.fileType === 6 ? '原路径' : '路径',
  165. dataIndex: 'filePath',
  166. key: 'filePath',
  167. showOverflowTooltip: true
  168. })
  169. }
  170. if (selectedColumnList.value.includes('extendName') && screenWidth.value > 768) {
  171. cols.push({
  172. title: '类型',
  173. dataIndex: 'extendName',
  174. key: 'extendName',
  175. width: 80,
  176. sorter: (a, b) => {
  177. if (a.isDir !== b.isDir) return b.isDir - a.isDir
  178. return a.extendName.localeCompare(b.extendName)
  179. },
  180. showOverflowTooltip: true
  181. })
  182. }
  183. if (selectedColumnList.value.includes('fileSize') && screenWidth.value > 768) {
  184. cols.push({
  185. title: '大小',
  186. dataIndex: 'fileSize',
  187. key: 'fileSize',
  188. width: 100,
  189. align: 'right',
  190. sorter: (a, b) => {
  191. if (a.isDir !== b.isDir) return b.isDir - a.isDir
  192. return a.fileSize - b.fileSize
  193. }
  194. })
  195. }
  196. if (
  197. selectedColumnList.value.includes('uploadTime') &&
  198. ![7, 8].includes(props.fileType) &&
  199. !['Share'].includes(routeName.value) &&
  200. screenWidth.value > 768
  201. ) {
  202. cols.push({
  203. title: '修改日期',
  204. dataIndex: 'uploadTime',
  205. key: 'uploadTime',
  206. width: 160,
  207. align: 'center',
  208. sorter: (a, b) => {
  209. if (a.isDir !== b.isDir) return b.isDir - a.isDir
  210. return new Date(a.uploadTime).getTime() - new Date(b.uploadTime).getTime()
  211. }
  212. })
  213. }
  214. if (props.fileType === 6 && selectedColumnList.value.includes('deleteTime') && screenWidth.value > 768) {
  215. cols.push({
  216. title: '删除日期',
  217. dataIndex: 'deleteTime',
  218. key: 'deleteTime',
  219. width: 160,
  220. align: 'center',
  221. sorter: (a, b) => {
  222. if (a.isDir !== b.isDir) return b.isDir - a.isDir
  223. return new Date(a.deleteTime).getTime() - new Date(b.deleteTime).getTime()
  224. }
  225. })
  226. }
  227. if (props.fileType === 8 && screenWidth.value > 768) {
  228. cols.push({
  229. title: '分享类型',
  230. dataIndex: 'shareType',
  231. key: 'shareType',
  232. width: 100,
  233. align: 'center'
  234. })
  235. cols.push({
  236. title: '分享时间',
  237. dataIndex: 'shareTime',
  238. key: 'shareTime',
  239. width: 160,
  240. showOverflowTooltip: true,
  241. align: 'center',
  242. sorter: (a, b) => {
  243. if (a.isDir !== b.isDir) return b.isDir - a.isDir
  244. return new Date(a.shareTime).getTime() - new Date(b.shareTime).getTime()
  245. }
  246. })
  247. cols.push({
  248. title: '过期时间',
  249. dataIndex: 'endTime',
  250. key: 'endTime',
  251. width: 190,
  252. showOverflowTooltip: true,
  253. align: 'center',
  254. sorter: (a, b) => {
  255. if (a.isDir !== b.isDir) return b.isDir - a.isDir
  256. return new Date(a.endTime).getTime() - new Date(b.endTime).getTime()
  257. }
  258. })
  259. }
  260. if (screenWidth.value <= 768) {
  261. cols.push({
  262. title: '',
  263. dataIndex: 'operation',
  264. key: 'operation',
  265. width: 48
  266. })
  267. }
  268. return cols
  269. })
  270. watch(
  271. () => props.filePath,
  272. () => {
  273. clearSelectedTable()
  274. // Ant Design Vue Table 没有 clearSort 方法,需要手动处理排序状态
  275. // multipleTableRef.value.clearSort();
  276. }
  277. )
  278. watch(
  279. () => props.fileType,
  280. () => {
  281. clearSelectedTable()
  282. // multipleTableRef.value.clearSort();
  283. }
  284. )
  285. watch(
  286. () => props.fileList,
  287. () => {
  288. clearSelectedTable()
  289. // multipleTableRef.value.clearSort();
  290. sortedFileList.value = props.fileList
  291. }
  292. )
  293. // 当表格的排序条件发生变化的时候会触发该事件
  294. const handleTableChange = (pagination, filters, sorter) => {
  295. // Ant Design Vue 的 sorter 返回的是当前排序的列信息,需要根据实际情况更新 sortedFileList
  296. // 这里简化处理,如果需要前端排序,可以根据 sorter.field 和 sorter.order 对 fileList 进行排序
  297. // sortedFileList.value = multipleTableRef.value.tableData;
  298. }
  299. // 表格某一行右键事件
  300. const customRow = (record, index) => {
  301. return {
  302. onContextmenu: (event) => {
  303. // 阻止右键事件冒泡
  304. event.cancelBubble = true
  305. // xs 以上的屏幕
  306. if (screenWidth.value > 768) {
  307. event.preventDefault()
  308. // Ant Design Vue Table 没有 setCurrentRow 方法,需要手动处理选中状态
  309. // multipleTableRef.value.setCurrentRow(record);
  310. proxy.$openBox
  311. .contextMenu({
  312. selectedFile: record,
  313. domEvent: event,
  314. serviceEl: proxy
  315. })
  316. .then((res) => {
  317. // multipleTableRef.value.setCurrentRow(); // 取消当前选中行
  318. if (res === 'confirm') {
  319. emit('getTableDataByType') // 刷新文件列表
  320. myResourceStore.showStorage() // 刷新存储容量
  321. }
  322. })
  323. }
  324. }
  325. }
  326. }
  327. // 清空表格已选行
  328. const clearSelectedTable = () => {
  329. selectedRowKeys.value = []
  330. myResourceStore.changeSelectedFiles([])
  331. myResourceStore.changeIsBatchOperation(false)
  332. }
  333. // 表格选择项发生变化时的回调函数
  334. const onSelectChange = (selectedKeys, selectedRows) => {
  335. selectedRowKeys.value = selectedKeys
  336. myResourceStore.changeSelectedFiles(selectedRows)
  337. myResourceStore.changeIsBatchOperation(selectedRows.length !== 0)
  338. }
  339. // 更多图标点击事件
  340. const handleClickMore = (record, event) => {
  341. // multipleTableRef.value.setCurrentRow(record); // 选中当前行
  342. proxy.$openBox
  343. .contextMenu({
  344. selectedFile: record,
  345. domEvent: event
  346. })
  347. .then((res) => {
  348. // multipleTableRef.value.setCurrentRow(); // 取消当前选中行
  349. if (res === 'confirm') {
  350. emit('getTableDataByType') // 刷新文件列表
  351. myResourceStore.showStorage() // 刷新存储容量
  352. }
  353. })
  354. }
  355. </script>
  356. <style lang="less" scoped>
  357. @import '@/style/myResource/varibles.less';
  358. @import '@/style/myResource/mixins.less';
  359. .file-table-wrapper {
  360. margin-top: 2px;
  361. .file-type-0 {
  362. height: calc(100vh - 206px) !important;
  363. :deep(.ant-table-body) {
  364. height: calc(100vh - 262px) !important;
  365. }
  366. }
  367. .file-type-6 {
  368. height: calc(100vh - 211px) !important;
  369. :deep(.ant-table-body) {
  370. height: calc(100vh - 263px) !important;
  371. }
  372. }
  373. .file-table.share {
  374. height: calc(100vh - 109px) !important;
  375. :deep(.ant-table-body) {
  376. height: calc(100vh - 161px) !important;
  377. }
  378. }
  379. .file-table {
  380. width: 100% !important;
  381. height: calc(100vh - 203px);
  382. :deep(.ant-table-thead) {
  383. th {
  384. // background: @tabBackColor; // 需要在 varibles.less 中定义
  385. padding: 4px 0;
  386. color: @RegularText; // 需要在 varibles.less 中定义
  387. }
  388. .anticon-plus-circle,
  389. .anticon-minus-circle {
  390. margin-left: 6px;
  391. cursor: pointer;
  392. font-size: 16px;
  393. &:hover {
  394. color: @Primary; // 需要在 varibles.less 中定义
  395. }
  396. }
  397. }
  398. :deep(.ant-table-body) {
  399. height: calc(100vh - 255px);
  400. overflow-y: auto;
  401. // setScrollbar(6px, transparent, #C0C4CC); // 需要在 mixins.less 中定义
  402. td {
  403. padding: 8px 0;
  404. .file-name {
  405. .keyword {
  406. color: @Danger; // 需要在 varibles.less 中定义
  407. }
  408. }
  409. }
  410. .anticon-warning {
  411. font-size: 16px;
  412. color: @Warning; // 需要在 varibles.less 中定义
  413. }
  414. .anticon-clock-circle {
  415. font-size: 16px;
  416. color: @Success; // 需要在 varibles.less 中定义
  417. }
  418. }
  419. }
  420. }
  421. .right-menu-list {
  422. position: fixed;
  423. display: flex;
  424. flex-direction: column;
  425. background: #fff;
  426. border: 1px solid @BorderLighter; // 需要在 varibles.less 中定义
  427. border-radius: 4px;
  428. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  429. z-index: 2;
  430. padding: 4px 0;
  431. color: @RegularText; // 需要在 varibles.less 中定义
  432. .right-menu-item,
  433. .unzip-item {
  434. padding: 0 16px;
  435. height: 36px;
  436. line-height: 36px;
  437. cursor: pointer;
  438. &:hover {
  439. background: @PrimaryHover; // 需要在 varibles.less 中定义
  440. color: @Primary; // 需要在 varibles.less 中定义
  441. }
  442. i {
  443. margin-right: 8px;
  444. }
  445. }
  446. .unzip-menu-item {
  447. position: relative;
  448. &:hover {
  449. .unzip-list {
  450. display: block;
  451. }
  452. }
  453. .unzip-list {
  454. position: absolute;
  455. display: none;
  456. .unzip-item {
  457. width: 200px;
  458. // setEllipsis(1); // 需要在 mixins.less 中定义
  459. }
  460. }
  461. }
  462. }
  463. .right-menu-list,
  464. .unzip-list {
  465. background: #fff;
  466. border: 1px solid @BorderLighter; // 需要在 varibles.less 中定义
  467. border-radius: 4px;
  468. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  469. z-index: 2;
  470. padding: 4px 0;
  471. color: @RegularText; // 需要在 varibles.less 中定义
  472. }
  473. </style>