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