LeftPanel.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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 borderComponents from 'data-room-ui/js/config/borderComponentsConfig'
  153. import decorationComponents from 'data-room-ui/js/config/decorationComponentsConfig'
  154. import LayerList from './LayerList/index.vue'
  155. import { mapMutations } from 'vuex'
  156. import IconSvg from 'data-room-ui/SvgIcon'
  157. export default {
  158. name: 'PageLeftPanel',
  159. components: {
  160. LayerList,
  161. IconSvg
  162. },
  163. props: {
  164. headerShow: {
  165. type: Boolean,
  166. default: true
  167. },
  168. height: {
  169. type: String,
  170. default: '100vh'
  171. }
  172. },
  173. data () {
  174. return {
  175. g2PlotComponents,
  176. activeName: 'chart', // 设置左侧tab栏的默认值
  177. fold: false, // 控制左侧菜单栏伸缩
  178. currentTab: 'basic',
  179. menuList: [
  180. {
  181. id: 1,
  182. name: 'chart',
  183. title: '基础',
  184. icon: 'icon-zujian',
  185. components: basicComponents
  186. },
  187. {
  188. id: 2,
  189. name: 'g2PlotComponents',
  190. title: '图表',
  191. icon: 'icon-jichushuju',
  192. components: this.g2PlotComponents
  193. },
  194. {
  195. id: 3,
  196. name: 'dataV',
  197. title: '边框',
  198. icon: 'icon-border-outer',
  199. components: borderComponents
  200. },
  201. {
  202. id: 4,
  203. name: 'decoration',
  204. title: '装饰',
  205. icon: 'icon-a-1',
  206. components: decorationComponents
  207. },
  208. {
  209. id: 5,
  210. name: 'source',
  211. title: '资源',
  212. icon: 'icon-tupian',
  213. components: []
  214. },
  215. {
  216. id: 6,
  217. name: 'component',
  218. title: '组件',
  219. icon: 'icon-zujian1',
  220. components: ''
  221. }
  222. ],
  223. currentActive: 'chart'
  224. }
  225. },
  226. computed: {
  227. // 获取当前类型的组件
  228. currentComponentList () {
  229. return this.componentList.filter((item) => item.type === this.currentTab)
  230. },
  231. foldText () {
  232. return this.fold ? '展开' : '收起'
  233. }
  234. },
  235. watch: {
  236. fold (isExpand) {
  237. if (isExpand && this.activeName === 'default') {
  238. this.activeName = 'chart'
  239. }
  240. }
  241. },
  242. created () {
  243. this.initList()
  244. this.g2PlotComponents = [...this.g2PlotComponents, ...getCustomPlots()]
  245. this.menuList[1].components = this.g2PlotComponents
  246. },
  247. mounted () {
  248. this.nodeDrag()
  249. },
  250. methods: {
  251. ...mapMutations('bigScreen', ['changeActiveCode']),
  252. nodeDrag () {
  253. this.$nextTick(() => {
  254. const nodes = document.querySelectorAll('.drag-node')
  255. nodes.forEach((node) => {
  256. node.addEventListener('dragstart', (event) => {
  257. const type = node.getAttribute('data-type')
  258. const name = node.getAttribute('data-name')
  259. // 从menuList中获取当前拖拽的组件
  260. const element = this.menuList
  261. .find((item) => item.name === this.activeName)
  262. ?.components.find(
  263. (item) => item.type === type && item.name === name
  264. )
  265. /* 设置拖拽传输数据 */
  266. event.dataTransfer.setData(
  267. 'dragComponent',
  268. JSON.stringify({
  269. ...element,
  270. offsetX: event.offsetX,
  271. offsetY: event.offsetY
  272. })
  273. )
  274. })
  275. })
  276. // 阻止默认动作
  277. document.addEventListener(
  278. 'drop',
  279. (e) => {
  280. e.preventDefault()
  281. },
  282. false
  283. )
  284. })
  285. },
  286. onClone (e) {
  287. return cloneDeep(e)
  288. },
  289. onStart (e) {
  290. // this.$emit('onStart', e)
  291. },
  292. // 拖拽组件时触发
  293. onEnd (e) { },
  294. // 点击左侧组件时触发
  295. addComponent (element) {
  296. this.$store.commit('bigScreen/changeActiveItem', element)
  297. this.$emit('addComponent', element)
  298. },
  299. // 初始化
  300. initList () { },
  301. // 点击tab标签
  302. tabClick (tab) {
  303. this.nodeDrag()
  304. if (tab.index !== '0') {
  305. this.fold = false
  306. this.currentActive = this.activeName
  307. }
  308. if (tab.name === 'source') {
  309. this.fold = true
  310. this.$emit('toggleLeftSidebar')
  311. this.$emit('openResource')
  312. this.$emit('toggleLeftSidebar')
  313. }
  314. if (tab.name === 'component') {
  315. this.fold = true
  316. this.$emit('toggleLeftSidebar')
  317. this.$emit('openComponent')
  318. }
  319. },
  320. toggleSidebar () {
  321. this.fold = !this.fold
  322. this.$emit('toggleLeftSidebar')
  323. setTimeout(() => {
  324. this.activeName = this.currentActive
  325. })
  326. },
  327. openRightPanel (config) {
  328. this.$emit('openRightPanel', config)
  329. }
  330. }
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. @import '../BigScreenDesign/fonts/iconfont.css';
  335. .bs-left-panel {
  336. display: flex;
  337. background-color: var(--bs-background-1);
  338. .bs-folder-wrap {
  339. width: 20px;
  340. position: relative;
  341. i {
  342. position: absolute;
  343. top: 50%;
  344. left: 0;
  345. transform: translateY(-50%);
  346. font-size: 20px;
  347. color: #fff;
  348. cursor: pointer;
  349. z-index: 1;
  350. }
  351. &:hover {
  352. background: rgba(143, 225, 255, 0.1);
  353. }
  354. }
  355. .page-left {
  356. box-sizing: border-box;
  357. >* {
  358. color: #fff;
  359. }
  360. .iconfont-bigscreen {
  361. color: #fff;
  362. }
  363. .flexible {
  364. width: 45px;
  365. /* border-right: 1px solid #ccc; */
  366. text-align: center;
  367. }
  368. .el-tabs {
  369. width: 250;
  370. position: relative;
  371. height: 100% !important;
  372. overflow: visible;
  373. .is-active {
  374. .iconfont-bigscreen {
  375. color: var(--bs-el-color-primary);
  376. }
  377. .menu-title-span {
  378. color: var(--bs-el-color-primary);
  379. }
  380. }
  381. .el-tab-pane {
  382. height: 100%;
  383. }
  384. .page-left-content {
  385. height: 100%;
  386. }
  387. ::v-deep.el-tabs__content {
  388. height: 100%;
  389. width: 160px;
  390. .page-left-content-title {
  391. background-color: var(--bs-background-2);
  392. color: var(--bs-el-title);
  393. font-size: 14px;
  394. margin: 8px;
  395. padding: 8px 0;
  396. .page-left-content-title-text {
  397. /*border-left: 4px solid #007aff;*/
  398. position: relative;
  399. padding-left: 12px;
  400. &:after {
  401. position: absolute;
  402. left: 0;
  403. top: 50%;
  404. transform: translateY(-50%);
  405. content: '';
  406. width: 4px;
  407. height: 14px;
  408. background-color: var(--bs-el-color-primary);
  409. }
  410. }
  411. }
  412. .el-scrollbar__view {
  413. height: calc(100vh - 55px);
  414. }
  415. .page-left-content-components {
  416. width: 100%;
  417. text-align: center;
  418. padding-bottom: 20px;
  419. margin-bottom: 20px;
  420. .draggable {
  421. display: flex;
  422. flex-wrap: wrap;
  423. cursor: pointer;
  424. box-sizing: border-box;
  425. justify-content: center;
  426. padding: 8px;
  427. cursor: move;
  428. .item {
  429. width: 100%;
  430. background: var(--bs-background-2);
  431. margin-bottom: 8px;
  432. .component-name {
  433. background: var(--bs-el-background-3);
  434. color: var(--bs-el-title);
  435. font-size: 12px;
  436. padding: 4px 8px;
  437. text-align: left;
  438. }
  439. .sampleImg {
  440. margin: 0 auto;
  441. width: 102px;
  442. height: 73px;
  443. display: block;
  444. }
  445. .img_dispaly {
  446. padding: 8px 0;
  447. margin: 0 auto;
  448. text-align: center;
  449. width: 120px;
  450. .icon-svg {
  451. width: 60px !important;
  452. height: 60px !important;
  453. vertical-align: -0.15em;
  454. fill: currentColor;
  455. overflow: hidden;
  456. }
  457. img {
  458. height: 60px;
  459. max-width: 100%;
  460. }
  461. }
  462. }
  463. .menu-component {
  464. .page-opt-list-component {
  465. width: 102px;
  466. height: 75px;
  467. margin: 0 auto;
  468. }
  469. .img_dispaly {
  470. height: 80px;
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. ::v-deep.el-tabs__header {
  478. width: 45px;
  479. height: 100%;
  480. margin-right: 0 !important;
  481. }
  482. ::v-deep.el-tabs--left .el-tabs__nav-wrap.is-left::after {
  483. width: 0 !important;
  484. }
  485. .el-tabs__active-bar {
  486. transform: none !important;
  487. height: 0 !important;
  488. }
  489. .el-tabs__nav-wrap.is-left::after {
  490. left: 0;
  491. }
  492. .el-tabs__nav-wrap {
  493. height: 100%;
  494. /* border-right: 1px solid #ccc; */
  495. }
  496. ::v-deep .el-tabs__nav-scroll {
  497. background-color: var(--bs-background-2);
  498. }
  499. }
  500. .page-left-fold {
  501. width: 45px;
  502. overflow: hidden;
  503. /* border-right: 1px solid #ccc; */
  504. .el-tabs__content {
  505. border: none;
  506. }
  507. }
  508. .left-tabs-box {
  509. ::v-deep.el-tabs__item {
  510. height: 70px !important;
  511. .menu-slot {
  512. height: 100%;
  513. display: flex;
  514. justify-content: center;
  515. align-items: center;
  516. flex-wrap: wrap;
  517. color: #bcc9d4;
  518. .menu-icon {
  519. height: 20px;
  520. }
  521. .menu-title-span {
  522. display: block;
  523. width: 100%;
  524. font-size: 12px;
  525. text-align: center;
  526. }
  527. }
  528. }
  529. }
  530. }
  531. .slide-fade-enter-active {
  532. transition: all 0.3s ease;
  533. }
  534. .slide-fade-leave-active {
  535. transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
  536. }
  537. .slide-fade-enter,
  538. .slide-fade-leave-to
  539. /* .slide-fade-leave-active for below version 2.1.8 */
  540. {
  541. transform: translateX(10px);
  542. opacity: 0;
  543. }
  544. ::v-deep .el-tabs__item.is-left {
  545. text-align: center;
  546. padding: 0;
  547. }
  548. </style>