index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <div class="container">
  3. <!-- 标签 -->
  4. <div class="tags">
  5. <!-- TODO 标签可以拖动位置 -->
  6. <el-tabs
  7. v-model="clickCollect"
  8. class="demo-tabs"
  9. @tab-click="changeSearchFor"
  10. >
  11. <el-tab-pane label="常用" name="first"></el-tab-pane>
  12. <el-tab-pane label="默认" name="second"></el-tab-pane>
  13. <el-tab-pane
  14. v-for="item in tabList"
  15. :key="item.labelId"
  16. :label="item.labelName"
  17. :name="item.labelId"
  18. @contextmenu.prevent="checkRight($event, item)"
  19. ></el-tab-pane>
  20. </el-tabs>
  21. <!-- 添加标签 -->
  22. <div class="addCollect">
  23. <div v-if="!isAddCollect">
  24. <el-icon color="#2E6BC8">
  25. <Plus />
  26. </el-icon>
  27. <span @click="toAddCollectFn">添加标签</span>
  28. </div>
  29. <div v-else>
  30. <el-input
  31. v-model="tabName"
  32. size="mini"
  33. @blur="addCollectFn"
  34. maxlength="32"
  35. :autofocus="true"
  36. ></el-input>
  37. </div>
  38. </div>
  39. </div>
  40. <el-collapse v-model="activeNames" @change="handleChange">
  41. <div v-if="isList">
  42. <el-collapse-item name="folder">
  43. <template #title>
  44. <span class="collapseItem_title">文件夹</span>
  45. </template>
  46. <!-- 表格 -->
  47. <el-table
  48. :data="tableData"
  49. style="width: 100%"
  50. height="250"
  51. :scrollbar-always-on="true"
  52. >
  53. <el-table-column fixed prop="date" label="名称" width="500">
  54. <template #default="scope">
  55. <div>
  56. <img
  57. class="table_icon"
  58. src="@/assets/images/fileBox.png"
  59. alt=""
  60. style=""
  61. />
  62. {{ scope.row.date }}
  63. </div>
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="name" label="时间" width="200" />
  67. <el-table-column prop="state" label="类型" width="180" />
  68. <el-table-column prop="city" label="大小" width="160" />
  69. </el-table>
  70. </el-collapse-item>
  71. <el-collapse-item name="file">
  72. <template #title>
  73. <span class="collapseItem_title">文件</span>
  74. </template>
  75. <!-- 表格 -->
  76. <el-table
  77. :data="tableData"
  78. style="width: 100%"
  79. height="250"
  80. :scrollbar-always-on="true"
  81. >
  82. <el-table-column fixed prop="date" label="名称" width="500">
  83. <template #default="scope">
  84. <div>
  85. <img
  86. class="table_icon"
  87. src="@/assets/images/fileBox.png"
  88. alt=""
  89. style=""
  90. />
  91. {{ scope.row.date }}
  92. </div>
  93. </template>
  94. </el-table-column>
  95. <el-table-column prop="name" label="时间" width="200" />
  96. <el-table-column prop="state" label="类型" width="180" />
  97. <el-table-column prop="city" label="大小" width="160" />
  98. </el-table>
  99. </el-collapse-item>
  100. </div>
  101. <div v-else>
  102. <el-collapse-item name="folder">
  103. <template #title>
  104. <span class="collapseItem_title">文件夹</span>
  105. </template>
  106. <!-- 平铺 -->
  107. <el-scrollbar height="360px">
  108. <div class="tile_box">
  109. <div class="file_box" v-for="item in 20" :key="item">
  110. <img
  111. class="big_file_img"
  112. src="@/assets/images/fileBox.png"
  113. alt=""
  114. />
  115. <span>Inceptos</span>
  116. </div>
  117. </div>
  118. </el-scrollbar>
  119. </el-collapse-item>
  120. <el-collapse-item name="file">
  121. <template #title>
  122. <span class="collapseItem_title">文件</span>
  123. </template>
  124. <!-- 平铺 -->
  125. <el-scrollbar height="360px">
  126. <div class="tile_box">
  127. <div class="file_box" v-for="item in 20" :key="item">
  128. <img
  129. class="big_file_img"
  130. src="@/assets/images/fileType//file/DOC.png"
  131. alt=""
  132. />
  133. <span>Inceptos</span>
  134. </div>
  135. </div>
  136. </el-scrollbar>
  137. </el-collapse-item>
  138. </div>
  139. </el-collapse>
  140. </div>
  141. <!-- 右键唤出的菜单 -->
  142. <div
  143. class="right_menu"
  144. v-show="visible"
  145. :style="{ left: left + 'px', top: top + 'px' }"
  146. >
  147. <div class="menu_item">
  148. <img src="@/assets/images/textbox.png" alt="" />
  149. <span>重命名</span>
  150. </div>
  151. <div class="menu_item">
  152. <img src="@/assets/images/trash.png" alt="" />
  153. <span>删除</span>
  154. </div>
  155. </div>
  156. </template>
  157. <script setup>
  158. import { onMounted, ref, watch } from "vue";
  159. import { listLabel, addLabel, delLabel } from "@/api/biz/label.js";
  160. import { listFavorite } from "@/api/biz/favorite.js";
  161. const activeNames = ref(["folder", "file"]);
  162. const clickCollect = ref("first"); //当前标签
  163. const isAddCollect = ref(false); //是否在添加标签
  164. const tabName = ref(""); //新增的标签名
  165. const tabList = ref([]);
  166. const tableData = [
  167. {
  168. date: "2016-05-03",
  169. name: "Tom",
  170. state: "California",
  171. city: "Los Angeles",
  172. address: "No. 189, Grove St, Los Angeles",
  173. zip: "CA 90036",
  174. },
  175. {
  176. date: "2016-05-02",
  177. name: "Tom",
  178. state: "California",
  179. city: "Los Angeles",
  180. address: "No. 189, Grove St, Los Angeles",
  181. zip: "CA 90036",
  182. },
  183. {
  184. date: "2016-05-04",
  185. name: "Tom",
  186. state: "California",
  187. city: "Los Angeles",
  188. address: "No. 189, Grove St, Los Angeles",
  189. zip: "CA 90036",
  190. },
  191. {
  192. date: "2016-05-01",
  193. name: "Tom",
  194. state: "California",
  195. city: "Los Angeles",
  196. address: "No. 189, Grove St, Los Angeles",
  197. zip: "CA 90036",
  198. },
  199. {
  200. date: "2016-05-08",
  201. name: "Tom",
  202. state: "California",
  203. city: "Los Angeles",
  204. address: "No. 189, Grove St, Los Angeles",
  205. zip: "CA 90036",
  206. },
  207. {
  208. date: "2016-05-06",
  209. name: "Tom",
  210. state: "California",
  211. city: "Los Angeles",
  212. address: "No. 189, Grove St, Los Angeles",
  213. zip: "CA 90036",
  214. },
  215. {
  216. date: "2016-05-07",
  217. name: "Tom",
  218. state: "California",
  219. city: "Los Angeles",
  220. address: "No. 189, Grove St, Los Angeles",
  221. zip: "CA 90036",
  222. },
  223. ];
  224. const visible = ref(false); //显示右键菜单
  225. const top = ref(0);
  226. const left = ref(0);
  227. onMounted(async () => {
  228. await getList();
  229. await getCollectList();
  230. });
  231. // tab右键事件
  232. const checkRight = (e, item) => {
  233. console.log('11');
  234. // TODO 唤出右键菜单,思路:获取鼠标位置来定位菜单
  235. this.visible = true;
  236. top.value = e.pageY;
  237. left.value = e.pageX;
  238. };
  239. // 关闭右键菜单
  240. const closeMenu = () => {
  241. visible.value = false;
  242. };
  243. //添加标签
  244. const toAddCollectFn = async () => {
  245. isAddCollect.value = true;
  246. // const res = await addLabel({
  247. // labelName: "tab1",
  248. // params: {},
  249. // });
  250. // if (res.code == 200) {
  251. // getList();
  252. // }
  253. };
  254. const addCollectFn = async () => {
  255. if (!tabName.value) {
  256. isAddCollect.value = false;
  257. return;
  258. }
  259. const res = await addLabel({
  260. labelName: tabName.value,
  261. });
  262. if (res.code == 200) {
  263. isAddCollect.value = false;
  264. tabName.value = "";
  265. getList();
  266. }
  267. };
  268. //获取标签数据
  269. const getList = async () => {
  270. const res = await listLabel();
  271. console.log("tabList =", res);
  272. if (res.rows.length > 0) {
  273. tabList.value = res.rows;
  274. }
  275. };
  276. // 删除标签
  277. const delTabs = async () => {
  278. const res = await delLabel("7"); //直接传id
  279. console.log("delres = ", res);
  280. getList();
  281. };
  282. //获取收藏数据
  283. const getCollectList = async () => {
  284. const res = await listFavorite();
  285. // console.log("collectres = ", res);
  286. if (res.code === 200 && res.rows.length > 0) {
  287. tableData.value = res.rows;
  288. }
  289. };
  290. watch(
  291. () => visible.value,
  292. (nv, ov) => {
  293. if (nv) {
  294. console.log('r',nv);
  295. document.body.addEventListener("click", closeMenu());
  296. } else {
  297. document.body.removeEventListener("click",closeMenu());
  298. }
  299. }
  300. );
  301. </script>
  302. <style lang="scss" scoped>
  303. .container {
  304. height: 100%;
  305. background-color: #fff;
  306. border-radius: 4px;
  307. .tags {
  308. display: flex;
  309. width: 100%;
  310. height: 40px;
  311. box-sizing: border-box;
  312. border-top: 1px solid #c1cce3;
  313. border-bottom: 1px solid #c1cce3;
  314. background-color: #f5f7f9;
  315. }
  316. .addCollect {
  317. margin-left: 16px;
  318. cursor: pointer;
  319. height: 100%;
  320. line-height: 40px;
  321. font-size: 14px;
  322. color: #2e6bc8;
  323. font-weight: 400;
  324. vertical-align: middle;
  325. }
  326. }
  327. .right_menu {
  328. width: 100px;
  329. padding: 8px;
  330. box-shadow: 0px 2px 10px 1px rgba(199, 203, 216, 0.4);
  331. border-radius: 4px 4px 4px 4px;
  332. border: 1px solid #c1cce3;
  333. .menu_item {
  334. width: 100%;
  335. height: 40px;
  336. border-radius: 4px 4px 4px 4px;
  337. display: flex;
  338. align-items: center;
  339. &:hover {
  340. background-color: #f5f7f9;
  341. }
  342. span {
  343. margin-left: 4px;
  344. }
  345. }
  346. }
  347. // tag间距
  348. ::v-deep .el-tabs__item {
  349. padding: 0 16px !important;
  350. color: #505870 !important;
  351. font-weight: 400 !important;
  352. }
  353. ::v-deep .el-tabs--top .el-tabs__item.is-top:last-child {
  354. padding-right: 0 !important;
  355. }
  356. // tag选中颜色
  357. ::v-deep .el-tabs__item.is-active {
  358. color: #2e6bc8 !important;
  359. font-weight: normal;
  360. font-family: Inter-SemiBold;
  361. }
  362. ::v-deep .el-tabs__active-bar {
  363. background-color: #2e6bc8;
  364. }
  365. .table_icon {
  366. height: 27px;
  367. width: 27px;
  368. vertical-align: middle;
  369. }
  370. ::v-deep .el-collapse-item__content {
  371. padding-bottom: 0;
  372. }
  373. ::v-deep .el-collapse-item__header {
  374. background-color: #ebeff6 !important;
  375. width: 100% !important;
  376. height: 24px !important;
  377. }
  378. ::v-deep .el-collapse-item__arrow {
  379. position: relative;
  380. color: #2e6bc8;
  381. right: 97%;
  382. }
  383. ::v-deep .el-table td.el-table__cell {
  384. border: none;
  385. font-size: 14px !important;
  386. font-weight: 400 !important;
  387. color: #000 !important;
  388. }
  389. ::v-deep .el-table__row {
  390. height: 35px !important;
  391. }
  392. ::v-deep .el-table .el-table__header-wrapper th {
  393. border-bottom: none;
  394. border-right: 1px solid #c1cce3;
  395. background-color: #fff !important;
  396. color: #505870;
  397. font-size: 14px;
  398. }
  399. .collapseItem_title {
  400. position: relative;
  401. left: 40px;
  402. color: #2e6bc8;
  403. font-family: Inter-Medium;
  404. font-size: 12px;
  405. }
  406. // 表格右边3个靠右对齐
  407. ::v-deep .el-table__header thead tr th {
  408. font-family: Inter-Medium;
  409. font-size: 14px;
  410. color: #505870;
  411. text-align: right;
  412. &:nth-child(1) {
  413. text-align: left;
  414. }
  415. }
  416. ::v-deep .el-table__body tbody [class*="column_"] {
  417. text-align: right;
  418. &:nth-child(4n + 1) {
  419. text-align: left;
  420. }
  421. }
  422. //平铺
  423. .tile_box {
  424. width: 100%;
  425. height: 300px;
  426. display: flex;
  427. flex-wrap: wrap;
  428. .file_box {
  429. width: 116px;
  430. min-height: 138px;
  431. // border: 1px solid #000;
  432. display: flex;
  433. flex-direction: column;
  434. align-items: center;
  435. .big_file_img {
  436. width: 100px;
  437. height: 100px;
  438. }
  439. span {
  440. font-size: 14px;
  441. font-weight: 400;
  442. line-height: 22px;
  443. }
  444. }
  445. }
  446. </style>