index.vue 15 KB

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