index.vue 14 KB

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