index.vue 15 KB

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