LeftPanel.vue 14 KB

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