LeftPanel.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <!--
  2. * @description: 左侧组件列表
  3. * @Date: 2022-05-24 15:35:07
  4. * @Author: xingheng
  5. -->
  6. <template>
  7. <transition name="slide-fade">
  8. <div
  9. class="bs-left-panel"
  10. @click.stop
  11. >
  12. <div
  13. :class="fold ? 'page-left page-left-fold' : 'page-left'"
  14. :style="{ height }"
  15. >
  16. <el-tabs
  17. v-model="activeName"
  18. tab-position="left"
  19. style="height: 200px"
  20. class="left-tabs-box"
  21. @tab-click="tabClick"
  22. >
  23. <el-tab-pane
  24. name="default"
  25. @click.native="changeActiveCode('')"
  26. >
  27. <span
  28. slot="label"
  29. class="menu-slot"
  30. name="default"
  31. @click="toggleSidebar"
  32. >
  33. <i
  34. class="iconfont-bigscreen menu-icon"
  35. :class="fold ? 'icon-zhankaicaidan' : 'icon-shouqicaidan'"
  36. />
  37. <span class="menu-title-span">{{ foldText }}</span>
  38. </span>
  39. </el-tab-pane>
  40. <el-tab-pane name="layer">
  41. <div
  42. slot="label"
  43. class="menu-slot"
  44. name="layer"
  45. @dbclick="toggleSidebar"
  46. >
  47. <i
  48. :class="['iconfont-bigscreen', 'icon-layer']"
  49. class="menu-icon"
  50. />
  51. <span class="menu-title-span">图层</span>
  52. </div>
  53. <div class="page-left-content">
  54. <div class="page-left-content-title">
  55. <div class="page-left-content-title-text">
  56. 图层
  57. </div>
  58. </div>
  59. <div class="page-left-content-components">
  60. <el-scrollbar>
  61. <LayerList @openRightPanel="openRightPanel" />
  62. </el-scrollbar>
  63. </div>
  64. </div>
  65. </el-tab-pane>
  66. <el-tab-pane
  67. v-for="menu in menuList"
  68. :key="menu.id"
  69. :name="menu.name"
  70. @click.stop.native="
  71. fold = false
  72. changeActiveCode('')
  73. "
  74. >
  75. <div
  76. slot="label"
  77. class="menu-slot"
  78. @dbclick="toggleSidebar"
  79. >
  80. <i
  81. :class="['iconfont-bigscreen', menu.icon]"
  82. class="menu-icon"
  83. />
  84. <span class="menu-title-span">{{ menu.title }}</span>
  85. </div>
  86. <div class="page-left-content">
  87. <div class="page-left-content-title">
  88. <div class="page-left-content-title-text">
  89. {{ menu.title }}
  90. </div>
  91. </div>
  92. <el-scrollbar>
  93. <div class="page-left-content-components">
  94. <div class="draggable chat-list">
  95. <div
  96. v-for="element in menu.components"
  97. :key="element.type + element.name"
  98. :class="element.component
  99. ? 'item menu-component drag-node'
  100. : 'item drag-node'
  101. "
  102. draggable="true"
  103. :data-type="element.type"
  104. :data-name="element.name"
  105. >
  106. <div class="component-name">
  107. {{ element.title || element.name }}
  108. </div>
  109. <div
  110. class="img_dispaly chooseDragNode"
  111. @click.stop="addComponent(element)"
  112. >
  113. <!-- <svg
  114. v-if="element.icon"
  115. class="icon-svg"
  116. aria-hidden="true"
  117. >
  118. <use :xlink:href="`#icon-a-${element.icon}`" />
  119. </svg> -->
  120. <icon-svg
  121. v-if="element.icon"
  122. :name="element.icon"
  123. class="page-opt-list-icon"
  124. />
  125. <img
  126. v-else-if="element.img"
  127. :src="element.img"
  128. class="page-opt-list-img"
  129. alt=""
  130. >
  131. <component
  132. :is="element.component"
  133. :key="new Date().getTime() + 1"
  134. class="page-opt-list-component"
  135. />
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </el-scrollbar>
  141. </div>
  142. </el-tab-pane>
  143. </el-tabs>
  144. </div>
  145. </div>
  146. </transition>
  147. </template>
  148. <script>
  149. import cloneDeep from 'lodash/cloneDeep'
  150. import basicComponents from 'data-room-ui/js/config/basicComponentsConfig'
  151. import g2PlotComponents, { getCustomPlots } from '../G2Plots/plotList'
  152. import echartsComponents from '../Echarts/echartList'
  153. import borderComponents from 'data-room-ui/js/config/borderComponentsConfig'
  154. import decorationComponents from 'data-room-ui/js/config/decorationComponentsConfig'
  155. import LayerList from './LayerList/index.vue'
  156. import { mapMutations } from 'vuex'
  157. import IconSvg from 'data-room-ui/SvgIcon'
  158. import { customSerialize } from 'data-room-ui/js/utils/jsonSerialize.js'
  159. export default {
  160. name: 'PageLeftPanel',
  161. components: {
  162. LayerList,
  163. IconSvg
  164. },
  165. props: {
  166. headerShow: {
  167. type: Boolean,
  168. default: true
  169. },
  170. height: {
  171. type: String,
  172. default: '100vh'
  173. }
  174. },
  175. data () {
  176. return {
  177. echartsComponents,
  178. g2PlotComponents,
  179. activeName: 'chart', // 设置左侧tab栏的默认值
  180. fold: false, // 控制左侧菜单栏伸缩
  181. currentTab: 'basic',
  182. menuList: [
  183. {
  184. id: 1,
  185. name: 'chart',
  186. title: '基础',
  187. icon: 'icon-zujian',
  188. components: basicComponents
  189. },
  190. {
  191. id: 2,
  192. name: 'g2PlotComponents',
  193. title: '图表',
  194. icon: 'icon-jichushuju',
  195. components: this.g2PlotComponents
  196. },
  197. {
  198. id: 7,
  199. name: 'echart',
  200. title: '3D',
  201. icon: 'icon-jichushuju',
  202. components: this.echartsComponents
  203. },
  204. {
  205. id: 3,
  206. name: 'dataV',
  207. title: '边框',
  208. icon: 'icon-border-outer',
  209. components: borderComponents
  210. },
  211. {
  212. id: 4,
  213. name: 'decoration',
  214. title: '装饰',
  215. icon: 'icon-a-1',
  216. components: decorationComponents
  217. },
  218. {
  219. id: 5,
  220. name: 'source',
  221. title: '资源',
  222. icon: 'icon-tupian',
  223. components: []
  224. },
  225. {
  226. id: 6,
  227. name: 'component',
  228. title: '组件',
  229. icon: 'icon-zujian1',
  230. components: ''
  231. }
  232. ],
  233. currentActive: 'chart'
  234. }
  235. },
  236. computed: {
  237. // 获取当前类型的组件
  238. currentComponentList () {
  239. return this.componentList.filter((item) => item.type === this.currentTab)
  240. },
  241. foldText () {
  242. return this.fold ? '展开' : '收起'
  243. }
  244. },
  245. watch: {
  246. fold (isExpand) {
  247. if (isExpand && this.activeName === 'default') {
  248. this.activeName = 'chart'
  249. }
  250. }
  251. },
  252. created () {
  253. this.initList()
  254. this.g2PlotComponents = [...this.g2PlotComponents, ...getCustomPlots()]
  255. this.menuList[1].components = this.g2PlotComponents
  256. this.menuList[2].components = this.echartsComponents
  257. },
  258. mounted () {
  259. this.nodeDrag()
  260. },
  261. methods: {
  262. ...mapMutations('bigScreen', ['changeActiveCode']),
  263. nodeDrag () {
  264. this.$nextTick(() => {
  265. const nodes = document.querySelectorAll('.drag-node')
  266. nodes.forEach((node) => {
  267. node.addEventListener('dragstart', (event) => {
  268. const type = node.getAttribute('data-type')
  269. const name = node.getAttribute('data-name')
  270. // 从menuList中获取当前拖拽的组件
  271. const element = this.menuList
  272. .find((item) => item.name === this.activeName)
  273. ?.components.find(
  274. (item) => item.type === type && item.name === name
  275. )
  276. /* 设置拖拽传输数据 */
  277. event.dataTransfer.setData(
  278. 'dragComponent',
  279. customSerialize({
  280. ...element,
  281. offsetX: event.offsetX,
  282. offsetY: event.offsetY
  283. })
  284. )
  285. })
  286. })
  287. // 阻止默认动作
  288. document.addEventListener(
  289. 'drop',
  290. (e) => {
  291. e.preventDefault()
  292. },
  293. false
  294. )
  295. })
  296. },
  297. onClone (e) {
  298. return cloneDeep(e)
  299. },
  300. onStart (e) {
  301. // this.$emit('onStart', e)
  302. },
  303. // 拖拽组件时触发
  304. onEnd (e) { },
  305. // 点击左侧组件时触发
  306. addComponent (element) {
  307. this.$store.commit('bigScreen/changeActiveItem', element)
  308. this.$emit('addComponent', element)
  309. },
  310. // 初始化
  311. initList () { },
  312. // 点击tab标签
  313. tabClick (tab) {
  314. this.nodeDrag()
  315. if (tab.index !== '0') {
  316. this.fold = false
  317. this.currentActive = this.activeName
  318. }
  319. if (tab.name === 'source') {
  320. this.fold = true
  321. this.$emit('toggleLeftSidebar')
  322. this.$emit('openResource')
  323. this.$emit('toggleLeftSidebar')
  324. }
  325. if (tab.name === 'component') {
  326. this.fold = true
  327. this.$emit('toggleLeftSidebar')
  328. this.$emit('openComponent')
  329. }
  330. },
  331. toggleSidebar () {
  332. this.fold = !this.fold
  333. this.$emit('toggleLeftSidebar')
  334. setTimeout(() => {
  335. this.activeName = this.currentActive
  336. })
  337. },
  338. openRightPanel (config) {
  339. this.$emit('openRightPanel', config)
  340. }
  341. }
  342. }
  343. </script>
  344. <style lang="scss" scoped>
  345. @import '../BigScreenDesign/fonts/iconfont.css';
  346. .bs-left-panel {
  347. display: flex;
  348. background-color: var(--bs-background-1);
  349. .bs-folder-wrap {
  350. width: 20px;
  351. position: relative;
  352. i {
  353. position: absolute;
  354. top: 50%;
  355. left: 0;
  356. transform: translateY(-50%);
  357. font-size: 20px;
  358. color: #fff;
  359. cursor: pointer;
  360. z-index: 1;
  361. }
  362. &:hover {
  363. background: rgba(143, 225, 255, 0.1);
  364. }
  365. }
  366. .page-left {
  367. box-sizing: border-box;
  368. >* {
  369. color: #fff;
  370. }
  371. .iconfont-bigscreen {
  372. color: #fff;
  373. }
  374. .flexible {
  375. width: 45px;
  376. /* border-right: 1px solid #ccc; */
  377. text-align: center;
  378. }
  379. .el-tabs {
  380. width: 250;
  381. position: relative;
  382. height: 100% !important;
  383. overflow: visible;
  384. .is-active {
  385. .iconfont-bigscreen {
  386. color: var(--bs-el-color-primary);
  387. }
  388. .menu-title-span {
  389. color: var(--bs-el-color-primary);
  390. }
  391. }
  392. .el-tab-pane {
  393. height: 100%;
  394. }
  395. .page-left-content {
  396. height: 100%;
  397. }
  398. ::v-deep .el-tabs__content {
  399. height: 100%;
  400. width: 160px;
  401. .page-left-content-title {
  402. background-color: var(--bs-background-2);
  403. color: var(--bs-el-title);
  404. font-size: 14px;
  405. margin: 8px;
  406. padding: 8px 0;
  407. .page-left-content-title-text {
  408. /*border-left: 4px solid #007aff;*/
  409. position: relative;
  410. padding-left: 12px;
  411. &:after {
  412. position: absolute;
  413. left: 0;
  414. top: 50%;
  415. transform: translateY(-50%);
  416. content: '';
  417. width: 4px;
  418. height: 14px;
  419. background-color: var(--bs-el-color-primary);
  420. }
  421. }
  422. }
  423. .el-scrollbar__view {
  424. height: calc(100vh - 55px);
  425. }
  426. .page-left-content-components {
  427. width: 100%;
  428. text-align: center;
  429. padding-bottom: 20px;
  430. margin-bottom: 20px;
  431. .draggable {
  432. display: flex;
  433. flex-wrap: wrap;
  434. cursor: pointer;
  435. box-sizing: border-box;
  436. justify-content: center;
  437. padding: 8px;
  438. cursor: move;
  439. .item {
  440. width: 100%;
  441. background: var(--bs-background-2);
  442. margin-bottom: 8px;
  443. .component-name {
  444. background: var(--bs-el-background-3);
  445. color: var(--bs-el-title);
  446. font-size: 12px;
  447. padding: 4px 8px;
  448. text-align: left;
  449. }
  450. .sampleImg {
  451. margin: 0 auto;
  452. width: 102px;
  453. height: 73px;
  454. display: block;
  455. }
  456. .img_dispaly {
  457. padding: 8px 0;
  458. margin: 0 auto;
  459. text-align: center;
  460. width: 120px;
  461. .icon-svg {
  462. width: 60px !important;
  463. height: 60px !important;
  464. vertical-align: -0.15em;
  465. fill: currentColor;
  466. overflow: hidden;
  467. }
  468. img {
  469. height: 60px;
  470. max-width: 100%;
  471. }
  472. }
  473. }
  474. .menu-component {
  475. .page-opt-list-component {
  476. width: 102px;
  477. height: 75px;
  478. margin: 0 auto;
  479. }
  480. .img_dispaly {
  481. height: 80px;
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. ::v-deep .el-tabs__header {
  489. width: 45px;
  490. height: 100%;
  491. margin-right: 0 !important;
  492. }
  493. ::v-deep .el-tabs--left .el-tabs__nav-wrap.is-left::after {
  494. width: 0 !important;
  495. }
  496. .el-tabs__active-bar {
  497. transform: none !important;
  498. height: 0 !important;
  499. }
  500. .el-tabs__nav-wrap.is-left::after {
  501. left: 0;
  502. }
  503. .el-tabs__nav-wrap {
  504. height: 100%;
  505. /* border-right: 1px solid #ccc; */
  506. }
  507. ::v-deep .el-tabs__nav-scroll {
  508. background-color: var(--bs-background-2);
  509. }
  510. }
  511. .page-left-fold {
  512. width: 45px;
  513. overflow: hidden;
  514. /* border-right: 1px solid #ccc; */
  515. .el-tabs__content {
  516. border: none;
  517. }
  518. }
  519. .left-tabs-box {
  520. ::v-deep .el-tabs__item {
  521. height: 70px !important;
  522. .menu-slot {
  523. height: 100%;
  524. display: flex;
  525. justify-content: center;
  526. align-items: center;
  527. flex-wrap: wrap;
  528. color: #bcc9d4;
  529. .menu-icon {
  530. height: 20px;
  531. }
  532. .menu-title-span {
  533. display: block;
  534. width: 100%;
  535. font-size: 12px;
  536. text-align: center;
  537. }
  538. }
  539. }
  540. }
  541. }
  542. .slide-fade-enter-active {
  543. transition: all 0.3s ease;
  544. }
  545. .slide-fade-leave-active {
  546. transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
  547. }
  548. .slide-fade-enter,
  549. .slide-fade-leave-to
  550. /* .slide-fade-leave-active for below version 2.1.8 */
  551. {
  552. transform: translateX(10px);
  553. opacity: 0;
  554. }
  555. ::v-deep .el-tabs__item.is-left {
  556. text-align: center;
  557. padding: 0;
  558. }
  559. </style>