index.vue 14 KB

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