index.vue 16 KB

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