LeftPanel.vue 15 KB

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