index.vue 13 KB

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