• Vue和Element UI 路由跳转,侧边导航的路由跳转,侧边栏拖拽


     首先看布局,因为我的用于页面显示的  是通过重定向定位到登陆页的,然后通过登陆页跳转到主页。项目中用到了点击侧边栏的跳转,所以记录下来,方便有需要的人用到~

    1. 阐述
      (1).content{ display:flex;} 一定要有,否则在拖拽时会出现换行的情况
      (2)resize 要相对于父级绝对定位

    1. <template>
    2. <!-- <div class="el-dialog__header">-->
    3. <!-- </div>-->
    4. <div >
    5. <!--搜索框-->
    6. <div class="top-wrapper ">
    7. <div class="search el-input el-input--suffix">
    8. <input
    9. type="text"
    10. autocomplete="off"
    11. placeholder="输入指标名称搜索"
    12. class="el-input__inner"
    13. />
    14. </div>
    15. </div>
    16. <!--中部-->
    17. <div class="indicator-wrapper">
    18. <!--侧边栏 -->
    19. <div class="indicator-side">
    20. <a
    21. :class="{ 'indicator-category': true, 'indicator-category-active': item.checked }"
    22. v-for="item in sideList"
    23. :key="item.id"
    24. @click.prevent="categoryClick(item)"
    25. href="#!"
    26. >
    27. {{ item.name }}
    28. </a>
    29. </div>
    30. <!--中间选择器 -->
    31. <div class="indicator-body">
    32. <div class="indicator-block"
    33. v-for="item in sideList"
    34. :key="item.id" :id="'chen'+ item.id">
    35. <div class="indicator-group">
    36. <span class="indicator-title">{{ item.name }} </span>
    37. </div>
    38. <div class="el-row">
    39. <div class="el-col el-col-8" v-for="el in item.child " :key="el.id">
    40. <el-checkbox v-model="el.checked" class="el-checkbox__input el-checkbox"
    41. ><span class="el-checkbox__label">{{ el.name }}</span></el-checkbox>
    42. </div>
    43. </div>
    44. </div>
    45. </div>
    46. <!--拖拽-->
    47. <div class="flex ">
    48. <div class="indicator-drag">
    49. <div class="indicator-content">
    50. <div class="drag-title">已选指标</div>
    51. <div class="drag-sec">拖动可自定义指标顺序</div>
    52. <div class="indicator-limit_low">
    53. <div class="drag-block not-allow mg2">账户名称</div>
    54. </div>
    55. <div class="drag-sepreate">以上指标将横向固定</div>
    56. </div>
    57. <div class="indicator-limit-many" style="max-height: 445px">
    58. <section
    59. v-draggable="[
    60. drag,
    61. {
    62. animation: 150,
    63. ghostClass: 'ghost',
    64. group: 'people',
    65. onUpdate,
    66. onAdd,
    67. onRemove
    68. }
    69. ]"
    70. class="flex flex-col gap-2 p-4 w-300px h-300px m-auto bg-gray-500/5 rounded overflow-auto"
    71. >
    72. <div
    73. v-for="item in drag"
    74. :key="item.id"
    75. class="drag-block hover-class all-scroll mg2"
    76. @click="dragClick(item)"
    77. >
    78. {{ item.name
    79. }}
    80. <el-icon
    81. @click="removeItem(item.id)"
    82. style="
    83. float: right;
    84. align-items: center;
    85. position: relative;
    86. top: 8px;
    87. "
    88. class="mg-icon-close close"
    89. >
    90. <close
    91. />
    92. </el-icon>
    93. </div>
    94. </section>
    95. <div class="flex justify-between">
    96. <preview-list :list="drag" />
    97. </div>
    98. </div>
    99. </div>
    100. </div>
    101. </div>
    102. </div>
    103. </template>
    104. <script setup lang="ts">
    105. import { ref } from "vue";
    106. import { vDraggable } from "vue-draggable-plus";
    107. import { Close } from "@element-plus/icons-vue";
    108. const sideList = ref([
    109. {
    110. id: 1,
    111. name: "基本信息",
    112. child: [
    113. {
    114. id: 1,
    115. name: "账号名称"
    116. },
    117. {
    118. id: 2,
    119. name: "账户ID"
    120. },
    121. {
    122. id: 3,
    123. name: "账户主体"
    124. }
    125. ]
    126. },
    127. {
    128. id: 2,
    129. name: "财务流水",
    130. child: [
    131. {
    132. id: 1,
    133. name: "共享赠款支出(¥)"
    134. },
    135. {
    136. id: 2,
    137. name: "账户总支出"
    138. },
    139. {
    140. id: 3,
    141. name: "账户现金支出"
    142. }
    143. ]
    144. },
    145. {
    146. id: 3,
    147. name: "展现数据",
    148. child: [
    149. {
    150. id: 1,
    151. name: "消耗"
    152. },
    153. {
    154. id: 2,
    155. name: "展示数"
    156. },
    157. {
    158. id: 3,
    159. name: "平均千次展现费用"
    160. }
    161. ]
    162. },
    163. {
    164. id: 4,
    165. name: "转化数据",
    166. child: [
    167. {
    168. id: 1,
    169. name: "转换数"
    170. },
    171. {
    172. id: 2,
    173. name: "转换陈本"
    174. },
    175. {
    176. id: 3,
    177. name: "转换率"
    178. }
    179. ]
    180. },
    181. {
    182. id: 5,
    183. name: "转化数据(计费时间)",
    184. child: [
    185. {
    186. id: 1,
    187. name: "转化数(计费时间)"
    188. },
    189. {
    190. id: 2,
    191. name: "转化成本(计费时间)"
    192. },
    193. {
    194. id: 3,
    195. name: "深度转化次数(计费时间)"
    196. }
    197. ]
    198. },
    199. {
    200. id: 6,
    201. name: " APP下载数据",
    202. child: [
    203. {
    204. id: 1,
    205. name: "安卓下载开始数"
    206. },
    207. {
    208. id: 2,
    209. name: "安卓下载开始成本"
    210. },
    211. {
    212. id: 3,
    213. name: "安卓下载开始率"
    214. }
    215. ]
    216. },
    217. {
    218. id: 7,
    219. name: "视频数据",
    220. child: [
    221. {
    222. id: 1,
    223. name: "播放数"
    224. },
    225. {
    226. id: 2,
    227. name: "有效播放数"
    228. },
    229. {
    230. id: 3,
    231. name: "有效播放率"
    232. }
    233. ]
    234. },
    235. {
    236. id: 8,
    237. name: "落地页及门店数据",
    238. child: [
    239. {
    240. id: 1,
    241. name: "点击电话按钮"
    242. },
    243. {
    244. id: 2,
    245. name: "表单提交"
    246. },
    247. {
    248. id: 3,
    249. name: "地图搜索"
    250. }
    251. ]
    252. },
    253. {
    254. id: 9,
    255. name: "附加创意",
    256. child: [
    257. {
    258. id: 1,
    259. name: "附加创意电话按钮点击"
    260. },
    261. {
    262. id: 2,
    263. name: "附加创意在线咨询点击"
    264. },
    265. {
    266. id: 3,
    267. name: "附加创意表单按钮点击"
    268. }
    269. ]
    270. },
    271. {
    272. id: 10,
    273. name: "互动数据",
    274. child: [
    275. {
    276. id: 1,
    277. name: "新增关注数"
    278. },
    279. {
    280. id: 2,
    281. name: "点赞数"
    282. },
    283. {
    284. id: 3,
    285. name: "评论提交数"
    286. }
    287. ]
    288. },
    289. {
    290. id: 11,
    291. name: " 直播间数据",
    292. child: [
    293. {
    294. id: 1,
    295. name: "直播间观看数"
    296. },
    297. {
    298. id: 2,
    299. name: "直播间超过1分钟观看数"
    300. },
    301. {
    302. id: 3,
    303. name: "直播间关注数"
    304. }
    305. ]
    306. },
    307. {
    308. id: 12,
    309. name: "游戏行业",
    310. child: [
    311. {
    312. id: 1,
    313. name: "当日付费金额"
    314. },
    315. {
    316. id: 2,
    317. name: "当日付费ROI"
    318. },
    319. {
    320. id: 3,
    321. name: "激活24h首次付费数"
    322. }
    323. ]
    324. },
    325. {
    326. id: 13,
    327. name: "线索收集",
    328. child: [
    329. {
    330. id: 1,
    331. name: "有效获客"
    332. },
    333. {
    334. id: 2,
    335. name: "乘客首次下单数"
    336. },
    337. {
    338. id: 3,
    339. name: "回访—加好友(计费时间)"
    340. }
    341. ]
    342. }
    343. ]);
    344. const categoryClick = (item) => {
    345. sideList.value.forEach((el) => (el.checked = false));
    346. item.checked = !item.checked;
    347. const element = document.getElementById("chen" + item.id);
    348. if (element) {
    349. element.scrollIntoView({ behavior: "smooth" });
    350. }
    351. };
    352. const count = ref(0);
    353. const removeItem = (id) => {
    354. drag.value = drag.value.filter(item => item.id != id);
    355. };
    356. // const domeRef = ref<HTMLElement | null>(null);
    357. // const handleClick = (MouseEvent) => {
    358. // e.preventDefault();
    359. // };
    360. //拖拽
    361. const drag = ref([
    362. {
    363. id: 1,
    364. name: "账户ID"
    365. },
    366. {
    367. id: 2,
    368. name: "备注"
    369. },
    370. {
    371. id: 3,
    372. name: "项目"
    373. },
    374. {
    375. id: 4,
    376. name: "登录邮箱"
    377. },
    378. {
    379. id: 5,
    380. name: "账户余额(元)"
    381. },
    382. {
    383. id: 6,
    384. name: "消耗"
    385. },
    386. {
    387. id: 7,
    388. name: "点击率"
    389. },
    390. {
    391. id: 8,
    392. name: "深度转化成本"
    393. },
    394. {
    395. id: 9,
    396. name: "首次付费率"
    397. },
    398. {
    399. id: 10,
    400. name: "APP内访问"
    401. },
    402. {
    403. id: 11,
    404. name: "app内下单"
    405. }
    406. ]);
    407. const dragClick = (item) => {
    408. drag.value.forEach((el) => (el.checked = false));
    409. item.checked = !item.checked;
    410. };
    411. function onUpdate() {
    412. console.log("update");
    413. }
    414. function onAdd() {
    415. console.log("add");
    416. }
    417. function onRemove() {
    418. console.log("remove");
    419. }
    420. </script>
    421. <style scoped lang="scss">
    422. ::v-deep .el-scrollbar {
    423. overflow: hidden;
    424. height: 100%;
    425. position: static !important;
    426. }
    427. ::v-deep .el-checkbox__input.is-checked .el-checkbox__inner {
    428. background-color: #409eff;;
    429. //border-color: var(--el-checkbox-checked-input-border-color);
    430. }
    431. //隐藏滚动条
    432. ::-webkit-scrollbar-thumb {
    433. border-radius: 5px;
    434. background-color: rgb(255, 255, 255, 0.2);;
    435. }
    436. ::-webkit-scrollbar {
    437. width: 10px;
    438. height: 10px;
    439. }
    440. //搜索框
    441. .top-wrapper {
    442. display: flex;
    443. justify-content: flex-start;
    444. margin-bottom: 16px;
    445. }
    446. .top-wrapper .search {
    447. width: 250px;
    448. }
    449. .el-input {
    450. position: relative;
    451. font-size: 14px;
    452. }
    453. .el-input__inner {
    454. -webkit-appearance: none;
    455. background-color: #fff;
    456. background-image: none;
    457. border-radius: 4px;
    458. border: 1px solid #dcdfe6;
    459. box-sizing: border-box;
    460. color: #606266;
    461. display: inline-block;
    462. height: 40px;
    463. line-height: 40px;
    464. outline: 0;
    465. padding: 0 15px;
    466. transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    467. width: 100%;
    468. font-size: inherit;
    469. -webkit-transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    470. }
    471. .el-dialog .el-dialog__body .el-input .el-input__inner {
    472. padding-left: 8px;
    473. color: #333;
    474. }
    475. .el-input .el-input__inner {
    476. height: 32px;
    477. line-height: 32px;
    478. border-radius: 2px;
    479. }
    480. //侧边栏
    481. .indicator-side .indicator-category {
    482. padding-left: 16px;
    483. font-size: 14px;
    484. line-height: 40px;
    485. color: #333;
    486. cursor: pointer;
    487. display: block;
    488. }
    489. .indicator-side .indicator-category-active {
    490. color: #197afb;
    491. background-color: #d6eaff;
    492. }
    493. //中间基本信息
    494. .indicator-block {
    495. padding: 16px 0 0 24px;
    496. border-bottom: 1px solid #eaebec;
    497. }
    498. .indicator-group {
    499. display: flex;
    500. justify-content: flex-start;
    501. }
    502. .indicator-title {
    503. margin-bottom: 16px;
    504. font-weight: 700;
    505. color: #333;
    506. }
    507. .el-checkbox__input.is-checked .el-checkbox__label{
    508. color: #409eff;
    509. }
    510. .el-checkbox__label {
    511. color: #333;
    512. }
    513. .el-checkbox__label,
    514. .el-radio__label {
    515. font-size: 12px;
    516. color: #666;
    517. }
    518. .el-checkbox__label {
    519. display: inline-block;
    520. padding-left: 1px;
    521. line-height: 19px;
    522. font-size: 12px;
    523. }
    524. //拖拽
    525. .indicator-drag .indicator-content {
    526. padding: 0 16px;
    527. }
    528. .indicator-drag .drag-title {
    529. font-size: 14px;
    530. font-weight: 700;
    531. line-height: 100%;
    532. color: #333;
    533. }
    534. .indicator-drag .drag-sec {
    535. margin: 8px 0;
    536. font-size: 12px;
    537. line-height: 100%;
    538. color: #999;
    539. }
    540. .indicator-drag .drag-sepreate {
    541. position: relative;
    542. margin: 16px 0 0;
    543. font-size: 12px;
    544. color: #999;
    545. text-align: center;
    546. }
    547. .indicator-drag .indicator-limit-many {
    548. max-height: 445px;
    549. padding: 0 16px;
    550. margin-top: 16px;
    551. overflow-x: hidden;
    552. overflow-y: auto;
    553. }
    554. .indicator-drag .mg2 {
    555. margin-bottom: 2px;
    556. }
    557. .indicator-drag .drag-block {
    558. position: relative;
    559. height: 40px;
    560. //width: 134px;
    561. padding: 0 30px 0 36px;
    562. overflow: hidden;
    563. line-height: 40px;
    564. text-overflow: ellipsis;
    565. white-space: nowrap;
    566. background-color: #fff;
    567. border-bottom: 1px solid #e8eaec;
    568. }
    569. .indicator-drag .drag-block .close {
    570. position: absolute;
    571. top: 13px;
    572. line-height: 100%;
    573. color: #cecece;
    574. cursor: pointer;
    575. }
    576. //滑动条
    577. .infinite-list {
    578. width: 160px;
    579. height: 300px;
    580. padding: 0;
    581. margin: 0;
    582. list-style: none;
    583. }
    584. .infinite-list .infinite-list-item {
    585. display: flex;
    586. align-items: center;
    587. justify-content: center;
    588. height: 40px;
    589. padding-left: 16px;
    590. font-size: 14px;
    591. background: #409eff;
    592. margin: 10px;
    593. color: #409eff;
    594. }
    595. .infinite-list .infinite-list-item + .list-item {
    596. margin-top: 10px;
    597. }
    598. //中部
    599. .indicator-wrapper {
    600. display: flex;
    601. width: 832px;
    602. height: 516px;
    603. border: 1px solid #eaebec;
    604. border-radius: 4px;
    605. }
    606. //侧边栏
    607. .indicator-side {
    608. flex-shrink: 0;
    609. width: 160px;
    610. overflow: auto;
    611. border-right: 1px solid #eaebec;
    612. }
    613. //选择器
    614. .indicator-body {
    615. width: 672px;
    616. overflow: auto;
    617. scroll-behavior: smooth;
    618. }
    619. //右边
    620. .indicator-drag {
    621. position: absolute;
    622. top: 0;
    623. right: 0;
    624. flex-shrink: 0;
    625. width: 216px;
    626. //height: 676px;
    627. padding: 25px 0;
    628. overflow: auto;
    629. background-color: #f8f8f9;
    630. border-right: 1px solid #eaebec;
    631. }
    632. </style>

  • 相关阅读:
    SPOJ 4110 Fast Maximum Flow (最大流模板)
    C语言之婚礼上的谎言
    RestFul,会话技术,Fiddler
    自动翻译软件-批量批量自动翻译软件推荐
    py19_初识 Python 异常处理的简单总结
    Java初始化大量数据到Neo4j中(一)
    物联网鸿蒙实训解决方案
    数据结构和算法(10):B-树
    chrome 录制器及性能分析工具的使用
    8月榜单丨飞瓜数据B站UP主排行榜(哔哩哔哩平台)发布!
  • 原文地址:https://blog.csdn.net/2301_78133614/article/details/140375386