index.vue 15 KB

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