index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. mapElement.style.bottom = parseFloat(window.getComputedStyle(mapElement).bottom) - 150 + 'px'
  248. }
  249. },
  250. fitZoom (zoom) {
  251. this.zoomList[0] = {
  252. label: `自适应(${zoom}%)`,
  253. value: zoom
  254. }
  255. }
  256. },
  257. computed: {
  258. ...mapState({
  259. pageInfo: (state) => state.bigScreen.pageInfo,
  260. chartList: (state) => state.bigScreen.pageInfo.chartList,
  261. pageConfig: (state) => state.bigScreen.pageInfo.pageConfig,
  262. pageLoading: (state) => state.bigScreen.pageLoading,
  263. hoverCode: (state) => state.bigScreen.hoverCode,
  264. presetLine: (state) => state.bigScreen.presetLine,
  265. updateKey: (state) => state.bigScreen.updateKey,
  266. hasGrid: (state) => state.bigScreen.hasGrid,
  267. zoom: (state) => state.bigScreen.zoom,
  268. fitZoom: (state) => state.bigScreen.fitZoom,
  269. iframeDialog: (state) => state.bigScreen.iframeDialog,
  270. activeCode: state => state.bigScreen.activeCode
  271. }),
  272. pageCode () {
  273. return this.code || this.$route.query.code
  274. },
  275. offset () {
  276. return {
  277. x: 220 + 50 - this.ruleStartX,
  278. y: 55 + 50 - this.ruleStartY
  279. }
  280. }
  281. },
  282. created () {
  283. this.changePageLoading(true)
  284. this.permission()
  285. /**
  286. * 以下是为了解决在火狐浏览器上推拽时弹出tab页到搜索问题
  287. * @param event
  288. */
  289. if (isFirefox()) {
  290. document.body.ondrop = function (event) {
  291. event.preventDefault()
  292. event.stopPropagation()
  293. }
  294. }
  295. },
  296. mounted () {
  297. EventBus.$on('closeRightPanel', () => {
  298. this.updateRightVisiable(false)
  299. })
  300. },
  301. beforeDestroy () {
  302. this.clearTimeline()
  303. EventBus.$off('closeRightPanel')
  304. },
  305. methods: {
  306. ...mapActions('bigScreen', ['initLayout']),
  307. ...mapMutations('bigScreen', [
  308. 'changeLayout',
  309. 'changePageLoading',
  310. 'resetPresetLine',
  311. 'changeActiveCode',
  312. 'changeActiveCodes',
  313. 'changePageConfig',
  314. 'changeChartConfig',
  315. 'changeChartKey',
  316. 'changeZoom',
  317. 'clearTimeline',
  318. 'saveTimeLine',
  319. 'changeIframeDialog',
  320. 'changePageInfo',
  321. 'changeActiveItemConfig',
  322. 'emptyDataset',
  323. 'emptyComputedDatas'
  324. ]),
  325. // 控制小地图显示与隐藏
  326. showMinimap () {
  327. this.mapShow = !this.mapShow
  328. },
  329. // 判断页面权限
  330. permission () {
  331. this.$dataRoomAxios.get(`/bigScreen/permission/check/${this.pageCode}`).then(res => {
  332. this.hasPermission = res
  333. if (res) {
  334. this.init()
  335. }
  336. })
  337. },
  338. // 添加资源弹窗初始化
  339. initDialog () {
  340. this.$refs.SourceDialog.init()
  341. },
  342. openComponent () {
  343. this.$refs.componentDialog.init()
  344. },
  345. // 从组件库添加组件模板到当前画布
  346. setComponent (component) {
  347. // 根据component获取页面详情
  348. getScreenInfo(component.code).then(res => {
  349. res.chartList.forEach((item) => {
  350. if (!item.border) {
  351. item.border = { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [0, 0, 0, 0] }
  352. }
  353. if (!item.border.padding) {
  354. item.border.padding = [0, 0, 0, 0]
  355. }
  356. if (item.type == 'customComponent') {
  357. plotSettings[Symbol.iterator] = function * () {
  358. const keys = Object.keys(plotSettings)
  359. for (const k of keys) {
  360. yield [k, plotSettings[k]]
  361. }
  362. }
  363. for (const [key, value] of plotSettings) {
  364. if (item.name == value.name) {
  365. const settings = JSON.parse(JSON.stringify(value.setting))
  366. item.setting = settings.map((x) => {
  367. const index = item.setting.findIndex(y => y.field == x.field)
  368. x.field = item.setting[index].field
  369. x.value = item.setting[index].value
  370. return x
  371. })
  372. }
  373. }
  374. }
  375. })
  376. // 给组件库导入的组件加入统一的前缀
  377. const randomStr = randomString(8)
  378. const pageInfo = handleResData(res)
  379. const chartList = pageInfo.chartList.reverse()
  380. chartList.forEach((chart) => {
  381. // 如果组件存在数据联动,则将数据联动的code也加上相同的前缀
  382. if (chart.linkage && chart.linkage.components && chart.linkage.components.length) {
  383. chart.linkage.components.forEach((com) => { com.componentKey = randomStr + com.componentKey })
  384. }
  385. const newChart = {
  386. ...chart,
  387. offsetX: 0,
  388. group: randomStr,
  389. code: randomStr + chart.code
  390. }
  391. // 如果是从组件库中添加的自定义组件,则不需要初始化theme
  392. const isComponent = true
  393. this.$refs.Render.addChart(newChart, { x: chart.x, y: chart.y }, isComponent)
  394. this.updateRightVisiable(false)
  395. })
  396. })
  397. },
  398. // 添加远程组件
  399. setRemoteComponent (component) {
  400. const newChart = {
  401. ...component,
  402. offsetX: 0,
  403. offsetY: 0,
  404. code: randomString(8)
  405. }
  406. this.$refs.Render.addChart(newChart, { x: 0, y: 0 })
  407. },
  408. setImg (val) {
  409. this.$refs.Render.addSourceChart(
  410. JSON.stringify({
  411. title: val.originalName,
  412. name: val.originalName,
  413. icon: null,
  414. className:
  415. 'com.gccloud.dataroom.core.module.chart.components.ScreenPictureChart',
  416. w: 300,
  417. h: 300,
  418. x: 0,
  419. y: 0,
  420. type: 'picture',
  421. option: {
  422. ...cloneDeep(settingConfig)
  423. },
  424. setting: {}, // 右侧面板自定义配置
  425. dataHandler: {}, // 数据自定义处理js脚本
  426. ...cloneDeep(dataConfig),
  427. customize: {
  428. url: val.url,
  429. radius: 0,
  430. opacity: 100
  431. }
  432. }),
  433. { x: 150, y: 100 }
  434. )
  435. },
  436. init () {
  437. this.changePageLoading(true)
  438. this.initLayout(this.pageCode)
  439. .then(() => {
  440. this.changePageLoading(false)
  441. })
  442. .finally(() => {
  443. setTimeout(() => {
  444. this.resetPresetLine()
  445. }, 500)
  446. })
  447. },
  448. // 点击当前组件时打开右侧面板
  449. openRightPanel (card) {
  450. this.rightVisiable = true
  451. this.pageInfoVisiable = false
  452. this.$refs.Rules.initRuleHeight()
  453. },
  454. openDataViewDialog (config) {
  455. this.$refs.dataViewDialog.init(config)
  456. },
  457. /**
  458. * @description: 清空页面
  459. */
  460. empty () {
  461. this.$confirm('确定清空页面吗?', '提示', {
  462. confirmButtonText: '确定',
  463. cancelButtonText: '取消',
  464. type: 'warning',
  465. customClass: 'bs-el-message-box'
  466. })
  467. .then(() => {
  468. this.changeLayout([])
  469. // 清空缓存的数据库的内容
  470. this.emptyDataset()
  471. this.emptyComputedDatas()
  472. this.resetPresetLine()
  473. this.saveTimeLine('清空画布')
  474. })
  475. .catch(() => {})
  476. },
  477. // 切换主题时针对远程组件触发样式修改的方法
  478. styleHandler (config) {
  479. this.$nextTick(() => {
  480. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  481. config.code
  482. ]?.changeStyle(cloneDeep(config), true)
  483. })
  484. },
  485. // 自定义属性更新
  486. updateSetting (config) {
  487. if (config.type === 'map' || config.type === 'screenScrollBoard' || config.type === 'remoteComponent' || config.type === 'video' || config.type === 'flyMap') {
  488. config.key = new Date().getTime()
  489. }
  490. this.changeChartConfig(cloneDeep(config))
  491. // 如果是tab内的组件
  492. if (config.parentCode) {
  493. const dom = this.$refs.Render?.$refs['RenderCard' + config.parentCode][0]?.$refs[config.parentCode]?.$refs['RenderCard' + config.code]?.$refs[config.code]
  494. if (dom) {
  495. dom?.changeStyle(cloneDeep(config))
  496. }
  497. } else {
  498. if (this.$refs.Render?.$refs['RenderCard' + config.code]) {
  499. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  500. config.code
  501. ]?.changeStyle(cloneDeep(config))
  502. }
  503. }
  504. },
  505. // 动态属性更新
  506. updateDataSetting (config) {
  507. config.key = new Date().getTime()
  508. this.changeChartConfig(config)
  509. },
  510. onSelectArea (area) {
  511. const { startX, startY, endX, endY } = area
  512. // 计算所有在此区域中的组件,如果在此区域中,将其code添加到activeCodes数组中
  513. const activeCodes = this.chartList
  514. ?.filter((chart) => {
  515. const { x, y, w, h } = chart
  516. return startX - 50 <= x && x + w <= endX && startY - 50 <= y && y + h <= endY
  517. })
  518. ?.map((chart) => chart.code)
  519. this.changeActiveCodes(activeCodes)
  520. },
  521. changeStart ({ x, y }) {
  522. this.ruleStartX = x
  523. this.ruleStartY = y
  524. },
  525. // 保存并预览
  526. saveAndPreview () {
  527. this.$refs.PageTopSetting.execRun()
  528. },
  529. // 保存
  530. save () {
  531. this.$refs.PageTopSetting.save('saveLoading')
  532. },
  533. changeScreenZoom (zoom) {
  534. // 自适应
  535. if (zoom === 'auto') {
  536. this.$refs.Rules.initZoom()
  537. } else {
  538. this.changeZoom(zoom)
  539. }
  540. },
  541. updateRightVisiable (visiable) {
  542. this.rightVisiable = visiable
  543. this.$refs.Rules.initRuleHeight()
  544. },
  545. toggleLeftSidebar () {
  546. this.$refs.Rules.initRuleHeight()
  547. },
  548. showPageInfo () {
  549. this.pageInfoVisiable = true
  550. this.rightVisiable = true
  551. this.changeActiveCode('')
  552. },
  553. // 页面信息更改
  554. updatePage () {
  555. this.$refs.Rules.initZoom()
  556. }
  557. }
  558. }
  559. </script>
  560. <style lang="scss" scoped>
  561. .bs-page-design-wrap {
  562. overflow: hidden;
  563. .drag-wrap {
  564. display: flex;
  565. background-color: #1d1e20;
  566. height: calc(100vh - 40px);
  567. // overflow: hidden;
  568. .grid-wrap-box {
  569. flex: 1;
  570. // overflow: hidden;
  571. position: relative;
  572. margin: 8px 0 0 8px;
  573. .footer-tools-bar {
  574. position: absolute;
  575. bottom: 0;
  576. width: 100%;
  577. height: 30px;
  578. display: flex;
  579. justify-content: flex-end;
  580. align-items: center;
  581. z-index: 1000;
  582. background-color: var(--bs-background-2);
  583. .bs-select-wrap {
  584. margin-right: 16px;
  585. }
  586. .select-zoom-text {
  587. color: var(--bs-el-title);
  588. margin-right: 16px;
  589. }
  590. ::v-deep .el-select {
  591. width: 150px !important;
  592. }
  593. }
  594. }
  595. ::v-deep .el-loading-mask {
  596. background-color: transparent !important;
  597. }
  598. }
  599. }
  600. .minimap{
  601. position: absolute ;
  602. bottom: 20px;
  603. right: 20px;
  604. z-index:1000;
  605. }
  606. .minimap .mapHeader{
  607. background-color:#303640;
  608. box-sizing:border-box;
  609. padding: 0 10px;
  610. display: flex;
  611. justify-content: space-between;
  612. align-items: center;
  613. height: 30px;
  614. width: 150px;
  615. font-size: 12px;
  616. color: var(--bs-el-title);
  617. cursor: pointer;
  618. span {
  619. user-select: none;
  620. }
  621. }
  622. .minimap .selectWin{
  623. background-color: #232832;
  624. height: 150px;
  625. width: 150px;
  626. position: relative;
  627. }
  628. .minimap .selectionWin{
  629. position: absolute;
  630. left: 0px;
  631. top: 0px;
  632. width: 30px;
  633. height: 30px;
  634. background-color: white;
  635. opacity: 0.5;
  636. cursor: move;
  637. }
  638. </style>