LeftPanel.vue 15 KB

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