index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <div
  3. v-if="hasPermission"
  4. class="bs-page-design-wrap"
  5. >
  6. <PageTopSetting
  7. v-show="headerShow"
  8. ref="PageTopSetting"
  9. :right-fold="rightVisiable"
  10. @updateRightVisiable="updateRightVisiable"
  11. @showPageInfo="showPageInfo"
  12. @changeZoom="changeScreenZoom"
  13. @empty="empty"
  14. />
  15. <div class="drag-wrap">
  16. <!-- 左侧面板 -->
  17. <LeftPanel
  18. :header-show="headerShow"
  19. :height="height"
  20. @openRightPanel="openRightPanel"
  21. @openResource="initDialog"
  22. @openComponent="openComponent"
  23. @toggleLeftSidebar="toggleLeftSidebar"
  24. />
  25. <!-- 中间组件展示面板 -->
  26. <div
  27. v-loading="pageLoading"
  28. class="grid-wrap-box"
  29. :style="{
  30. height: 'calc(100vh - 48px)'
  31. }"
  32. tabindex="1000"
  33. @keydown="designKeydown"
  34. >
  35. <div
  36. id="minimap"
  37. class="minimap"
  38. >
  39. <div class="mapHeader" id="mapHeader">
  40. <div>
  41. <span>小地图</span>
  42. </div>
  43. <div class="showMap" @click="showMinimap">
  44. <i class="el-icon-arrow-down" style="width:20px;height:20px;color:#fff;" v-if="!mapShow"/>
  45. <i class="el-icon-arrow-up" style="width:20px;height:20px;color:#fff;" v-if="mapShow"/>
  46. </div>
  47. </div>
  48. <div
  49. id="selectWin"
  50. class="selectWin"
  51. v-show="mapShow"
  52. >
  53. <div
  54. id="selectionWin"
  55. class="selectionWin"
  56. />
  57. </div>
  58. </div>
  59. <SketchDesignRuler
  60. ref="Rules"
  61. :width="3000"
  62. :height="3000"
  63. :page-width="pageConfig.w"
  64. :page-height="pageConfig.h"
  65. @changeStart="changeStart"
  66. >
  67. <MouseSelect
  68. :offset-x="offset.x"
  69. :offset-y="offset.y"
  70. @selectArea="onSelectArea"
  71. >
  72. <Render
  73. ref="Render"
  74. :class="{
  75. 'grid-bg': hasGrid
  76. }"
  77. @openRightPanel="openRightPanel"
  78. @openDataViewDialog="openDataViewDialog"
  79. />
  80. </MouseSelect>
  81. </SketchDesignRuler>
  82. <!-- <div class="footer-tools-bar">
  83. <el-slider
  84. class="bs-slider-wrap"
  85. :value="zoom"
  86. :min="10"
  87. style="width: 200px; margin-right: 20px"
  88. @input="changeScreenZoom"
  89. />
  90. <span class="select-zoom-text">缩放比例</span>
  91. <el-select
  92. class="bs-el-select"
  93. popper-class="bs-el-select"
  94. :value="zoom"
  95. @change="changeScreenZoom"
  96. >
  97. <el-option
  98. v-for="(zoom,index) in zoomList"
  99. :key="index"
  100. :label="zoom.label"
  101. :value="zoom.value"
  102. />
  103. </el-select>
  104. </div> -->
  105. </div>
  106. <!-- 右侧折叠设置面板 -->
  107. <SettingPanel
  108. :header-show="headerShow"
  109. :height="height"
  110. :right-visiable.sync="rightVisiable"
  111. :page-info-visiable="pageInfoVisiable"
  112. @updateSetting="updateSetting"
  113. @updateDataSetting="updateDataSetting"
  114. @updatePage="updatePage"
  115. @styleHandler="styleHandler"
  116. >
  117. <template #dataSetSelect="{ value }">
  118. <slot
  119. name="dataSetSelect"
  120. :value="value"
  121. />
  122. </template>
  123. </SettingPanel>
  124. <!-- 添加资源面板 -->
  125. <SourceDialog
  126. ref="SourceDialog"
  127. @getImg="setImg"
  128. />
  129. <ComponentDialog
  130. ref="componentDialog"
  131. @setComponent="setComponent"
  132. @setRemoteComponent="setRemoteComponent"
  133. />
  134. <iframe-dialog
  135. v-if="iframeDialog"
  136. ref="iframeDialog"
  137. />
  138. </div>
  139. <data-view-dialog
  140. ref="dataViewDialog"
  141. />
  142. </div>
  143. <NotPermission v-else-if="!hasPermission" />
  144. </template>
  145. <script>
  146. import SourceDialog from './SourceDialog/index.vue'
  147. import ComponentDialog from './ComponentDialog/index.vue'
  148. import iframeDialog from 'data-room-ui/BasicComponents/LinkChart/iframeDialog'
  149. import {
  150. dataConfig,
  151. settingConfig
  152. } from 'data-room-ui/BasicComponents/Picture/settingConfig'
  153. import LeftPanel from './LeftPanel.vue'
  154. import SettingPanel from './SettingPanel.vue'
  155. import PageTopSetting from './PageDesignTop.vue'
  156. import Render from '../Render'
  157. import { mapActions, mapMutations, mapState } from 'vuex'
  158. import SketchDesignRuler from 'data-room-ui/BigScreenDesign/RulerTool/SketchRuler.vue'
  159. import multipleSelectMixin from 'data-room-ui/js/mixins/multipleSelectMixin'
  160. import { getScreenInfo } from 'data-room-ui/js/api/bigScreenApi'
  161. import plotSettings from 'data-room-ui/G2Plots/settings'
  162. import MouseSelect from './MouseSelect/index.vue'
  163. import cloneDeep from 'lodash/cloneDeep'
  164. import { randomString } from '../js/utils'
  165. import { isFirefox } from 'data-room-ui/js/utils/userAgent'
  166. import { handleResData } from 'data-room-ui/js/store/actions.js'
  167. import { EventBus } from 'data-room-ui/js/utils/eventBus'
  168. import NotPermission from 'data-room-ui/NotPermission'
  169. import DataViewDialog from 'data-room-ui/BigScreenDesign/DataViewDialog'
  170. export default {
  171. name: 'BigScreenDesign',
  172. components: {
  173. PageTopSetting,
  174. LeftPanel,
  175. Render,
  176. SketchDesignRuler,
  177. MouseSelect,
  178. SettingPanel,
  179. SourceDialog,
  180. ComponentDialog,
  181. iframeDialog,
  182. NotPermission,
  183. DataViewDialog
  184. },
  185. mixins: [multipleSelectMixin],
  186. props: {
  187. code: {
  188. type: String,
  189. default: ''
  190. },
  191. headerShow: {
  192. type: Boolean,
  193. default: true
  194. },
  195. height: {
  196. type: String,
  197. default: 'calc(100vh - 40px)'
  198. }
  199. },
  200. data () {
  201. return {
  202. mapShow: true, // 小地图显示与否
  203. hasPermission: true,
  204. rightVisiable: false,
  205. pageInfoVisiable: false,
  206. ruleStartX: 100,
  207. ruleStartY: 100,
  208. zoomList: [
  209. {
  210. label: '自适应',
  211. value: 'auto'
  212. },
  213. {
  214. label: '100%',
  215. value: 100
  216. },
  217. {
  218. label: '80%',
  219. value: 80
  220. },
  221. {
  222. label: '50%',
  223. value: 50
  224. },
  225. {
  226. label: '20%',
  227. value: 20
  228. }
  229. ]
  230. }
  231. },
  232. watch: {
  233. chartList (val) {
  234. // if(val.findIndex(item=>item.code==this.activeCode)==-1){
  235. // this.updateRightVisiable(false)
  236. // }
  237. // if(val.length==0){
  238. // this.updateRightVisiable(false)
  239. // }
  240. },
  241. mapShow (value) {
  242. const mapElement = document.getElementById('minimap')
  243. // const selectElement = document.getElementById('selectWin')
  244. if (!value) {
  245. mapElement.style.bottom = parseFloat(window.getComputedStyle(mapElement).bottom) + 150 + 'px'
  246. } else {
  247. this.$refs.Rules.handleScroll()
  248. mapElement.style.bottom = parseFloat(window.getComputedStyle(mapElement).bottom) - 150 + 'px'
  249. }
  250. },
  251. fitZoom (zoom) {
  252. this.zoomList[0] = {
  253. label: `自适应(${zoom}%)`,
  254. value: zoom
  255. }
  256. }
  257. },
  258. computed: {
  259. ...mapState({
  260. pageInfo: (state) => state.bigScreen.pageInfo,
  261. chartList: (state) => state.bigScreen.pageInfo.chartList,
  262. pageConfig: (state) => state.bigScreen.pageInfo.pageConfig,
  263. pageLoading: (state) => state.bigScreen.pageLoading,
  264. hoverCode: (state) => state.bigScreen.hoverCode,
  265. presetLine: (state) => state.bigScreen.presetLine,
  266. updateKey: (state) => state.bigScreen.updateKey,
  267. hasGrid: (state) => state.bigScreen.hasGrid,
  268. zoom: (state) => state.bigScreen.zoom,
  269. fitZoom: (state) => state.bigScreen.fitZoom,
  270. iframeDialog: (state) => state.bigScreen.iframeDialog,
  271. activeCode: state => state.bigScreen.activeCode
  272. }),
  273. pageCode () {
  274. return this.code || this.$route.query.code
  275. },
  276. offset () {
  277. return {
  278. x: 220 + 50 - this.ruleStartX,
  279. y: 55 + 50 - this.ruleStartY
  280. }
  281. }
  282. },
  283. created () {
  284. this.changePageLoading(true)
  285. this.permission()
  286. /**
  287. * 以下是为了解决在火狐浏览器上推拽时弹出tab页到搜索问题
  288. * @param event
  289. */
  290. if (isFirefox()) {
  291. document.body.ondrop = function (event) {
  292. event.preventDefault()
  293. event.stopPropagation()
  294. }
  295. }
  296. },
  297. mounted () {
  298. EventBus.$on('closeRightPanel', () => {
  299. this.updateRightVisiable(false)
  300. })
  301. },
  302. beforeDestroy () {
  303. this.clearTimeline()
  304. EventBus.$off('closeRightPanel')
  305. },
  306. methods: {
  307. ...mapActions('bigScreen', ['initLayout']),
  308. ...mapMutations('bigScreen', [
  309. 'changeLayout',
  310. 'changePageLoading',
  311. 'resetPresetLine',
  312. 'changeActiveCode',
  313. 'changeActiveCodes',
  314. 'changePageConfig',
  315. 'changeChartConfig',
  316. 'changeChartKey',
  317. 'changeZoom',
  318. 'clearTimeline',
  319. 'saveTimeLine',
  320. 'changeIframeDialog',
  321. 'changePageInfo',
  322. 'changeActiveItemConfig',
  323. 'emptyDataset',
  324. 'emptyComputedDatas'
  325. ]),
  326. // 控制小地图显示与隐藏
  327. showMinimap () {
  328. this.mapShow = !this.mapShow
  329. },
  330. // 判断页面权限
  331. permission () {
  332. this.$dataRoomAxios.get(`/bigScreen/permission/check/${this.pageCode}`).then(res => {
  333. this.hasPermission = res
  334. if (res) {
  335. this.init()
  336. }
  337. })
  338. },
  339. // 添加资源弹窗初始化
  340. initDialog () {
  341. this.$refs.SourceDialog.init()
  342. },
  343. openComponent () {
  344. this.$refs.componentDialog.init()
  345. },
  346. // 从组件库添加组件模板到当前画布
  347. setComponent (component) {
  348. // 根据component获取页面详情
  349. getScreenInfo(component.code).then(res => {
  350. res.chartList.forEach((item) => {
  351. if (!item.border) {
  352. item.border = { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [0, 0, 0, 0] }
  353. }
  354. if (!item.border.padding) {
  355. item.border.padding = [0, 0, 0, 0]
  356. }
  357. if (item.type == 'customComponent') {
  358. plotSettings[Symbol.iterator] = function * () {
  359. const keys = Object.keys(plotSettings)
  360. for (const k of keys) {
  361. yield [k, plotSettings[k]]
  362. }
  363. }
  364. for (const [key, value] of plotSettings) {
  365. if (item.name == value.name) {
  366. const settings = JSON.parse(JSON.stringify(value.setting))
  367. item.setting = settings.map((x) => {
  368. const index = item.setting.findIndex(y => y.field == x.field)
  369. x.field = item.setting[index].field
  370. x.value = item.setting[index].value
  371. return x
  372. })
  373. }
  374. }
  375. }
  376. })
  377. // 给组件库导入的组件加入统一的前缀
  378. const randomStr = randomString(8)
  379. const pageInfo = handleResData(res)
  380. const chartList = pageInfo.chartList.reverse()
  381. chartList.forEach((chart) => {
  382. // 如果组件存在数据联动,则将数据联动的code也加上相同的前缀
  383. if (chart.linkage && chart.linkage.components && chart.linkage.components.length) {
  384. chart.linkage.components.forEach((com) => { com.componentKey = randomStr + com.componentKey })
  385. }
  386. const newChart = {
  387. ...chart,
  388. offsetX: 0,
  389. group: randomStr,
  390. code: randomStr + chart.code
  391. }
  392. // 如果是从组件库中添加的自定义组件,则不需要初始化theme
  393. const isComponent = true
  394. this.$refs.Render.addChart(newChart, { x: chart.x, y: chart.y }, isComponent)
  395. this.updateRightVisiable(false)
  396. })
  397. })
  398. },
  399. // 添加远程组件
  400. setRemoteComponent (component) {
  401. const newChart = {
  402. ...component,
  403. offsetX: 0,
  404. offsetY: 0,
  405. code: randomString(8)
  406. }
  407. this.$refs.Render.addChart(newChart, { x: 0, y: 0 })
  408. },
  409. setImg (val) {
  410. this.$refs.Render.addSourceChart(
  411. JSON.stringify({
  412. title: val.originalName,
  413. name: val.originalName,
  414. icon: null,
  415. className:
  416. 'com.gccloud.dataroom.core.module.chart.components.ScreenPictureChart',
  417. w: 300,
  418. h: 300,
  419. x: 0,
  420. y: 0,
  421. type: 'picture',
  422. option: {
  423. ...cloneDeep(settingConfig)
  424. },
  425. setting: {}, // 右侧面板自定义配置
  426. dataHandler: {}, // 数据自定义处理js脚本
  427. ...cloneDeep(dataConfig),
  428. customize: {
  429. url: val.url,
  430. radius: 0,
  431. opacity: 100
  432. }
  433. }),
  434. { x: 150, y: 100 }
  435. )
  436. },
  437. init () {
  438. this.changePageLoading(true)
  439. this.initLayout(this.pageCode)
  440. .then(() => {
  441. this.changePageLoading(false)
  442. })
  443. .finally(() => {
  444. setTimeout(() => {
  445. this.resetPresetLine()
  446. }, 500)
  447. })
  448. },
  449. // 点击当前组件时打开右侧面板
  450. openRightPanel (card) {
  451. this.rightVisiable = true
  452. this.pageInfoVisiable = false
  453. this.$refs.Rules.initRuleHeight()
  454. },
  455. openDataViewDialog (config) {
  456. this.$refs.dataViewDialog.init(config)
  457. },
  458. /**
  459. * @description: 清空页面
  460. */
  461. empty () {
  462. this.$confirm('确定清空页面吗?', '提示', {
  463. confirmButtonText: '确定',
  464. cancelButtonText: '取消',
  465. type: 'warning',
  466. customClass: 'bs-el-message-box'
  467. })
  468. .then(() => {
  469. this.changeLayout([])
  470. // 清空缓存的数据库的内容
  471. this.emptyDataset()
  472. this.emptyComputedDatas()
  473. this.resetPresetLine()
  474. this.saveTimeLine('清空画布')
  475. })
  476. .catch(() => {})
  477. },
  478. // 切换主题时针对远程组件触发样式修改的方法
  479. styleHandler (config) {
  480. this.$nextTick(() => {
  481. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  482. config.code
  483. ]?.changeStyle(cloneDeep(config), true)
  484. })
  485. },
  486. // 自定义属性更新
  487. updateSetting (config) {
  488. if (config.type === 'map' || config.type === 'screenScrollBoard' || config.type === 'remoteComponent' || config.type === 'video' || config.type === 'flyMap') {
  489. config.key = new Date().getTime()
  490. }
  491. this.changeChartConfig(cloneDeep(config))
  492. // 如果是tab内的组件
  493. if (config.parentCode) {
  494. const dom = this.$refs.Render?.$refs['RenderCard' + config.parentCode][0]?.$refs[config.parentCode]?.$refs['RenderCard' + config.code]?.$refs[config.code]
  495. if (dom) {
  496. dom?.changeStyle(cloneDeep(config))
  497. }
  498. } else {
  499. if (this.$refs.Render?.$refs['RenderCard' + config.code]) {
  500. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  501. config.code
  502. ]?.changeStyle(cloneDeep(config))
  503. }
  504. }
  505. },
  506. // 动态属性更新
  507. updateDataSetting (config) {
  508. config.key = new Date().getTime()
  509. this.changeChartConfig(config)
  510. },
  511. onSelectArea (area) {
  512. const { startX, startY, endX, endY } = area
  513. // 计算所有在此区域中的组件,如果在此区域中,将其code添加到activeCodes数组中
  514. const activeCodes = this.chartList
  515. ?.filter((chart) => {
  516. const { x, y, w, h } = chart
  517. return startX - 50 <= x && x + w <= endX && startY - 50 <= y && y + h <= endY
  518. })
  519. ?.map((chart) => chart.code)
  520. this.changeActiveCodes(activeCodes)
  521. },
  522. changeStart ({ x, y }) {
  523. this.ruleStartX = x
  524. this.ruleStartY = y
  525. },
  526. // 保存并预览
  527. saveAndPreview () {
  528. this.$refs.PageTopSetting.execRun()
  529. },
  530. // 保存
  531. save () {
  532. this.$refs.PageTopSetting.save('saveLoading')
  533. },
  534. changeScreenZoom (zoom) {
  535. // 自适应
  536. if (zoom === 'auto') {
  537. this.$refs.Rules.initZoom()
  538. } else {
  539. this.changeZoom(zoom)
  540. }
  541. },
  542. updateRightVisiable (visiable) {
  543. this.rightVisiable = visiable
  544. this.$refs.Rules.initRuleHeight()
  545. },
  546. toggleLeftSidebar () {
  547. this.$refs.Rules.initRuleHeight()
  548. },
  549. showPageInfo () {
  550. this.pageInfoVisiable = true
  551. this.rightVisiable = true
  552. this.changeActiveCode('')
  553. },
  554. // 页面信息更改
  555. updatePage () {
  556. this.$refs.Rules.initZoom()
  557. }
  558. }
  559. }
  560. </script>
  561. <style lang="scss" scoped>
  562. .bs-page-design-wrap {
  563. overflow: hidden;
  564. .drag-wrap {
  565. display: flex;
  566. background-color: #1d1e20;
  567. height: calc(100vh - 40px);
  568. // overflow: hidden;
  569. .grid-wrap-box {
  570. flex: 1;
  571. // overflow: hidden;
  572. position: relative;
  573. margin: 8px 0 0 8px;
  574. .footer-tools-bar {
  575. position: absolute;
  576. bottom: 0;
  577. width: 100%;
  578. height: 30px;
  579. display: flex;
  580. justify-content: flex-end;
  581. align-items: center;
  582. z-index: 1000;
  583. background-color: var(--bs-background-2);
  584. .bs-select-wrap {
  585. margin-right: 16px;
  586. }
  587. .select-zoom-text {
  588. color: var(--bs-el-title);
  589. margin-right: 16px;
  590. }
  591. ::v-deep .el-select {
  592. width: 150px !important;
  593. }
  594. }
  595. }
  596. ::v-deep .el-loading-mask {
  597. background-color: transparent !important;
  598. }
  599. }
  600. }
  601. .minimap{
  602. position: absolute ;
  603. bottom: 20px;
  604. right: 20px;
  605. z-index:1000;
  606. }
  607. .minimap .mapHeader{
  608. background-color:#303640;
  609. box-sizing:border-box;
  610. padding: 0 10px;
  611. display: flex;
  612. justify-content: space-between;
  613. align-items: center;
  614. height: 30px;
  615. width: 150px;
  616. font-size: 12px;
  617. color: var(--bs-el-title);
  618. cursor: pointer;
  619. span {
  620. user-select: none;
  621. }
  622. }
  623. .minimap .selectWin{
  624. background-color: #232832;
  625. height: 150px;
  626. width: 150px;
  627. position: relative;
  628. }
  629. .minimap .selectionWin{
  630. position: absolute;
  631. left: 0px;
  632. top: 0px;
  633. width: 30px;
  634. height: 30px;
  635. background-color: white;
  636. opacity: 0.5;
  637. cursor: move;
  638. }
  639. </style>