index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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. dataViewDialogConfig: null,
  178. hasPermission: true,
  179. rightVisiable: false,
  180. pageInfoVisiable: false,
  181. ruleStartX: 100,
  182. ruleStartY: 100,
  183. zoomList: [
  184. {
  185. label: '自适应',
  186. value: 'auto'
  187. },
  188. {
  189. label: '100%',
  190. value: 100
  191. },
  192. {
  193. label: '80%',
  194. value: 80
  195. },
  196. {
  197. label: '50%',
  198. value: 50
  199. },
  200. {
  201. label: '20%',
  202. value: 20
  203. }
  204. ]
  205. }
  206. },
  207. watch: {
  208. fitZoom (zoom) {
  209. this.zoomList[0] = {
  210. label: `自适应(${zoom}%)`,
  211. value: zoom
  212. }
  213. }
  214. },
  215. computed: {
  216. ...mapState({
  217. pageInfo: (state) => state.bigScreen.pageInfo,
  218. chartList: (state) => state.bigScreen.pageInfo.chartList,
  219. pageConfig: (state) => state.bigScreen.pageInfo.pageConfig,
  220. pageLoading: (state) => state.bigScreen.pageLoading,
  221. hoverCode: (state) => state.bigScreen.hoverCode,
  222. presetLine: (state) => state.bigScreen.presetLine,
  223. updateKey: (state) => state.bigScreen.updateKey,
  224. hasGrid: (state) => state.bigScreen.hasGrid,
  225. zoom: (state) => state.bigScreen.zoom,
  226. fitZoom: (state) => state.bigScreen.fitZoom,
  227. iframeDialog: (state) => state.bigScreen.iframeDialog,
  228. activeCode: state => state.bigScreen.activeCode
  229. }),
  230. pageCode () {
  231. return this.code || this.$route.query.code
  232. },
  233. offset () {
  234. return {
  235. x: 220 + 50 - this.ruleStartX,
  236. y: 55 + 50 - this.ruleStartY
  237. }
  238. }
  239. },
  240. created () {
  241. this.changePageLoading(true)
  242. this.permission()
  243. /**
  244. * 以下是为了解决在火狐浏览器上推拽时弹出tab页到搜索问题
  245. * @param event
  246. */
  247. if (isFirefox()) {
  248. document.body.ondrop = function (event) {
  249. event.preventDefault()
  250. event.stopPropagation()
  251. }
  252. }
  253. },
  254. mounted () {
  255. EventBus.$on('closeRightPanel', () => { this.rightVisiable = false })
  256. },
  257. beforeDestroy () {
  258. this.clearTimeline()
  259. EventBus.$off('closeRightPanel')
  260. },
  261. methods: {
  262. ...mapActions('bigScreen', ['initLayout']),
  263. ...mapMutations('bigScreen', [
  264. 'changeLayout',
  265. 'changePageLoading',
  266. 'resetPresetLine',
  267. 'changeActiveCode',
  268. 'changeActiveCodes',
  269. 'changePageConfig',
  270. 'changeChartConfig',
  271. 'changeChartKey',
  272. 'changeZoom',
  273. 'clearTimeline',
  274. 'saveTimeLine',
  275. 'changeIframeDialog',
  276. 'changePageInfo',
  277. 'changeActiveItemConfig'
  278. ]),
  279. // 判断页面权限
  280. permission () {
  281. this.$dataRoomAxios.get(`/bigScreen/permission/check/${this.pageCode}`).then(res => {
  282. this.hasPermission = res
  283. if (res) {
  284. this.init()
  285. }
  286. })
  287. },
  288. // 添加资源弹窗初始化
  289. initDialog () {
  290. this.$refs.SourceDialog.init()
  291. },
  292. openComponent () {
  293. this.$refs.componentDialog.init()
  294. },
  295. // 从组件库添加组件模板到当前画布
  296. setComponent (component) {
  297. // 根据component获取页面详情
  298. getScreenInfo(component.code).then(res => {
  299. // 给组件库导入的组件加入统一的前缀
  300. const randomStr = randomString(8)
  301. const pageInfo = handleResData(res)
  302. const chartList = pageInfo.chartList.reverse()
  303. chartList.forEach((chart) => {
  304. // 如果组件存在数据联动,则将数据联动的code也加上相同的前缀
  305. if (chart.linkage && chart.linkage.components && chart.linkage.components.length) {
  306. chart.linkage.components.forEach((com) => { com.componentKey = randomStr + com.componentKey })
  307. }
  308. const newChart = {
  309. ...chart,
  310. offsetX: 0,
  311. group: randomStr,
  312. code: randomStr + chart.code
  313. }
  314. // 如果是从组件库中添加的自定义组件,则不需要初始化theme
  315. const isComponent = true
  316. this.$refs.Render.addChart(newChart, { x: chart.x, y: chart.y }, isComponent)
  317. this.updateRightVisiable(false)
  318. })
  319. })
  320. },
  321. // 添加远程组件
  322. setRemoteComponent (component) {
  323. const newChart = {
  324. ...component,
  325. offsetX: 0,
  326. offsetY: 0,
  327. code: randomString(8)
  328. }
  329. this.$refs.Render.addChart(newChart, { x: 0, y: 0 })
  330. },
  331. setImg (val) {
  332. this.$refs.Render.addSourceChart(
  333. JSON.stringify({
  334. title: val.originalName,
  335. name: val.originalName,
  336. icon: null,
  337. className:
  338. 'com.gccloud.dataroom.core.module.chart.components.ScreenPictureChart',
  339. w: 300,
  340. h: 300,
  341. x: 0,
  342. y: 0,
  343. type: 'picture',
  344. option: {
  345. ...cloneDeep(settingConfig)
  346. },
  347. setting: {}, // 右侧面板自定义配置
  348. dataHandler: {}, // 数据自定义处理js脚本
  349. ...cloneDeep(dataConfig),
  350. customize: {
  351. url: val.url,
  352. radius: 0,
  353. opacity: 100
  354. }
  355. }),
  356. { x: 150, y: 100 }
  357. )
  358. },
  359. init () {
  360. this.changePageLoading(true)
  361. this.initLayout(this.pageCode)
  362. .then(() => {
  363. this.changePageLoading(false)
  364. })
  365. .finally(() => {
  366. setTimeout(() => {
  367. this.resetPresetLine()
  368. }, 500)
  369. })
  370. },
  371. // 点击当前组件时打开右侧面板
  372. openRightPanel (card) {
  373. this.rightVisiable = true
  374. this.pageInfoVisiable = false
  375. },
  376. openDataViewDialog (config) {
  377. this.dataViewDialogConfig = config
  378. this.$refs.dataViewDialog.init(config)
  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. styleHandler (config) {
  399. this.$nextTick(() => {
  400. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  401. config.code
  402. ]?.changeStyle(cloneDeep(config), true)
  403. })
  404. },
  405. // 自定义属性更新
  406. updateSetting (config) {
  407. if (config.type === 'map' || config.type === 'remoteComponent' || config.type === 'video' || config.type === 'flyMap') {
  408. config.key = new Date().getTime()
  409. }
  410. this.changeChartConfig(cloneDeep(config))
  411. // 如果是tab内的组件
  412. if (config.parentCode) {
  413. const dom = this.$refs.Render?.$refs['RenderCard' + config.parentCode][0]?.$refs[config.parentCode]?.$refs['RenderCard' + config.code]?.$refs[config.code]
  414. if (dom) {
  415. dom?.changeStyle(cloneDeep(config))
  416. }
  417. } else {
  418. if (this.$refs.Render?.$refs['RenderCard' + config.code]) {
  419. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  420. config.code
  421. ]?.changeStyle(cloneDeep(config))
  422. }
  423. }
  424. },
  425. // 动态属性更新
  426. updateDataSetting (config) {
  427. config.key = new Date().getTime()
  428. this.changeChartConfig(config)
  429. },
  430. onSelectArea (area) {
  431. const { startX, startY, endX, endY } = area
  432. // 计算所有在此区域中的组件,如果在此区域中,将其code添加到activeCodes数组中
  433. const activeCodes = this.chartList
  434. ?.filter((chart) => {
  435. const { x, y, w, h } = chart
  436. return startX <= x && x + w <= endX && startY <= y && y + h <= endY
  437. })
  438. ?.map((chart) => chart.code)
  439. this.changeActiveCodes(activeCodes)
  440. },
  441. changeStart ({ x, y }) {
  442. this.ruleStartX = x
  443. this.ruleStartY = y
  444. },
  445. // 保存并预览
  446. saveAndPreview () {
  447. this.$refs.PageTopSetting.execRun()
  448. },
  449. // 保存
  450. save () {
  451. this.$refs.PageTopSetting.save('saveLoading')
  452. },
  453. changeScreenZoom (zoom) {
  454. // 自适应
  455. if (zoom === 'auto') {
  456. this.$refs.Rules.initZoom()
  457. } else {
  458. this.changeZoom(zoom)
  459. }
  460. },
  461. updateRightVisiable (visiable) {
  462. this.rightVisiable = visiable
  463. this.$refs.Rules.initRuleHeight()
  464. },
  465. toggleLeftSidebar () {
  466. this.$refs.Rules.initRuleHeight()
  467. },
  468. showPageInfo () {
  469. this.pageInfoVisiable = true
  470. this.rightVisiable = true
  471. this.changeActiveCode('')
  472. },
  473. // 页面信息更改
  474. updatePage () {
  475. this.$refs.Rules.initZoom()
  476. }
  477. }
  478. }
  479. </script>
  480. <style lang="scss" scoped>
  481. .bs-page-design-wrap {
  482. overflow: hidden;
  483. .drag-wrap {
  484. display: flex;
  485. background-color: #1d1e20;
  486. height: calc(100vh - 40px);
  487. overflow: hidden;
  488. .grid-wrap-box {
  489. flex: 1;
  490. overflow: hidden;
  491. position: relative;
  492. margin: 8px 0 0 8px;
  493. .footer-tools-bar {
  494. position: absolute;
  495. bottom: 0;
  496. width: 100%;
  497. height: 30px;
  498. display: flex;
  499. justify-content: flex-end;
  500. align-items: center;
  501. z-index: 1000;
  502. background-color: var(--bs-background-2);
  503. .bs-select-wrap {
  504. margin-right: 16px;
  505. }
  506. .select-zoom-text {
  507. color: var(--bs-el-title);
  508. margin-right: 16px;
  509. }
  510. ::v-deep .el-select {
  511. width: 150px !important;
  512. }
  513. }
  514. }
  515. ::v-deep .el-loading-mask {
  516. background-color: transparent !important;
  517. }
  518. }
  519. }
  520. </style>