index.vue 14 KB

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