index.vue 16 KB

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