index.vue 15 KB

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