index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <template>
  2. <div class="container">
  3. <!-- 标签 -->
  4. <div class="tags">
  5. <!-- TODO 标签可以拖动位置 -->
  6. <!--
  7. <el-tabs v-if="false" v-model="clickCollect" class="demo-tabs tabSign">
  8. <el-tab-pane label="常用" name="first"></el-tab-pane>
  9. <el-tab-pane label="默认" name="second"></el-tab-pane>
  10. <draggable
  11. :list="toRaw(tabList)"
  12. ghost-class="ghost"
  13. chosen-class="chosenClass"
  14. animation="300"
  15. >
  16. <template #item="{ element }">
  17. <el-tab-pane>
  18. <template #label>
  19. <div
  20. v-if="isChangeTabName !== element.labelId"
  21. @click.right="tabClick($event, element)"
  22. >
  23. {{ element.labelName }}
  24. </div>
  25. <div v-else>
  26. <el-input
  27. v-model="changeTabName"
  28. size="mini"
  29. @blur="reTabName"
  30. maxlength="32"
  31. :autofocus="true"
  32. ></el-input>
  33. </div>
  34. </template>
  35. </el-tab-pane>
  36. </template>
  37. </draggable>
  38. </el-tabs> -->
  39. <el-tabs
  40. v-model="clickCollect"
  41. class="tabSign"
  42. @tab-change="tabchange"
  43. ref="tabs"
  44. >
  45. <el-tab-pane label="常用" name="first"></el-tab-pane>
  46. <el-tab-pane label="默认" name="second"></el-tab-pane>
  47. <el-tab-pane
  48. v-for="item in toRaw(tabList)"
  49. :key="item"
  50. :name="item.labelId"
  51. >
  52. <template #label>
  53. <div
  54. v-if="isChangeTabName !== item.labelId"
  55. @click.right="tabClick($event, item)"
  56. >
  57. {{ item.labelName }}
  58. </div>
  59. <div v-else>
  60. <el-input
  61. v-model="changeTabName"
  62. size="mini"
  63. @blur="reTabName"
  64. maxlength="32"
  65. :autofocus="true"
  66. ></el-input>
  67. </div>
  68. </template>
  69. </el-tab-pane>
  70. </el-tabs>
  71. <!-- 添加标签 -->
  72. <div class="addCollect">
  73. <div v-if="!isAddCollect">
  74. <el-icon color="#2E6BC8">
  75. <Plus />
  76. </el-icon>
  77. <span @click="toAddCollectFn">添加标签</span>
  78. </div>
  79. <div v-else>
  80. <el-input
  81. v-model="tabName"
  82. size="mini"
  83. @change="addCollectFn"
  84. maxlength="32"
  85. :autofocus="true"
  86. ></el-input>
  87. </div>
  88. </div>
  89. </div>
  90. <el-collapse v-model="activeNames">
  91. <div v-if="isList">
  92. <el-collapse-item name="folder">
  93. <template #title>
  94. <span class="collapseItem_title">文件夹</span>
  95. </template>
  96. <!-- 表格 -->
  97. <el-table
  98. :data="folderArr"
  99. style="width: 100%"
  100. height="250"
  101. :scrollbar-always-on="true"
  102. >
  103. <el-table-column fixed prop="date" label="名称" width="500">
  104. <template #default="scope">
  105. <div>
  106. <img
  107. class="table_icon"
  108. src="@/assets/images/fileBox.png"
  109. alt=""
  110. style=""
  111. />
  112. {{ scope.row.docDir.dirName }}
  113. </div>
  114. </template>
  115. </el-table-column>
  116. <el-table-column
  117. prop="docDir.createTime"
  118. label="时间"
  119. width="200"
  120. />
  121. <el-table-column prop="docInfo.fileType" label="类型" width="180">
  122. <!-- <template #default="scope"> -->
  123. <div>文件夹</div>
  124. <!-- </template> -->
  125. </el-table-column>
  126. </el-table>
  127. </el-collapse-item>
  128. <el-collapse-item name="file">
  129. <template #title>
  130. <span class="collapseItem_title">文件</span>
  131. </template>
  132. <!-- 表格 -->
  133. <el-table
  134. :data="fileArr"
  135. style="width: 100%"
  136. height="250"
  137. :scrollbar-always-on="true"
  138. >
  139. <el-table-column fixed prop="date" label="名称" width="500">
  140. <template #default="scope">
  141. <div>
  142. <img
  143. class="table_icon"
  144. :src="setIcon(scope.row.docInfo.fileType)"
  145. alt=""
  146. style=""
  147. />
  148. {{ scope.row.docInfo.fileName }}
  149. </div>
  150. </template>
  151. </el-table-column>
  152. <el-table-column prop="createTime" label="时间" width="200" />
  153. <el-table-column prop="docInfo.fileType" label="类型" width="180" />
  154. <el-table-column prop="docInfo.fileSize" label="大小" width="160">
  155. <template #default="scope">
  156. <div>{{ scope.row.docInfo.fileSize }} KB</div>
  157. </template>
  158. </el-table-column>
  159. </el-table>
  160. </el-collapse-item>
  161. </div>
  162. <div v-else>
  163. <el-collapse-item name="folder">
  164. <template #title>
  165. <span class="collapseItem_title">文件夹</span>
  166. </template>
  167. <!-- 平铺 -->
  168. <el-scrollbar height="360px">
  169. <div class="tile_box">
  170. <div class="file_box" v-for="item in folderArr" :key="item">
  171. <img
  172. class="big_file_img"
  173. src="@/assets/images/fileBox.png"
  174. alt=""
  175. />
  176. <span>{{ item.docDir.dirName }}</span>
  177. </div>
  178. </div>
  179. </el-scrollbar>
  180. </el-collapse-item>
  181. <el-collapse-item name="file">
  182. <template #title>
  183. <span class="collapseItem_title">文件</span>
  184. </template>
  185. <!-- 平铺 -->
  186. <el-scrollbar height="360px">
  187. <div class="tile_box">
  188. <div class="file_box" v-for="item in fileArr" :key="item">
  189. <img
  190. class="big_file_img"
  191. :src="setIcon(item.docInfo.fileType)"
  192. alt=""
  193. />
  194. <span>{{ item.docInfo.fileName }}</span>
  195. </div>
  196. </div>
  197. </el-scrollbar>
  198. </el-collapse-item>
  199. </div>
  200. </el-collapse>
  201. </div>
  202. <!-- 右键唤出的菜单 -->
  203. <div
  204. class="right_menu"
  205. v-if="visible"
  206. :style="{ left: left + 'px', top: top + 'px' }"
  207. >
  208. <div class="menu_item" @click="reName">
  209. <img src="@/assets/images/textbox.png" alt="" />
  210. <span>重命名</span>
  211. </div>
  212. <div class="menu_item" @click="delTabs">
  213. <img src="@/assets/images/trash.png" alt="" />
  214. <span>删除</span>
  215. </div>
  216. </div>
  217. </template>
  218. <script setup>
  219. import Sortable from "sortablejs";
  220. import { setIcon } from "@/utils/index.js";
  221. import draggable from "vuedraggable";
  222. import { onMounted, ref, watch, nextTick } from "vue";
  223. import { toRaw } from "@vue/reactivity";
  224. import {
  225. listLabel,
  226. addLabel,
  227. delLabel,
  228. updateLabel,
  229. sortLabel,
  230. } from "@/api/biz/label.js";
  231. import { listFavorite, listFavoriteById } from "@/api/biz/favorite.js";
  232. const activeNames = ref(["folder", "file"]);
  233. const clickCollect = ref("first"); //当前标签
  234. const isAddCollect = ref(false); //是否在添加标签
  235. const tabName = ref(""); //新增的标签名
  236. const changeTabName = ref(""); //修改的标签名
  237. const tabList = ref([]);
  238. const tableData = [
  239. {
  240. date: "2016-05-03",
  241. name: "Tom",
  242. state: "California",
  243. city: "Los Angeles",
  244. address: "No. 189, Grove St, Los Angeles",
  245. zip: "CA 90036",
  246. },
  247. {
  248. date: "2016-05-02",
  249. name: "Tom",
  250. state: "California",
  251. city: "Los Angeles",
  252. address: "No. 189, Grove St, Los Angeles",
  253. zip: "CA 90036",
  254. },
  255. {
  256. date: "2016-05-04",
  257. name: "Tom",
  258. state: "California",
  259. city: "Los Angeles",
  260. address: "No. 189, Grove St, Los Angeles",
  261. zip: "CA 90036",
  262. },
  263. {
  264. date: "2016-05-01",
  265. name: "Tom",
  266. state: "California",
  267. city: "Los Angeles",
  268. address: "No. 189, Grove St, Los Angeles",
  269. zip: "CA 90036",
  270. },
  271. {
  272. date: "2016-05-08",
  273. name: "Tom",
  274. state: "California",
  275. city: "Los Angeles",
  276. address: "No. 189, Grove St, Los Angeles",
  277. zip: "CA 90036",
  278. },
  279. {
  280. date: "2016-05-06",
  281. name: "Tom",
  282. state: "California",
  283. city: "Los Angeles",
  284. address: "No. 189, Grove St, Los Angeles",
  285. zip: "CA 90036",
  286. },
  287. {
  288. date: "2016-05-07",
  289. name: "Tom",
  290. state: "California",
  291. city: "Los Angeles",
  292. address: "No. 189, Grove St, Los Angeles",
  293. zip: "CA 90036",
  294. },
  295. ];
  296. const visible = ref(false); //显示右键菜单
  297. const top = ref(0);
  298. const left = ref(0);
  299. const thisTab = ref({}); //当前右键的标签
  300. const isChangeTabName = ref(0); //存放修改状标签的id
  301. const folderArr = ref(); //文件夹数组
  302. const fileArr = ref(); //文件数组
  303. const isList = ref(false); //控制显示方式
  304. onMounted(async () => {
  305. await getList();
  306. await getCollectList();
  307. rowDrop();
  308. // 添加监听,点击其他地方关闭菜单
  309. window.addEventListener("click", closeMenu, true);
  310. });
  311. // tab右键事件
  312. const tabClick = (e, item) => {
  313. e.preventDefault();
  314. e.stopPropagation();
  315. // console.log("e", e);
  316. // console.log("item", toRaw(item));
  317. thisTab.value = item;
  318. // 唤出右键菜单,思路:获取鼠标位置来定位菜单
  319. visible.value = true;
  320. top.value = e.pageY;
  321. left.value = e.pageX;
  322. };
  323. // 关闭右键菜单
  324. const closeMenu = () => {
  325. // console.log("close");
  326. visible.value = false;
  327. };
  328. //添加标签
  329. const toAddCollectFn = async () => {
  330. isAddCollect.value = true;
  331. };
  332. const addCollectFn = async () => {
  333. if (!tabName.value) {
  334. isAddCollect.value = false;
  335. return;
  336. }
  337. const list = toRaw(tabList.value);
  338. let order = 0;
  339. if (list.length > 0) {
  340. order = getBigOrder(list);
  341. }
  342. const res = await addLabel({
  343. labelName: tabName.value,
  344. orderNum: order,
  345. });
  346. if (res.code == 200) {
  347. isAddCollect.value = false;
  348. tabName.value = "";
  349. getList();
  350. }
  351. };
  352. //获取标签数据
  353. const getList = async () => {
  354. const res = await listLabel();
  355. console.log("tabList =", res);
  356. if (res.rows.length > 0) {
  357. let dates = JSON.parse(JSON.stringify(res.rows));
  358. dates.sort(sortArr("orderNum"));
  359. tabList.value = [...dates];
  360. // console.log("tabList", tabList.value);
  361. // console.log("dates", dates);
  362. }
  363. };
  364. // 删除标签
  365. const delTabs = async () => {
  366. let tabDetail = toRaw(thisTab.value);
  367. const res = await delLabel(tabDetail.labelId); //直接传id
  368. // console.log("delres = ", res);
  369. getList();
  370. };
  371. // TODO 按标签获取收藏数据,实现文件夹收藏功能,文件夹右键菜单和文件右键菜单样式统一
  372. //获取收藏数据
  373. const getCollectList = async () => {
  374. const res = await listFavoriteById(17);
  375. console.log("collectres = ", res);
  376. if (res.code === 200 && res.rows.length > 0) {
  377. tableData.value = res.rows;
  378. }
  379. };
  380. // 修改便签名
  381. const reName = async () => {
  382. console.log("thisTab", toRaw(thisTab.value));
  383. let tabDetail = toRaw(thisTab.value);
  384. changeTabName.value = tabDetail.labelName;
  385. isChangeTabName.value = tabDetail.labelId;
  386. };
  387. const reTabName = async () => {
  388. let tabDetail = toRaw(thisTab.value);
  389. const res = await updateLabel({
  390. labelId: tabDetail.labelId,
  391. labelName: changeTabName.value,
  392. });
  393. await getList();
  394. isChangeTabName.value = 0;
  395. console.log("rename", res);
  396. };
  397. //拖拽事件
  398. const rowDrop = () => {
  399. const el = document.querySelector(".tabSign .el-tabs__nav"); //找到想要拖拽的那一列
  400. // console.log('el',el);
  401. const _this = toRaw(JSON.parse(JSON.stringify(tabList.value))); //否则下面遍历会出错
  402. // console.log("_this", _this);
  403. Sortable.create(el, {
  404. filter: "#tab-first,#tab-second", //限制哪些可以拖动
  405. preventOnFilter: true,
  406. onChoose: function (/**Event*/ evt) {
  407. evt.oldIndex;
  408. // console.log("evt", evt);
  409. },
  410. //结束拖拽事件
  411. async onEnd({ newIndex, oldIndex, to }) {
  412. //拿到交换前后对应的index
  413. const ni = newIndex - 3;
  414. const oi = oldIndex - 3;
  415. let list = toRaw(tabList.value);
  416. list = list.filter((item) => item); //筛除空数据
  417. console.log("list", list);
  418. console.log("newIndex", ni);
  419. console.log("oldIndex", oi);
  420. const newList = list.map((item, index) => {
  421. console.log("item", item);
  422. if (oi > ni) {
  423. // 从后往前,需要将oi和ni之间的+1
  424. if (index === oi) {
  425. item.orderNum = _this[ni].orderNum;
  426. // console.log("oiitem", item);
  427. } else if (ni < index < oi) {
  428. item.orderNum += 1;
  429. }
  430. } else if (oi < ni) {
  431. // 从前往后,需要将oi和ni之间的-1
  432. if (index === oi) {
  433. item.orderNum = _this[ni].orderNum;
  434. // console.log("oiitem", item);
  435. } else if (oi < index < ni) {
  436. item.orderNum -= 1;
  437. }
  438. }
  439. return item;
  440. });
  441. console.log("newList", newList);
  442. const res = await sortLabel(newList);
  443. console.log("res", res);
  444. await getList();
  445. },
  446. });
  447. };
  448. const tabchange = async (labelId) => {
  449. console.log("labelId", toRaw(labelId));
  450. // 获取当前标签下的数据
  451. const res = await listFavoriteById(labelId);
  452. // console.log("res", res);
  453. folderArr.value = res.filter((item) => item.isFolder === "Y");
  454. fileArr.value = res.filter((item) => item.isFolder === "N");
  455. console.log("folderArr", folderArr.value);
  456. console.log("fileArr", fileArr.value);
  457. };
  458. // 工具函数
  459. //获取新增标签时要赋予的ordername
  460. const getBigOrder = (arr) => {
  461. let num = 0;
  462. arr.forEach((item) => {
  463. if (item.orderNum > num) {
  464. num = item.orderNum;
  465. }
  466. });
  467. return num + 1;
  468. };
  469. //数组排序
  470. const sortArr = (field) => {
  471. return function (a, b) {
  472. return a[field] - b[field];
  473. };
  474. };
  475. </script>
  476. <style lang="scss" scoped>
  477. .container {
  478. height: 100%;
  479. background-color: #fff;
  480. border-radius: 4px;
  481. .tags {
  482. display: flex;
  483. width: 100%;
  484. height: 40px;
  485. box-sizing: border-box;
  486. border-top: 1px solid #c1cce3;
  487. border-bottom: 1px solid #c1cce3;
  488. background-color: #f5f7f9;
  489. }
  490. .addCollect {
  491. margin-left: 16px;
  492. cursor: pointer;
  493. height: 100%;
  494. line-height: 40px;
  495. font-size: 14px;
  496. color: #2e6bc8;
  497. font-weight: 400;
  498. vertical-align: middle;
  499. }
  500. }
  501. .right_menu {
  502. width: 100px;
  503. position: absolute;
  504. padding: 8px;
  505. box-shadow: 0px 2px 10px 1px rgba(199, 203, 216);
  506. border-radius: 4px 4px 4px 4px;
  507. border: 1px solid #c1cce3;
  508. background-color: #fff;
  509. z-index: 10000;
  510. .menu_item {
  511. width: 100%;
  512. height: 40px;
  513. border-radius: 4px 4px 4px 4px;
  514. display: flex;
  515. align-items: center;
  516. &:hover {
  517. background-color: #f5f7f9;
  518. }
  519. span {
  520. margin-left: 4px;
  521. }
  522. }
  523. }
  524. // tag间距
  525. ::v-deep .el-tabs__item {
  526. padding: 0 16px !important;
  527. color: #505870 !important;
  528. font-weight: 400 !important;
  529. }
  530. ::v-deep .el-tabs--top .el-tabs__item.is-top:last-child {
  531. padding-right: 0 !important;
  532. }
  533. // tag选中颜色
  534. ::v-deep .el-tabs__item.is-active {
  535. color: #2e6bc8 !important;
  536. font-weight: normal;
  537. font-family: Inter-SemiBold;
  538. }
  539. ::v-deep .el-tabs__active-bar {
  540. background-color: #2e6bc8;
  541. }
  542. .table_icon {
  543. height: 27px;
  544. width: 27px;
  545. vertical-align: middle;
  546. }
  547. ::v-deep .el-collapse-item__content {
  548. padding-bottom: 0;
  549. }
  550. ::v-deep .el-collapse-item__header {
  551. background-color: #ebeff6 !important;
  552. width: 100% !important;
  553. height: 24px !important;
  554. }
  555. ::v-deep .el-collapse-item__arrow {
  556. position: relative;
  557. color: #2e6bc8;
  558. right: 97%;
  559. }
  560. ::v-deep .el-table td.el-table__cell {
  561. border: none;
  562. font-size: 14px !important;
  563. font-weight: 400 !important;
  564. color: #000 !important;
  565. }
  566. ::v-deep .el-table__row {
  567. height: 35px !important;
  568. }
  569. ::v-deep .el-table .el-table__header-wrapper th {
  570. border-bottom: none;
  571. border-right: 1px solid #c1cce3;
  572. background-color: #fff !important;
  573. color: #505870;
  574. font-size: 14px;
  575. }
  576. .collapseItem_title {
  577. position: relative;
  578. left: 40px;
  579. color: #2e6bc8;
  580. font-family: Inter-Medium;
  581. font-size: 12px;
  582. }
  583. // 表格右边3个靠右对齐
  584. ::v-deep .el-table__header thead tr th {
  585. font-family: Inter-Medium;
  586. font-size: 14px;
  587. color: #505870;
  588. text-align: right;
  589. &:nth-child(1) {
  590. text-align: left;
  591. }
  592. }
  593. ::v-deep .el-table__body tbody [class*="column_"] {
  594. text-align: right;
  595. &:nth-child(4n + 1) {
  596. text-align: left;
  597. }
  598. }
  599. //平铺
  600. .tile_box {
  601. width: 100%;
  602. height: 300px;
  603. display: flex;
  604. flex-wrap: wrap;
  605. .file_box {
  606. width: 116px;
  607. min-height: 138px;
  608. // border: 1px solid #000;
  609. display: flex;
  610. flex-direction: column;
  611. align-items: center;
  612. .big_file_img {
  613. width: 100px;
  614. height: 100px;
  615. }
  616. span {
  617. width: 100%;
  618. text-align: center;
  619. font-size: 14px;
  620. font-weight: 400;
  621. line-height: 22px;
  622. display: -webkit-box;
  623. -webkit-box-orient: vertical;
  624. text-overflow: ellipsis;
  625. -webkit-line-clamp: 2; //例如超过3行显示省略号
  626. overflow: hidden;
  627. }
  628. }
  629. }
  630. </style>