FileList.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <div class="file-list-wrapper">
  3. <!-- 操作按钮 -->
  4. <div class="header">
  5. <OperationMenu
  6. :fileType="fileType"
  7. :filePath="filePath"
  8. @getSearchFileList="getSearchFileList"
  9. @getTableDataByType="getTableDataByType"
  10. ></OperationMenu>
  11. </div>
  12. <div class="middle-wrapper">
  13. <!-- 面包屑导航栏 -->
  14. <BreadCrumb
  15. class="breadcrumb"
  16. :fileType="fileType"
  17. :filePath="filePath"
  18. @getTableDataByType="getTableDataByType"
  19. ></BreadCrumb>
  20. </div>
  21. <!-- 文件列表-表格模式 -->
  22. <FileTable
  23. :fileType="fileType"
  24. :filePath="filePath"
  25. :fileList="fileList"
  26. :loading="loading"
  27. v-if="fileModel === 0"
  28. @getTableDataByType="getTableDataByType"
  29. @contextmenu="handleClickRight"
  30. ></FileTable>
  31. <!-- 文件列表-网格模式 -->
  32. <FileGrid
  33. :fileType="fileType"
  34. :filePath="filePath"
  35. :fileList="fileList"
  36. :loading="loading"
  37. v-if="fileModel === 1"
  38. @getTableDataByType="getTableDataByType"
  39. @contextmenu="handleClickRight"
  40. ></FileGrid>
  41. <!-- 图片-时间线模式 -->
  42. <FileTimeLine
  43. class="image-model"
  44. :fileList="fileList"
  45. :loading="loading"
  46. v-if="fileModel === 2 && fileType === 1"
  47. @getTableDataByType="getTableDataByType"
  48. @contextmenu="handleClickRight"
  49. ></FileTimeLine>
  50. <div class="pagination-wrapper">
  51. <div class="current-page-count">当前页{{ fileList.length }}条</div>
  52. <!-- 回收站不展示分页组件 -->
  53. <a-pagination
  54. v-model:current="pageData.currentPage"
  55. v-model:pageSize="pageData.pageCount"
  56. :total="pageData.total"
  57. :pageSizeOptions="[10, 50, 100, 200]"
  58. showSizeChanger
  59. :showTotal="(total) => `共 ${total} 条`"
  60. showQuickJumper
  61. v-if="fileType !== 6"
  62. @change="handleCurrentChange"
  63. @showSizeChange="handleSizeChange"
  64. >
  65. </a-pagination>
  66. </div>
  67. </div>
  68. </template>
  69. <script setup>
  70. import { ref, computed, watch, onMounted } from 'vue'
  71. import { useRouter, useRoute } from 'vue-router'
  72. import { message } from 'ant-design-vue'
  73. import OperationMenu from '@/views/myResource/components/OperationMenu.vue'
  74. import BreadCrumb from '@/views/myResource/common/BreadCrumb.vue'
  75. import FileTable from '@/views/myResource/common/FileTable.vue'
  76. import FileGrid from '@/views/myResource/components/FileGrid.vue'
  77. import FileTimeLine from '@/views/myResource/components/FileTimeLine.vue'
  78. import { useMyResourceStore } from '@/store/myResource'
  79. import {
  80. getFileListByPath,
  81. getFileListByType,
  82. getRecoveryFile,
  83. getMyShareFileList,
  84. searchFile
  85. } from '@/api/myResource/file'
  86. const { proxy } = getCurrentInstance()
  87. const route = useRoute()
  88. const router = useRouter()
  89. const myResourceStore = useMyResourceStore()
  90. const fileNameSearch = ref('')
  91. const loading = ref(true) // 表格数据-loading
  92. const fileList = ref([]) // 表格数据-文件列表
  93. // 分页数据
  94. const pageData = ref({
  95. currentPage: 1,
  96. pageCount: 50,
  97. total: 0
  98. })
  99. // 左侧菜单选中的文件类型
  100. // const fileType = computed(() => {
  101. // return route.query.fileType ? Number(route.query.fileType) : 0
  102. // })
  103. const fileType = ref(0)
  104. // 当前所在路径
  105. const filePath = computed(() => {
  106. return route.query.filePath ? route.query.filePath : '/'
  107. })
  108. // 文件查看模式 0列表模式 1网格模式 2 时间线模式
  109. const fileModel = computed(() => {
  110. return myResourceStore.getFileModel
  111. })
  112. // 屏幕宽度
  113. const screenWidth = computed(() => {
  114. return myResourceStore.screenWidth
  115. })
  116. const navigateTo = (path) => {
  117. // fileList.value.navigateTo(path)
  118. console.log('navigateTo 变化', path)
  119. // {
  120. // "name": "resourceLibrary",
  121. // "query": {
  122. // "fileType": 2
  123. // }
  124. if (path.name && path.name == 'resourceLibrary') {
  125. // if (path.query.fileType == 0) {
  126. // }
  127. fileType.value = path.query.fileType
  128. setPageCount()
  129. getTableDataByType()
  130. }
  131. }
  132. // 监听路径变化
  133. // watch(
  134. // () => filePath.value,
  135. // () => {
  136. // // 当左侧菜单选择"全部"或"我的分享",文件路径发生变化时,再重新获取文件列表
  137. // if (route.name === 'resourceLibrary' && [0, 8].includes(fileType.value)) {
  138. // setPageCount()
  139. // getTableDataByType()
  140. // }
  141. // }
  142. // )
  143. // 监听文件类型变化
  144. // watch(
  145. // () => fileType.value,
  146. // () => {
  147. // if (route.name === 'resourceLibrary') {
  148. // setPageCount()
  149. // getTableDataByType()
  150. // }
  151. // }
  152. // )
  153. // 监听文件查看模式
  154. watch(
  155. () => fileModel.value,
  156. () => {
  157. setPageCount()
  158. }
  159. )
  160. onMounted(() => {
  161. setPageCount()
  162. getTableDataByType()
  163. })
  164. /**
  165. * 文件展示区域的空白处右键事件
  166. * @param {Document} event 右键事件对象
  167. */
  168. const handleClickRight = (event) => {
  169. event.preventDefault()
  170. console.log('proxy', proxy)
  171. // 只有在全部页面才可以进行以下操作
  172. if (![6, 8].includes(fileType.value)) {
  173. proxy.$openBox
  174. .contextMenu({
  175. selectedFile: undefined,
  176. domEvent: event,
  177. serviceEl: proxy
  178. })
  179. .then((res) => {
  180. if (res === 'confirm') {
  181. getTableDataByType() // 刷新文件列表
  182. myResourceStore.showStorage() // 刷新存储容量
  183. }
  184. })
  185. }
  186. }
  187. /**
  188. * 表格数据获取相关事件 | 调整分页大小
  189. */
  190. const setPageCount = () => {
  191. pageData.value.currentPage = 1
  192. if (fileModel.value === 0) {
  193. pageData.value.pageCount = 50
  194. }
  195. if (fileModel.value === 1) {
  196. pageData.value.pageCount = 100
  197. }
  198. }
  199. /**
  200. * 表格数据获取相关事件 | 获取文件列表数据
  201. */
  202. const getTableDataByType = () => {
  203. loading.value = true
  204. // 分类型
  205. if (Number(fileType.value)) {
  206. switch (Number(fileType.value)) {
  207. case 6: {
  208. showFileRecovery() // 回收站
  209. break
  210. }
  211. case 8: {
  212. showMyShareFile() // 我的分享
  213. break
  214. }
  215. default: {
  216. showFileList()
  217. break
  218. }
  219. }
  220. } else {
  221. // 全部文件
  222. showFileList()
  223. }
  224. myResourceStore.showStorage()
  225. }
  226. /**
  227. * 表格数据获取相关事件 | 获取当前路径下的文件列表
  228. */
  229. const showFileList = () => {
  230. let data = {
  231. fileType: fileType.value,
  232. filePath: filePath.value,
  233. currentPage: pageData.value.currentPage,
  234. pageCount: pageData.value.pageCount
  235. }
  236. getFileListByPath(data).then((res) => {
  237. if (res.success) {
  238. console.log('获取到的数据呢', res.dataList)
  239. for (let i = 0; i < res.dataList.length; i++) {
  240. res.dataList[i].key = i
  241. }
  242. fileList.value = res.dataList
  243. pageData.value.total = Number(res.total)
  244. loading.value = false
  245. } else {
  246. message.error(res.message)
  247. }
  248. })
  249. }
  250. /**
  251. * 表格数据获取相关事件 | 分页组件 | 当前页码改变
  252. */
  253. const handleCurrentChange = (currentPage) => {
  254. pageData.value.currentPage = currentPage
  255. getTableDataByType()
  256. }
  257. /**
  258. * 表格数据获取相关事件 | 分页组件 | 页大小改变时
  259. */
  260. const handleSizeChange = (pageSize) => {
  261. pageData.value.pageCount = pageSize
  262. getTableDataByType()
  263. }
  264. /**
  265. * 表格数据获取相关事件 | 获取回收站文件列表
  266. */
  267. const showFileRecovery = () => {
  268. getRecoveryFile().then((res) => {
  269. if (res.success) {
  270. fileList.value = res.dataList
  271. loading.value = false
  272. } else {
  273. message.error(res.message)
  274. }
  275. })
  276. }
  277. /**
  278. * 表格数据获取相关事件 | 获取我的分享列表
  279. */
  280. const showMyShareFile = () => {
  281. let data = {
  282. shareFilePath: filePath.value,
  283. shareBatchNum: route.query.shareBatchNum,
  284. currentPage: pageData.value.currentPage,
  285. pageCount: pageData.value.pageCount
  286. }
  287. getMyShareFileList(data).then((res) => {
  288. if (res.success) {
  289. fileList.value = res.dataList
  290. pageData.value.total = Number(res.total)
  291. loading.value = false
  292. } else {
  293. message.error(res.message)
  294. }
  295. })
  296. }
  297. /**
  298. * 表格数据获取相关事件 | 根据文件类型展示文件列表
  299. */
  300. const showFileListByType = () => {
  301. // 分类型
  302. let data = {
  303. fileType: fileType.value,
  304. currentPage: pageData.value.currentPage,
  305. pageCount: pageData.value.pageCount
  306. }
  307. getFileListByType(data).then((res) => {
  308. if (res.success) {
  309. fileList.value = res.dataList
  310. pageData.value.total = Number(res.total)
  311. loading.value = false
  312. } else {
  313. message.error(res.message)
  314. }
  315. })
  316. }
  317. /**
  318. * 获取搜索文件结果列表
  319. * @param {string} fileName 文件名称
  320. */
  321. const getSearchFileList = (fileName) => {
  322. loading.value = true
  323. searchFile({
  324. currentPage: pageData.value.currentPage,
  325. pageCount: pageData.value.pageCount,
  326. fileName: fileName
  327. }).then((res) => {
  328. loading.value = false
  329. if (res.success) {
  330. fileList.value = res.dataList.map((item) => {
  331. return {
  332. ...item,
  333. highlightFields: item.highLight.fileName[0]
  334. }
  335. })
  336. pageData.value.total = res.data.totalHits
  337. } else {
  338. message.error(res.message)
  339. }
  340. })
  341. }
  342. defineExpose({ navigateTo })
  343. </script>
  344. <style lang="less" scoped>
  345. @import '@/style/myResource/varibles.less';
  346. .file-list-wrapper {
  347. .header {
  348. padding: 0;
  349. }
  350. .middle-wrapper {
  351. margin-bottom: 8px;
  352. }
  353. .pagination-wrapper {
  354. position: relative;
  355. border-top: 1px solid @BorderBase;
  356. height: 44px;
  357. line-height: 44px;
  358. text-align: center;
  359. .current-page-count {
  360. position: absolute;
  361. left: 16px;
  362. height: 32px;
  363. line-height: 32px;
  364. font-size: 13px;
  365. color: @RegularText;
  366. }
  367. }
  368. }
  369. </style>