index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <template>
  2. <div class="container">
  3. <!-- 搜索标题 -->
  4. <div class="searchTitle">
  5. <el-icon @click="goBack">
  6. <ArrowLeftBold />
  7. </el-icon>
  8. <div class="colLine"></div>
  9. <div class="searchTitle_text">“{{ searchText }}”的搜索结果</div>
  10. </div>
  11. <!-- 搜索选项 -->
  12. <div class="searchType">
  13. <div class="searchFor">
  14. <div class="search_title">搜索范围:</div>
  15. <el-tabs v-model="searchFor" class="demo-tabs" @tab-change="changeSearchFor">
  16. <el-tab-pane label="公共" name="1"></el-tab-pane>
  17. <el-tab-pane label="部门" name="2"></el-tab-pane>
  18. <el-tab-pane label="个人" name="3"></el-tab-pane>
  19. </el-tabs>
  20. </div>
  21. <div class="line"></div>
  22. <div class="searchFor">
  23. <div class="search_title">分类:</div>
  24. <el-tabs v-model="searchType" class="demo-tabs" @tab-change="changeSearchType">
  25. <el-tab-pane label="全部" name="all"></el-tab-pane>
  26. <el-tab-pane label="文档" name="doc"></el-tab-pane>
  27. <el-tab-pane label="图片" name="img"></el-tab-pane>
  28. <el-tab-pane label="音频" name="audio"></el-tab-pane>
  29. <el-tab-pane label="视频" name="video"></el-tab-pane>
  30. <el-tab-pane label="压缩包" name="zip"></el-tab-pane>
  31. </el-tabs>
  32. </div>
  33. </div>
  34. <!-- 排序显示 -->
  35. <div class="statistics">
  36. <div class="left_box">
  37. <div class="dataNum">共查询到{{ total }}个相关结果</div>
  38. </div>
  39. <div class="right_box">
  40. <img src="@/assets/images/sort.png" @click="changeSort" v-if="isAsc == 'asc'" alt="" />
  41. <img src="@/assets/images/Frame_188.png" @click="changeSort" v-else alt="" />
  42. <img v-if="isList" src="@/assets/images/squre.png" alt="" @click="changeShow" />
  43. <img v-else src="@/assets/images/Frame_187.png" alt="" @click="changeShow" />
  44. </div>
  45. </div>
  46. <!-- 文件列表 -->
  47. <div class="fileList">
  48. <div>
  49. <div v-if="isList" style="height: calc(98vh - 420px);overflow-y: auto;">
  50. <!-- 表格 -->
  51. <el-table :data="tableData" style="width: 100%;height:calc(98vh - 620px) ;" ref="container"
  52. @scroll="handleScroll">
  53. <el-table-column fixed label="名称" width="500">
  54. <template #default="scope">
  55. <div class="flie_name">
  56. <img class="table_icon" :src="setIcon(scope.row.fileType)" alt="" style="" />
  57. {{ scope.row.fileName }}
  58. </div>
  59. </template>
  60. </el-table-column>
  61. <el-table-column prop="space.spaceName" label="所属空间" width="180" />
  62. <el-table-column prop="createTime" label="时间" width="auto" header-align="left" />
  63. <el-table-column prop="fileType" label="类型" width="auto" />
  64. <el-table-column prop="fileSize" label="大小" width="100">
  65. <template #default="scope">
  66. <div>{{ formatFileSize(scope.row.fileSize) }}</div>
  67. </template>
  68. </el-table-column>
  69. <el-table-column prop="dir.dirPath" label="文件夹" width="auto">
  70. <template #default="scope">
  71. <div class="folder">
  72. {{ scope.row.dir ? scope.row.dir.dirPath : "" }}
  73. </div>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <!-- <div class="pageBox">
  78. <Pagination :total="total" :page="page" :limit="limit" @pagination="pagination"></Pagination>
  79. </div> -->
  80. </div>
  81. <div v-else>
  82. <!-- 平铺 -->
  83. <div class="tile_box">
  84. <div class="file_box" v-for="item in tableData" :key="item">
  85. <img class="big_file_img" :src="setIcon(item.fileType)" alt="" />
  86. <span class="missing">{{ item.fileName }}</span>
  87. <span class="missingPass">{{ item.fileName }}</span>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. </template>
  95. <script setup>
  96. import { onMounted, ref, toRaw, inject, watch } from "vue";
  97. import { search } from "@/api/search/search.js";
  98. import { flieSearch } from "@/api/search/search.js";
  99. import { useRoute, useRouter, onBeforeRouteUpdate } from "vue-router";
  100. import Pagination from "@/components/Pagination/index.vue";
  101. import { ElTable, ElTableColumn, ElInfiniteScroll } from 'element-plus';
  102. //---------------导入图片--------------------------
  103. import file_DOC from "@/assets/images/fileType/file_DOC.png";
  104. import file_pdf from "@/assets/images/fileType/file_pdf.png";
  105. import file_PPT from "@/assets/images/fileType/file_PPT.png";
  106. import file_TXT from "@/assets/images/fileType/file_TXT.png";
  107. import file_XLSX from "@/assets/images/fileType/file_XLSX.png";
  108. import file_pic from "@/assets/images/fileType/file_pic.png";
  109. import file_audio from "@/assets/images/fileType/file_audio.png";
  110. import file_video from "@/assets/images/fileType/file_video.png";
  111. import file_zip from "@/assets/images/fileType/file_zip.png";
  112. //----------------------------------------
  113. const searchFor = ref("1"); //搜索范围
  114. const searchType = ref("doc"); //搜索对象
  115. const checkState = ref(false); //勾选框状态
  116. const activeNames = ref(["folder", "file"]);
  117. const isList = ref(true); //控制显示方式
  118. const isContent = ref(false); //内容搜索
  119. // const total = ref(0); //数据总条数
  120. const searchText = ref(""); //搜索ipt的值
  121. const baseData = ref(); //搜索出的原始数据
  122. const isAsc = ref("asc");
  123. const router = useRouter(); //注册路由
  124. const route = useRoute(); //注册路由
  125. //---------分页--------------
  126. const total = ref(0);
  127. const page = ref(1);
  128. const limit = ref(2); //pagesize
  129. //---------------------------
  130. const container = ref(null)
  131. const historyParams = history.state.params
  132. console.log('historyParams', historyParams);
  133. const reload = inject("reload");
  134. const tableData = ref([]);
  135. // 切换搜索范围
  136. const changeSearchFor = (name) => {
  137. // console.log('searchFor',searchFor.value);
  138. const typeArr = setType(searchType.value);
  139. let baseDataObj = toRaw(baseData.value);
  140. // console.log("tableData", tableData.tableData);
  141. tableData.value = toRaw(baseDataObj).filter(
  142. (item) => item.space.spaceType == name && typeArr.includes(item.fileType)
  143. );
  144. // console.log('tableData',tableData.value);
  145. };
  146. // 切换搜索分类
  147. const changeSearchType = (name) => {
  148. let baseDataObj = toRaw(baseData.value);
  149. if (name == 'all') {
  150. tableData.value = baseDataObj
  151. } else {
  152. // 获取分类具体数据
  153. console.log(name, 'name');
  154. const typeArr = setType(name);
  155. console.log(typeArr, '类型');
  156. tableData.value = toRaw(baseDataObj).filter((item) => {
  157. console.log(item,'遍历');
  158. return typeArr.includes(item.fileType) && item.space.spaceType === searchFor.value;
  159. });
  160. console.log(tableData.value,'数组');
  161. }
  162. };
  163. const changeShow = () => {
  164. isList.value = !isList.value;
  165. };
  166. const changeSort = async () => {
  167. isAsc.value == "asc" ? (isAsc.value = "desc") : (isAsc.value = "asc");
  168. const query = {
  169. keyword: searchText.value,
  170. isAsc: isAsc.value,
  171. orderByColumn: "createTime",
  172. };
  173. const res = await flieSearch(query);
  174. baseData.value = res.rows;
  175. tableData.value = res.rows;
  176. changeSearchFor(searchFor.value);
  177. // console.log("res", res);
  178. };
  179. // 根据选项对数据处理,返回处理后的数据
  180. const fliterListData = (dataList) => {
  181. return dataList;
  182. };
  183. // 回退
  184. const goBack = () => {
  185. router.back();
  186. };
  187. //分页
  188. const handleSizeChange = (val) => {
  189. limit.value = val;
  190. };
  191. const handleCurrentChange = (val) => {
  192. page.value = val;
  193. };
  194. const pagination = async (obj) => {
  195. console.log(obj, 'page');
  196. isAsc.value == "asc" ? (isAsc.value = "desc") : (isAsc.value = "asc");
  197. const query = {
  198. keyword: searchText.value,
  199. isAsc: isAsc.value,
  200. page: obj.page,
  201. size: obj.limit,
  202. orderByColumn: "createTime",
  203. };
  204. const res = await flieSearch(query);
  205. baseData.value = res.rows;
  206. tableData.value = res.rows;
  207. changeSearchFor(searchFor.value);
  208. };
  209. // 设置图标
  210. const setIcon = (fileType) => {
  211. switch (fileType) {
  212. case ".docx":
  213. return file_DOC;
  214. break;
  215. case ".pdf":
  216. return file_pdf;
  217. break;
  218. case ".ppt":
  219. return file_PPT;
  220. break;
  221. case ".txt":
  222. return file_TXT;
  223. break;
  224. case ".xlsx":
  225. return file_XLSX;
  226. break;
  227. case ".csv":
  228. return file_XLSX;
  229. break;
  230. case ".png":
  231. return file_pic;
  232. break;
  233. case ".mp3":
  234. return file_audio;
  235. break;
  236. case ".mp4":
  237. return file_video;
  238. break;
  239. case ".zip":
  240. return file_zip;
  241. break;
  242. default:
  243. return file_DOC;
  244. break;
  245. }
  246. };
  247. // TODO mp3筛选不出来 离大谱,一样的写法 mp4就可以
  248. // 设置分类
  249. const setType = (fileType) => {
  250. switch (fileType) {
  251. case "doc":
  252. return [".txt", ".ppt", ".pdf", ".docx", ".csv", ".wps", ".xls", '.pptxs', '.dll', '.pptx', '.doc'];
  253. break;
  254. case "img":
  255. return [".png", ".jpg", ".jpeg"];
  256. break;
  257. case "audio":
  258. return [".mp3"];
  259. break;
  260. case "video":
  261. return [".mp4", '.qlv'];
  262. break;
  263. case "zip":
  264. return [".zip", ".rar", ".7z"];
  265. break;
  266. default:
  267. return [""];
  268. break;
  269. }
  270. };
  271. function formatFileSize(fileSize) {
  272. if (fileSize >= 1024 * 1024 * 1024) {
  273. // 大于等于1GB,显示GB
  274. return (fileSize / (1024 * 1024 * 1024)).toFixed(2) + "GB";
  275. } else if (fileSize >= 1024 * 1024) {
  276. // 大于等于1MB,显示MB
  277. return (fileSize / (1024 * 1024)).toFixed(2) + "MB";
  278. } else if (fileSize >= 1024) {
  279. // 大于等于1KB,显示KB
  280. return (fileSize / 1024).toFixed(2) + "KB";
  281. } else {
  282. // 小于1KB,显示字节
  283. return fileSize + "B";
  284. }
  285. }
  286. let numnum = 1
  287. async function handleScroll(e) {
  288. // console.log(e, '出发了');
  289. const tableContainer = e.target;
  290. const scrollPosition = tableContainer.scrollTop + tableContainer.clientHeight;
  291. const contentHeight = tableContainer.scrollHeight;
  292. console.log(scrollPosition,contentHeight,'对比');
  293. if (scrollPosition + 0.40005 >= contentHeight) {
  294. numnum++
  295. const query = {
  296. keyword: searchText.value,
  297. isAsc: "asc",
  298. orderByColumn: "createTime",
  299. pageSize: 10,
  300. pageNum: numnum,
  301. };
  302. const res = await flieSearch(query);
  303. tableData.value = [...tableData.value,...res.rows]
  304. }
  305. }
  306. onMounted(() => {
  307. let antherContainer = container.value.$el.querySelector('.el-scrollbar__wrap')
  308. antherContainer.addEventListener('scroll', handleScroll);
  309. const JparData = history.state.clickRowId
  310. const parData = JSON.parse(JparData)
  311. searchText.value = parData.searchText;
  312. let searchData = parData.searchData;
  313. baseData.value = searchData.rows;
  314. tableData.value = searchData.rows;
  315. total.value = searchData.total;
  316. changeSearchFor(searchFor.value);
  317. });
  318. onBeforeRouteUpdate((to, from) => {
  319. console.log('to', to);
  320. console.log('from', from);
  321. })
  322. watch(() => history, (newValue, oldValue) => {
  323. console.log('history 发生改变了', newValue, oldValue);
  324. }, {
  325. immediate: true,
  326. deep: true
  327. });
  328. </script>
  329. <style lang="scss" scoped>
  330. .container {
  331. height: calc(98vh - 48px - 8px - 32px - 8px);
  332. background-color: #fff;
  333. border-radius: 4px;
  334. overflow: hidden;
  335. }
  336. .searchTitle {
  337. width: 100%;
  338. height: 40px;
  339. padding-left: 8px;
  340. display: flex;
  341. align-items: center;
  342. .colLine {
  343. margin-left: 5px;
  344. height: 100%;
  345. border-right: 1px solid #c1cce3;
  346. }
  347. .searchTitle_text {
  348. font-size: 16px;
  349. font-weight: 400;
  350. line-height: 24px;
  351. margin-left: 16px;
  352. }
  353. }
  354. .searchType {
  355. width: 100%;
  356. height: 40px;
  357. box-sizing: border-box;
  358. background-color: #f5f7f9;
  359. border-top: 1px solid #c1cce3;
  360. border-bottom: 1px solid #c1cce3;
  361. padding-left: 16px;
  362. display: flex;
  363. align-items: center;
  364. .searchFor {
  365. height: 100%;
  366. display: flex;
  367. // align-items: center;
  368. .search_title {
  369. height: 100%;
  370. line-height: 40px;
  371. font-size: 14px;
  372. font-weight: 500;
  373. font-family: Inter-Medium;
  374. }
  375. }
  376. .line {
  377. width: 1px;
  378. height: 24px;
  379. border-left: 1px solid #c1cce3;
  380. margin: 0 16px;
  381. }
  382. }
  383. .statistics {
  384. width: 100%;
  385. height: 40px;
  386. // background-color: #ccc;
  387. padding-left: 16px;
  388. display: flex;
  389. justify-content: space-between;
  390. align-items: center;
  391. .left_box {
  392. display: flex;
  393. align-items: center;
  394. .dataNum {
  395. margin-left: 4px;
  396. font-size: 14px;
  397. font-weight: 400;
  398. }
  399. }
  400. .right_box {
  401. width: 50px;
  402. display: flex;
  403. justify-content: space-between;
  404. margin-right: 30px;
  405. img {
  406. cursor: pointer;
  407. }
  408. }
  409. }
  410. .fileList {
  411. height: 100%;
  412. .content_box {
  413. width: 100%;
  414. height: 100%;
  415. padding: 16px;
  416. .oneBox {
  417. width: 100%;
  418. height: 120px;
  419. border-bottom: 1px dashed #c1cce3;
  420. .fileName {
  421. font-size: 16px;
  422. color: #2e6bc8;
  423. text-decoration: underline;
  424. font-family: Inter-SemiBold;
  425. }
  426. .flieTime {
  427. font-size: 12px;
  428. font-weight: 400;
  429. color: #06286c;
  430. line-height: 20px;
  431. }
  432. .flieContent {
  433. width: 100%;
  434. font-size: 14px;
  435. color: #000000;
  436. font-weight: 400;
  437. line-height: 22px;
  438. display: -webkit-box;
  439. -webkit-box-orient: vertical;
  440. text-overflow: ellipsis;
  441. -webkit-line-clamp: 3; //例如超过3行显示省略号
  442. overflow: hidden;
  443. em {
  444. color: #dd2025;
  445. }
  446. }
  447. }
  448. }
  449. }
  450. //表格文本超出隐藏
  451. ::v-deep .flie_name,
  452. .folder {
  453. /*第一步: 溢出隐藏 */
  454. overflow: hidden;
  455. /* 第二步:让文本不会换行, 在同一行继续 */
  456. white-space: nowrap;
  457. /* 第三步:用省略号来代表未显示完的文本 */
  458. text-overflow: ellipsis;
  459. }
  460. // tag间距
  461. ::v-deep .el-tabs__item {
  462. padding: 0 16px !important;
  463. color: #505870 !important;
  464. font-weight: 400 !important;
  465. }
  466. ::v-deep .el-tabs--top .el-tabs__item.is-top:nth-child(2) {
  467. padding-left: 0 !important;
  468. }
  469. ::v-deep .el-tabs--top .el-tabs__item.is-top:last-child {
  470. padding-right: 0 !important;
  471. }
  472. // tag选中颜色
  473. ::v-deep .el-tabs__item.is-active {
  474. color: #2e6bc8 !important;
  475. font-weight: normal;
  476. font-family: Inter-SemiBold;
  477. }
  478. ::v-deep .el-tabs__active-bar {
  479. background-color: #2e6bc8;
  480. }
  481. ::v-deep .el-table__inner-wrapper::before {
  482. background-color: #fff !important;
  483. }
  484. ::v-deep .el-collapse,
  485. .el-collapse-item__wrap {
  486. border: none;
  487. }
  488. .table_icon {
  489. height: 27px;
  490. width: 27px;
  491. vertical-align: middle;
  492. }
  493. ::v-deep .el-collapse-item__content {
  494. padding-bottom: 0;
  495. }
  496. ::v-deep .el-collapse-item__header {
  497. background-color: #ebeff6 !important;
  498. width: 100% !important;
  499. height: 24px !important;
  500. }
  501. ::v-deep .el-collapse-item__arrow {
  502. position: relative;
  503. color: #2e6bc8;
  504. right: 97%;
  505. }
  506. ::v-deep .el-table td.el-table__cell {
  507. border: none;
  508. font-size: 14px !important;
  509. font-weight: 400 !important;
  510. color: #000 !important;
  511. }
  512. ::v-deep .el-table__row {
  513. height: 35px !important;
  514. }
  515. ::v-deep .el-table .el-table__header-wrapper th {
  516. border-bottom: none;
  517. border-right: 1px solid #c1cce3;
  518. background-color: #fff !important;
  519. color: #505870;
  520. font-size: 14px;
  521. }
  522. .collapseItem_title {
  523. position: relative;
  524. left: 40px;
  525. color: #2e6bc8;
  526. font-family: Inter-Medium;
  527. font-size: 12px;
  528. }
  529. // 表格右边3个靠右对齐
  530. ::v-deep .el-table__header thead tr th {
  531. font-family: Inter-Medium;
  532. font-size: 14px;
  533. color: #505870;
  534. text-align: right;
  535. &:nth-child(1) {
  536. text-align: left;
  537. }
  538. }
  539. // ::v-deep .el-table__body tbody [class*="column_2"] {
  540. // text-align: right;
  541. // }
  542. // ::v-deep .el-table__body tbody [class*="column_3"] {
  543. // text-align: right;
  544. // }
  545. // ::v-deep .el-table__body tbody [class*="column_4"] {
  546. // text-align: right;
  547. // }
  548. // ::v-deep .el-table__body tbody [class*="column_6"] {
  549. // text-align: right;
  550. // }
  551. // ::v-deep .el-table__body tbody [class*="column_7"] {
  552. // text-align: right;
  553. // }
  554. ::v-deep .el-table__body tbody [class*="column_"] {
  555. text-align: right;
  556. &:nth-child(4n + 1) {
  557. text-align: left;
  558. }
  559. }
  560. //平铺
  561. .tile_box {
  562. width: 100%;
  563. height: 300px;
  564. display: flex;
  565. flex-wrap: wrap;
  566. .file_box {
  567. width: 116px;
  568. min-height: 138px;
  569. // border: 1px solid #000;
  570. display: flex;
  571. flex-direction: column;
  572. align-items: center;
  573. .big_file_img {
  574. width: 100px;
  575. height: 100px;
  576. }
  577. span {
  578. font-size: 14px;
  579. font-weight: 400;
  580. line-height: 22px;
  581. }
  582. }
  583. }
  584. .missing {
  585. width: 90px;
  586. white-space: nowrap;
  587. overflow: hidden;
  588. text-overflow: ellipsis
  589. }
  590. .missing:hover~.missingPass {
  591. display: block;
  592. }
  593. .missingPass {
  594. display: none;
  595. width: 140px;
  596. background-color: black;
  597. border-radius: 5px;
  598. color: white;
  599. text-align: center;
  600. z-index: 30 important;
  601. margin-left: 25px;
  602. font-size: 14px;
  603. }
  604. </style>