index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. @empty="empty"
  13. />
  14. <div class="drag-wrap">
  15. <!-- 左侧面板 -->
  16. <LeftPanel
  17. :header-show="headerShow"
  18. :height="height"
  19. @openRightPanel="openRightPanel"
  20. @openResource="initDialog"
  21. @openComponent="openComponent"
  22. @toggleLeftSidebar="toggleLeftSidebar"
  23. />
  24. <!-- 中间组件展示面板 -->
  25. <div
  26. v-loading="pageLoading"
  27. class="grid-wrap-box"
  28. :style="{
  29. height: 'calc(100vh - 48px)'
  30. }"
  31. tabindex="1000"
  32. @keydown="designKeydown"
  33. >
  34. <SketchDesignRuler
  35. ref="Rules"
  36. :width="3000"
  37. :height="3000"
  38. :page-width="pageConfig.w"
  39. :page-height="pageConfig.h"
  40. @changeStart="changeStart"
  41. >
  42. <MouseSelect
  43. :offset-x="offset.x"
  44. :offset-y="offset.y"
  45. @selectArea="onSelectArea"
  46. >
  47. <Render
  48. ref="Render"
  49. :class="{
  50. 'grid-bg': hasGrid
  51. }"
  52. @openRightPanel="openRightPanel"
  53. />
  54. </MouseSelect>
  55. </SketchDesignRuler>
  56. <div class="footer-tools-bar">
  57. <el-slider
  58. class="bs-slider-wrap"
  59. :value="zoom"
  60. :min="10"
  61. style="width: 200px; margin-right: 20px"
  62. @input="changeScreenZoom"
  63. />
  64. <span class="select-zoom-text">缩放比例</span>
  65. <el-select
  66. class="bs-el-select"
  67. popper-class="bs-el-select"
  68. :value="zoom"
  69. @change="changeScreenZoom"
  70. >
  71. <el-option
  72. v-for="(zoom,index) in zoomList"
  73. :key="index"
  74. :label="zoom.label"
  75. :value="zoom.value"
  76. />
  77. </el-select>
  78. </div>
  79. </div>
  80. <!-- 右侧折叠设置面板 -->
  81. <SettingPanel
  82. :header-show="headerShow"
  83. :height="height"
  84. :right-visiable.sync="rightVisiable"
  85. :page-info-visiable="pageInfoVisiable"
  86. @updateSetting="updateSetting"
  87. @updateDataSetting="updateDataSetting"
  88. @updatePage="updatePage"
  89. >
  90. <template #dataSetSelect="{ value }">
  91. <slot
  92. name="dataSetSelect"
  93. :value="value"
  94. />
  95. </template>
  96. </SettingPanel>
  97. <!-- 添加资源面板 -->
  98. <SourceDialog
  99. ref="SourceDialog"
  100. @getImg="setImg"
  101. />
  102. <ComponentDialog
  103. ref="componentDialog"
  104. @setComponent="setComponent"
  105. @setRemoteComponent="setRemoteComponent"
  106. />
  107. <iframe-dialog
  108. v-if="iframeDialog"
  109. ref="iframeDialog"
  110. />
  111. </div>
  112. </div>
  113. <NotPermission v-else-if="!hasPermission" />
  114. </template>
  115. <script>
  116. import SourceDialog from './SourceDialog/index.vue'
  117. import ComponentDialog from './ComponentDialog/index.vue'
  118. import iframeDialog from 'data-room-ui/BasicComponents/LinkChart/iframeDialog'
  119. import {
  120. dataConfig,
  121. settingConfig
  122. } from 'data-room-ui/BasicComponents/Picture/settingConfig'
  123. import LeftPanel from './LeftPanel.vue'
  124. import SettingPanel from './SettingPanel.vue'
  125. import PageTopSetting from './PageDesignTop.vue'
  126. import Render from '../Render'
  127. import { mapActions, mapMutations, mapState } from 'vuex'
  128. import SketchDesignRuler from 'data-room-ui/BigScreenDesign/RulerTool/SketchRuler.vue'
  129. import { G2 } from '@antv/g2plot'
  130. import multipleSelectMixin from 'data-room-ui/js/mixins/multipleSelectMixin'
  131. import { getThemeConfig, getScreenInfo } from 'data-room-ui/js/api/bigScreenApi'
  132. import MouseSelect from './MouseSelect/index.vue'
  133. import cloneDeep from 'lodash/cloneDeep'
  134. import { randomString } from '../js/utils'
  135. import { isFirefox } from 'data-room-ui/js/utils/userAgent'
  136. import { handleResData } from 'data-room-ui/js/store/actions.js'
  137. import { EventBus } from 'data-room-ui/js/utils/eventBus'
  138. import NotPermission from 'data-room-ui/NotPermission'
  139. export default {
  140. name: 'BigScreenDesign',
  141. components: {
  142. PageTopSetting,
  143. LeftPanel,
  144. Render,
  145. SketchDesignRuler,
  146. MouseSelect,
  147. SettingPanel,
  148. SourceDialog,
  149. ComponentDialog,
  150. iframeDialog,
  151. NotPermission
  152. },
  153. mixins: [multipleSelectMixin],
  154. props: {
  155. code: {
  156. type: String,
  157. default: ''
  158. },
  159. headerShow: {
  160. type: Boolean,
  161. default: true
  162. },
  163. height: {
  164. type: String,
  165. default: 'calc(100vh - 40px)'
  166. }
  167. },
  168. data () {
  169. return {
  170. hasPermission: true,
  171. rightVisiable: false,
  172. pageInfoVisiable: false,
  173. ruleStartX: 100,
  174. ruleStartY: 100,
  175. zoomList: [
  176. {
  177. label: '自适应',
  178. value: 'auto'
  179. },
  180. {
  181. label: '100%',
  182. value: 100
  183. },
  184. {
  185. label: '80%',
  186. value: 80
  187. },
  188. {
  189. label: '50%',
  190. value: 50
  191. },
  192. {
  193. label: '20%',
  194. value: 20
  195. }
  196. ]
  197. }
  198. },
  199. watch: {
  200. fitZoom (zoom) {
  201. this.zoomList[0] = {
  202. label: `自适应(${zoom}%)`,
  203. value: zoom
  204. }
  205. }
  206. },
  207. computed: {
  208. ...mapState({
  209. pageInfo: (state) => state.bigScreen.pageInfo,
  210. chartList: (state) => state.bigScreen.pageInfo.chartList,
  211. pageConfig: (state) => state.bigScreen.pageInfo.pageConfig,
  212. pageLoading: (state) => state.bigScreen.pageLoading,
  213. hoverCode: (state) => state.bigScreen.hoverCode,
  214. presetLine: (state) => state.bigScreen.presetLine,
  215. updateKey: (state) => state.bigScreen.updateKey,
  216. hasGrid: (state) => state.bigScreen.hasGrid,
  217. zoom: (state) => state.bigScreen.zoom,
  218. fitZoom: (state) => state.bigScreen.fitZoom,
  219. iframeDialog: (state) => state.bigScreen.iframeDialog,
  220. activeCode: state => state.bigScreen.activeCode
  221. }),
  222. pageCode () {
  223. return this.code || this.$route.query.code
  224. },
  225. offset () {
  226. return {
  227. x: 220 + 50 - this.ruleStartX,
  228. y: 55 + 50 - this.ruleStartY
  229. }
  230. }
  231. },
  232. // beforeRouteEnter (to, from, next) {
  233. // // 判断进入设计页面前是否有访问权限
  234. // const code = to.query.code
  235. // get(`/bigScreen/permission/check/${code}`).then((res) => {
  236. // if (res) {
  237. // next((vm) => {
  238. // // 重置大屏的vuex store
  239. // vm.$store.commit('bigScreen/resetStoreData')
  240. // })
  241. // } else {
  242. // next('/notPermission')
  243. // }
  244. // })
  245. // },
  246. created () {
  247. this.changePageLoading(true)
  248. this.permission()
  249. /**
  250. * 以下是为了解决在火狐浏览器上推拽时弹出tab页到搜索问题
  251. * @param event
  252. */
  253. if (isFirefox()) {
  254. document.body.ondrop = function (event) {
  255. event.preventDefault()
  256. event.stopPropagation()
  257. }
  258. }
  259. },
  260. mounted () {
  261. EventBus.$on('closeRightPanel', () => { this.rightVisiable = false })
  262. },
  263. beforeDestroy () {
  264. this.clearTimeline()
  265. EventBus.$off('closeRightPanel')
  266. },
  267. methods: {
  268. ...mapActions('bigScreen', ['initLayout']),
  269. ...mapMutations('bigScreen', [
  270. 'changeLayout',
  271. 'changePageLoading',
  272. 'resetPresetLine',
  273. 'changeActiveCode',
  274. 'changeActiveCodes',
  275. 'changePageConfig',
  276. 'changeChartConfig',
  277. 'changeChartKey',
  278. 'changeZoom',
  279. 'clearTimeline',
  280. 'saveTimeLine',
  281. 'changeIframeDialog',
  282. 'changePageInfo',
  283. 'changeActiveItemConfig'
  284. ]),
  285. // 判断页面权限
  286. permission () {
  287. this.$dataRoomAxios.get(`/bigScreen/permission/check/${this.pageCode}`).then(res => {
  288. this.hasPermission = res
  289. if (res) {
  290. this.init()
  291. }
  292. })
  293. },
  294. // 添加资源弹窗初始化
  295. initDialog () {
  296. this.$refs.SourceDialog.init()
  297. },
  298. openComponent () {
  299. this.$refs.componentDialog.init()
  300. },
  301. // 从组件库添加组件模板到当前画布
  302. setComponent (component) {
  303. // 根据component获取页面详情
  304. getScreenInfo(component.code).then(res => {
  305. // 给组件库导入的组件加入统一的前缀
  306. const randomStr = randomString(8)
  307. const pageInfo = handleResData(res)
  308. const chartList = pageInfo.chartList.reverse()
  309. chartList.forEach((chart) => {
  310. // 如果组件存在数据联动,则将数据联动的code也加上相同的前缀
  311. if (chart.linkage && chart.linkage.components && chart.linkage.components.length) {
  312. chart.linkage.components.forEach((com) => { com.componentKey = randomStr + com.componentKey })
  313. }
  314. const newChart = {
  315. ...chart,
  316. offsetX: 0,
  317. group: randomStr,
  318. code: randomStr + chart.code
  319. }
  320. // 如果是从组件库中添加的自定义组件,则不需要初始化theme
  321. const isComponent = true
  322. this.$refs.Render.addChart(newChart, { x: chart.x, y: chart.y }, isComponent)
  323. this.updateRightVisiable(false)
  324. })
  325. })
  326. },
  327. // 添加远程组件
  328. setRemoteComponent (component) {
  329. const newChart = {
  330. ...component,
  331. offsetX: 0,
  332. offsetY: 0,
  333. code: randomString(8)
  334. }
  335. this.$refs.Render.addChart(newChart, { x: 0, y: 0 })
  336. },
  337. setImg (val) {
  338. this.$refs.Render.addSourceChart(
  339. JSON.stringify({
  340. title: val.originalName,
  341. name: val.originalName,
  342. icon: null,
  343. className:
  344. 'com.gccloud.dataroom.core.module.chart.components.ScreenPictureChart',
  345. w: 300,
  346. h: 300,
  347. x: 0,
  348. y: 0,
  349. type: 'picture',
  350. option: {
  351. ...cloneDeep(settingConfig)
  352. },
  353. setting: {}, // 右侧面板自定义配置
  354. dataHandler: {}, // 数据自定义处理js脚本
  355. ...cloneDeep(dataConfig),
  356. customize: {
  357. url: val.url,
  358. radius: 0,
  359. opacity: 100
  360. }
  361. }),
  362. { x: 150, y: 100 }
  363. )
  364. },
  365. init () {
  366. this.changePageLoading(true)
  367. this.initLayout(this.pageCode)
  368. .then(() => {
  369. const themeName = this.pageConfig.customTheme
  370. if (!['dark', 'light', 'auto'].includes(themeName)) {
  371. getThemeConfig().then((res) => {
  372. // 初始化时如果就是自定义主题则统一注册
  373. const { registerTheme } = G2
  374. registerTheme(themeName, { ...res.chart })
  375. const pageConfig = this.pageConfig
  376. pageConfig.themeJson = res
  377. this.changePageConfig(pageConfig)
  378. this.changePageLoading(false)
  379. })
  380. } else {
  381. this.changePageLoading(false)
  382. }
  383. })
  384. .finally(() => {
  385. setTimeout(() => {
  386. this.resetPresetLine()
  387. }, 500)
  388. })
  389. },
  390. // 点击当前组件时打开右侧面板
  391. openRightPanel (card) {
  392. this.rightVisiable = true
  393. this.pageInfoVisiable = false
  394. },
  395. /**
  396. * @description: 清空页面
  397. */
  398. empty () {
  399. this.$confirm('确定清空页面吗?', '提示', {
  400. confirmButtonText: '确定',
  401. cancelButtonText: '取消',
  402. type: 'warning',
  403. customClass: 'bs-el-message-box'
  404. })
  405. .then(() => {
  406. this.changeLayout([])
  407. this.resetPresetLine()
  408. this.saveTimeLine('清空画布')
  409. })
  410. .catch(() => {})
  411. },
  412. // 自定义属性更新
  413. updateSetting (config) {
  414. if (config.type === 'map' || config.type === 'video' ||config.type === 'flyMap') {
  415. config.key = new Date().getTime()
  416. }
  417. this.changeChartConfig(cloneDeep(config))
  418. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  419. config.code
  420. ]?.changeStyle(cloneDeep(config))
  421. },
  422. // 动态属性更新
  423. updateDataSetting (config) {
  424. config.key = new Date().getTime()
  425. this.changeChartConfig(config)
  426. },
  427. onSelectArea (area) {
  428. const { startX, startY, endX, endY } = area
  429. // 计算所有在此区域中的组件,如果在此区域中,将其code添加到activeCodes数组中
  430. const activeCodes = this.chartList
  431. ?.filter((chart) => {
  432. const { x, y, w, h } = chart
  433. return startX <= x && x + w <= endX && startY <= y && y + h <= endY
  434. })
  435. ?.map((chart) => chart.code)
  436. this.changeActiveCodes(activeCodes)
  437. },
  438. changeStart ({ x, y }) {
  439. this.ruleStartX = x
  440. this.ruleStartY = y
  441. },
  442. // 保存并预览
  443. saveAndPreview () {
  444. this.$refs.PageTopSetting.execRun()
  445. },
  446. // 保存
  447. save () {
  448. this.$refs.PageTopSetting.save('saveLoading')
  449. },
  450. changeScreenZoom (zoom) {
  451. // 自适应
  452. if (zoom === 'auto') {
  453. this.$refs.Rules.initZoom()
  454. } else {
  455. this.changeZoom(zoom)
  456. }
  457. },
  458. updateRightVisiable (visiable) {
  459. this.rightVisiable = visiable
  460. this.$refs.Rules.initRuleHeight()
  461. },
  462. toggleLeftSidebar () {
  463. this.$refs.Rules.initRuleHeight()
  464. },
  465. showPageInfo () {
  466. this.pageInfoVisiable = true
  467. this.rightVisiable = true
  468. this.changeActiveCode('')
  469. },
  470. // 页面信息更改
  471. updatePage () {
  472. this.$refs.Rules.initZoom()
  473. }
  474. }
  475. }
  476. </script>
  477. <style lang="scss" scoped>
  478. .bs-page-design-wrap {
  479. overflow: hidden;
  480. .drag-wrap {
  481. display: flex;
  482. background-color: #1d1e20;
  483. height: calc(100vh - 40px);
  484. overflow: hidden;
  485. .grid-wrap-box {
  486. flex: 1;
  487. overflow: hidden;
  488. position: relative;
  489. margin: 8px 0 0 8px;
  490. .footer-tools-bar {
  491. position: absolute;
  492. bottom: 0;
  493. width: 100%;
  494. height: 30px;
  495. display: flex;
  496. justify-content: flex-end;
  497. align-items: center;
  498. z-index: 1000;
  499. background-color: var(--bs-background-2);
  500. .bs-select-wrap {
  501. margin-right: 16px;
  502. }
  503. .select-zoom-text {
  504. color: var(--bs-el-title);
  505. margin-right: 16px;
  506. }
  507. ::v-deep .el-select {
  508. width: 150px !important;
  509. }
  510. }
  511. }
  512. ::v-deep .el-loading-mask {
  513. background-color: transparent !important;
  514. }
  515. }
  516. }
  517. </style>