index.vue 14 KB

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