index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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 _ from 'lodash'
  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. }),
  221. pageCode () {
  222. return this.code || this.$route.query.code
  223. },
  224. offset () {
  225. return {
  226. x: 220 + 50 - this.ruleStartX,
  227. y: 55 + 50 - this.ruleStartY
  228. }
  229. }
  230. },
  231. // beforeRouteEnter (to, from, next) {
  232. // // 判断进入设计页面前是否有访问权限
  233. // const code = to.query.code
  234. // get(`/bigScreen/permission/check/${code}`).then((res) => {
  235. // if (res) {
  236. // next((vm) => {
  237. // // 重置大屏的vuex store
  238. // vm.$store.commit('bigScreen/resetStoreData')
  239. // })
  240. // } else {
  241. // next('/notPermission')
  242. // }
  243. // })
  244. // },
  245. created () {
  246. this.changePageLoading(true)
  247. this.permission()
  248. /**
  249. * 以下是为了解决在火狐浏览器上推拽时弹出tab页到搜索问题
  250. * @param event
  251. */
  252. if (isFirefox()) {
  253. document.body.ondrop = function (event) {
  254. event.preventDefault()
  255. event.stopPropagation()
  256. }
  257. }
  258. },
  259. mounted () {
  260. EventBus.$on('closeRightPanel', () => { this.rightVisiable = false })
  261. },
  262. beforeDestroy () {
  263. this.clearTimeline()
  264. EventBus.$off('closeRightPanel')
  265. },
  266. methods: {
  267. ...mapActions('bigScreen', ['initLayout']),
  268. ...mapMutations('bigScreen', [
  269. 'changeLayout',
  270. 'changePageLoading',
  271. 'resetPresetLine',
  272. 'changeActiveCode',
  273. 'changeActiveCodes',
  274. 'changePageConfig',
  275. 'changeChartConfig',
  276. 'changeChartKey',
  277. 'changeZoom',
  278. 'clearTimeline',
  279. 'saveTimeLine',
  280. 'changeIframeDialog'
  281. ]),
  282. // 判断页面权限
  283. permission () {
  284. this.$dataRoomAxios.get(`/bigScreen/permission/check/${this.pageCode}`).then(res => {
  285. this.hasPermission = res
  286. if (res) {
  287. this.init()
  288. }
  289. })
  290. },
  291. // 添加资源弹窗初始化
  292. initDialog () {
  293. this.$refs.SourceDialog.init()
  294. },
  295. openComponent () {
  296. this.$refs.componentDialog.init()
  297. },
  298. // 从组件库添加组件模板到当前画布
  299. setComponent (component) {
  300. // 根据component获取页面详情
  301. getScreenInfo(component.code).then(res => {
  302. // 给组件库导入的组件加入统一的前缀
  303. const randomStr = randomString(8)
  304. const pageInfo = handleResData(res)
  305. const chartList = pageInfo.chartList.reverse()
  306. chartList.forEach((chart) => {
  307. // 如果组件存在数据联动,则将数据联动的code也加上相同的前缀
  308. if (chart.linkage && chart.linkage.components && chart.linkage.components.length) {
  309. chart.linkage.components.forEach((com) => { com.componentKey = randomStr + com.componentKey })
  310. }
  311. const newChart = {
  312. ...chart,
  313. offsetX: 0,
  314. group: randomStr,
  315. code: randomStr + chart.code
  316. }
  317. this.$refs.Render.addChart(newChart, { x: chart.x, y: chart.y }, true)
  318. this.updateRightVisiable(false)
  319. })
  320. })
  321. },
  322. // 添加远程组件
  323. setRemoteComponent (component) {
  324. const newChart = {
  325. ...component,
  326. offsetX: 0,
  327. offsetY: 0,
  328. code: randomString(8)
  329. }
  330. this.$refs.Render.addChart(newChart, { x: 0, y: 0 })
  331. },
  332. setImg (val) {
  333. this.$refs.Render.addSourceChart(
  334. JSON.stringify({
  335. title: val.originalName,
  336. name: val.originalName,
  337. icon: null,
  338. className:
  339. 'com.gccloud.dataroom.core.module.chart.components.ScreenPictureChart',
  340. w: 300,
  341. h: 300,
  342. x: 0,
  343. y: 0,
  344. type: 'picture',
  345. option: {
  346. ..._.cloneDeep(settingConfig)
  347. },
  348. setting: {}, // 右侧面板自定义配置
  349. dataHandler: {}, // 数据自定义处理js脚本
  350. ..._.cloneDeep(dataConfig),
  351. customize: {
  352. url: val.url,
  353. radius: 0,
  354. opacity: 100
  355. }
  356. }),
  357. { x: 150, y: 100 }
  358. )
  359. },
  360. init () {
  361. this.changePageLoading(true)
  362. this.initLayout(this.pageCode)
  363. .then(() => {
  364. const themeName = this.pageConfig.customTheme
  365. if (!['dark', 'light', 'auto'].includes(themeName)) {
  366. getThemeConfig().then((res) => {
  367. // 初始化时如果就是自定义主题则统一注册
  368. const { registerTheme } = G2
  369. registerTheme(themeName, { ...res.chart })
  370. const pageConfig = this.pageConfig
  371. pageConfig.themeJson = res
  372. this.changePageConfig(pageConfig)
  373. this.changePageLoading(false)
  374. })
  375. } else {
  376. this.changePageLoading(false)
  377. }
  378. })
  379. .finally(() => {
  380. setTimeout(() => {
  381. this.resetPresetLine()
  382. }, 500)
  383. })
  384. },
  385. // 点击当前组件时打开右侧面板
  386. openRightPanel (card) {
  387. this.rightVisiable = true
  388. this.pageInfoVisiable = false
  389. },
  390. /**
  391. * @description: 清空页面
  392. */
  393. empty () {
  394. this.$confirm('确定清空页面吗?', '提示', {
  395. confirmButtonText: '确定',
  396. cancelButtonText: '取消',
  397. type: 'warning',
  398. customClass: 'bs-el-message-box'
  399. })
  400. .then(() => {
  401. this.changeLayout([])
  402. this.resetPresetLine()
  403. this.saveTimeLine('清空画布')
  404. })
  405. .catch(() => {})
  406. },
  407. // 自定义属性更新
  408. updateSetting (config) {
  409. if (config.type === 'map') {
  410. config.key = new Date().getTime()
  411. }
  412. this.changeChartConfig(_.cloneDeep(config))
  413. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  414. config.code
  415. ]?.changeStyle(_.cloneDeep(config))
  416. },
  417. // 动态属性更新
  418. updateDataSetting (config) {
  419. config.key = new Date().getTime()
  420. this.changeChartConfig(config)
  421. },
  422. onSelectArea (area) {
  423. const { startX, startY, endX, endY } = area
  424. // 计算所有在此区域中的组件,如果在此区域中,将其code添加到activeCodes数组中
  425. const activeCodes = this.chartList
  426. ?.filter((chart) => {
  427. const { x, y, w, h } = chart
  428. return startX <= x && x + w <= endX && startY <= y && y + h <= endY
  429. })
  430. ?.map((chart) => chart.code)
  431. this.changeActiveCodes(activeCodes)
  432. },
  433. changeStart ({ x, y }) {
  434. this.ruleStartX = x
  435. this.ruleStartY = y
  436. },
  437. // 保存并预览
  438. saveAndPreview () {
  439. this.$refs.PageTopSetting.execRun()
  440. },
  441. // 保存
  442. save () {
  443. this.$refs.PageTopSetting.save('saveLoading')
  444. },
  445. changeScreenZoom (zoom) {
  446. // 自适应
  447. if (zoom === 'auto') {
  448. this.$refs.Rules.initZoom()
  449. } else {
  450. this.changeZoom(zoom)
  451. }
  452. },
  453. updateRightVisiable (visiable) {
  454. this.rightVisiable = visiable
  455. this.$refs.Rules.initRuleHeight()
  456. },
  457. toggleLeftSidebar () {
  458. this.$refs.Rules.initRuleHeight()
  459. },
  460. showPageInfo () {
  461. this.pageInfoVisiable = true
  462. this.rightVisiable = true
  463. this.changeActiveCode('')
  464. },
  465. // 页面信息更改
  466. updatePage () {
  467. this.$refs.Rules.initZoom()
  468. }
  469. }
  470. }
  471. </script>
  472. <style lang="scss" scoped>
  473. .bs-page-design-wrap {
  474. overflow: hidden;
  475. .drag-wrap {
  476. display: flex;
  477. background-color: #1d1e20;
  478. height: calc(100vh - 40px);
  479. overflow: hidden;
  480. .grid-wrap-box {
  481. flex: 1;
  482. overflow: hidden;
  483. position: relative;
  484. margin: 8px 0 0 8px;
  485. .footer-tools-bar {
  486. position: absolute;
  487. bottom: 0;
  488. width: 100%;
  489. height: 30px;
  490. display: flex;
  491. justify-content: flex-end;
  492. align-items: center;
  493. z-index: 1000;
  494. background-color: var(--bs-background-2);
  495. .bs-select-wrap {
  496. margin-right: 16px;
  497. }
  498. .select-zoom-text {
  499. color: var(--bs-el-title);
  500. margin-right: 16px;
  501. }
  502. /deep/ .el-select {
  503. width: 150px !important;
  504. }
  505. }
  506. }
  507. /deep/ .el-loading-mask {
  508. background-color: transparent !important;
  509. }
  510. }
  511. }
  512. </style>