index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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 plotSettings from 'data-room-ui/G2Plots/settings'
  138. import MouseSelect from './MouseSelect/index.vue'
  139. import cloneDeep from 'lodash/cloneDeep'
  140. import { randomString } from '../js/utils'
  141. import { isFirefox } from 'data-room-ui/js/utils/userAgent'
  142. import { handleResData } from 'data-room-ui/js/store/actions.js'
  143. import { EventBus } from 'data-room-ui/js/utils/eventBus'
  144. import NotPermission from 'data-room-ui/NotPermission'
  145. import DataViewDialog from 'data-room-ui/BigScreenDesign/DataViewDialog'
  146. export default {
  147. name: 'BigScreenDesign',
  148. components: {
  149. PageTopSetting,
  150. LeftPanel,
  151. Render,
  152. SketchDesignRuler,
  153. MouseSelect,
  154. SettingPanel,
  155. SourceDialog,
  156. ComponentDialog,
  157. iframeDialog,
  158. NotPermission,
  159. DataViewDialog
  160. },
  161. mixins: [multipleSelectMixin],
  162. props: {
  163. code: {
  164. type: String,
  165. default: ''
  166. },
  167. headerShow: {
  168. type: Boolean,
  169. default: true
  170. },
  171. height: {
  172. type: String,
  173. default: 'calc(100vh - 40px)'
  174. }
  175. },
  176. data () {
  177. return {
  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. chartList (val) {
  209. // console.log(val,this.activeCode)
  210. // if(val.findIndex(item=>item.code==this.activeCode)==-1){
  211. // this.updateRightVisiable(false)
  212. // }
  213. // if(val.length==0){
  214. // this.updateRightVisiable(false)
  215. // }
  216. },
  217. fitZoom (zoom) {
  218. this.zoomList[0] = {
  219. label: `自适应(${zoom}%)`,
  220. value: zoom
  221. }
  222. }
  223. },
  224. computed: {
  225. ...mapState({
  226. pageInfo: (state) => state.bigScreen.pageInfo,
  227. chartList: (state) => state.bigScreen.pageInfo.chartList,
  228. pageConfig: (state) => state.bigScreen.pageInfo.pageConfig,
  229. pageLoading: (state) => state.bigScreen.pageLoading,
  230. hoverCode: (state) => state.bigScreen.hoverCode,
  231. presetLine: (state) => state.bigScreen.presetLine,
  232. updateKey: (state) => state.bigScreen.updateKey,
  233. hasGrid: (state) => state.bigScreen.hasGrid,
  234. zoom: (state) => state.bigScreen.zoom,
  235. fitZoom: (state) => state.bigScreen.fitZoom,
  236. iframeDialog: (state) => state.bigScreen.iframeDialog,
  237. activeCode: state => state.bigScreen.activeCode
  238. }),
  239. pageCode () {
  240. return this.code || this.$route.query.code
  241. },
  242. offset () {
  243. return {
  244. x: 220 + 50 - this.ruleStartX,
  245. y: 55 + 50 - this.ruleStartY
  246. }
  247. }
  248. },
  249. created () {
  250. this.changePageLoading(true)
  251. this.permission()
  252. /**
  253. * 以下是为了解决在火狐浏览器上推拽时弹出tab页到搜索问题
  254. * @param event
  255. */
  256. if (isFirefox()) {
  257. document.body.ondrop = function (event) {
  258. event.preventDefault()
  259. event.stopPropagation()
  260. }
  261. }
  262. },
  263. mounted () {
  264. EventBus.$on('closeRightPanel', () => {
  265. this.updateRightVisiable(false)
  266. })
  267. },
  268. beforeDestroy () {
  269. this.clearTimeline()
  270. EventBus.$off('closeRightPanel')
  271. },
  272. methods: {
  273. ...mapActions('bigScreen', ['initLayout']),
  274. ...mapMutations('bigScreen', [
  275. 'changeLayout',
  276. 'changePageLoading',
  277. 'resetPresetLine',
  278. 'changeActiveCode',
  279. 'changeActiveCodes',
  280. 'changePageConfig',
  281. 'changeChartConfig',
  282. 'changeChartKey',
  283. 'changeZoom',
  284. 'clearTimeline',
  285. 'saveTimeLine',
  286. 'changeIframeDialog',
  287. 'changePageInfo',
  288. 'changeActiveItemConfig'
  289. ]),
  290. // 判断页面权限
  291. permission () {
  292. this.$dataRoomAxios.get(`/bigScreen/permission/check/${this.pageCode}`).then(res => {
  293. this.hasPermission = res
  294. if (res) {
  295. this.init()
  296. }
  297. })
  298. },
  299. // 添加资源弹窗初始化
  300. initDialog () {
  301. this.$refs.SourceDialog.init()
  302. },
  303. openComponent () {
  304. this.$refs.componentDialog.init()
  305. },
  306. // 从组件库添加组件模板到当前画布
  307. setComponent (component) {
  308. // 根据component获取页面详情
  309. getScreenInfo(component.code).then(res => {
  310. res.chartList.forEach((item) => {
  311. if (!item.border) {
  312. item.border = { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [0, 0, 0, 0] }
  313. }
  314. if (!item.border.padding) {
  315. item.border.padding = [0, 0, 0, 0]
  316. }
  317. if (item.type == 'customComponent') {
  318. plotSettings[Symbol.iterator] = function * () {
  319. const keys = Object.keys(plotSettings)
  320. for (const k of keys) {
  321. yield [k, plotSettings[k]]
  322. }
  323. }
  324. for (const [key, value] of plotSettings) {
  325. if (item.name == value.name) {
  326. const settings = JSON.parse(JSON.stringify(value.setting))
  327. item.setting = settings.map((x) => {
  328. const index = item.setting.findIndex(y => y.field == x.field)
  329. x.field = item.setting[index].field
  330. x.value = item.setting[index].value
  331. return x
  332. })
  333. }
  334. }
  335. }
  336. })
  337. // 给组件库导入的组件加入统一的前缀
  338. const randomStr = randomString(8)
  339. const pageInfo = handleResData(res)
  340. const chartList = pageInfo.chartList.reverse()
  341. chartList.forEach((chart) => {
  342. // 如果组件存在数据联动,则将数据联动的code也加上相同的前缀
  343. if (chart.linkage && chart.linkage.components && chart.linkage.components.length) {
  344. chart.linkage.components.forEach((com) => { com.componentKey = randomStr + com.componentKey })
  345. }
  346. const newChart = {
  347. ...chart,
  348. offsetX: 0,
  349. group: randomStr,
  350. code: randomStr + chart.code
  351. }
  352. // 如果是从组件库中添加的自定义组件,则不需要初始化theme
  353. const isComponent = true
  354. this.$refs.Render.addChart(newChart, { x: chart.x, y: chart.y }, isComponent)
  355. this.updateRightVisiable(false)
  356. })
  357. })
  358. },
  359. // 添加远程组件
  360. setRemoteComponent (component) {
  361. const newChart = {
  362. ...component,
  363. offsetX: 0,
  364. offsetY: 0,
  365. code: randomString(8)
  366. }
  367. this.$refs.Render.addChart(newChart, { x: 0, y: 0 })
  368. },
  369. setImg (val) {
  370. this.$refs.Render.addSourceChart(
  371. JSON.stringify({
  372. title: val.originalName,
  373. name: val.originalName,
  374. icon: null,
  375. className:
  376. 'com.gccloud.dataroom.core.module.chart.components.ScreenPictureChart',
  377. w: 300,
  378. h: 300,
  379. x: 0,
  380. y: 0,
  381. type: 'picture',
  382. option: {
  383. ...cloneDeep(settingConfig)
  384. },
  385. setting: {}, // 右侧面板自定义配置
  386. dataHandler: {}, // 数据自定义处理js脚本
  387. ...cloneDeep(dataConfig),
  388. customize: {
  389. url: val.url,
  390. radius: 0,
  391. opacity: 100
  392. }
  393. }),
  394. { x: 150, y: 100 }
  395. )
  396. },
  397. init () {
  398. this.changePageLoading(true)
  399. this.initLayout(this.pageCode)
  400. .then(() => {
  401. this.changePageLoading(false)
  402. })
  403. .finally(() => {
  404. setTimeout(() => {
  405. this.resetPresetLine()
  406. }, 500)
  407. })
  408. },
  409. // 点击当前组件时打开右侧面板
  410. openRightPanel (card) {
  411. this.rightVisiable = true
  412. this.pageInfoVisiable = false
  413. },
  414. openDataViewDialog (config) {
  415. this.$refs.dataViewDialog.init(config)
  416. },
  417. /**
  418. * @description: 清空页面
  419. */
  420. empty () {
  421. this.$confirm('确定清空页面吗?', '提示', {
  422. confirmButtonText: '确定',
  423. cancelButtonText: '取消',
  424. type: 'warning',
  425. customClass: 'bs-el-message-box'
  426. })
  427. .then(() => {
  428. this.changeLayout([])
  429. this.resetPresetLine()
  430. this.saveTimeLine('清空画布')
  431. })
  432. .catch(() => {})
  433. },
  434. // 切换主题时针对远程组件触发样式修改的方法
  435. styleHandler (config) {
  436. this.$nextTick(() => {
  437. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  438. config.code
  439. ]?.changeStyle(cloneDeep(config), true)
  440. })
  441. },
  442. // 自定义属性更新
  443. updateSetting (config) {
  444. if (config.type === 'map' || config.type === 'screenScrollBoard' || config.type === 'remoteComponent' || config.type === 'video' || config.type === 'flyMap') {
  445. config.key = new Date().getTime()
  446. }
  447. this.changeChartConfig(cloneDeep(config))
  448. // 如果是tab内的组件
  449. if (config.parentCode) {
  450. const dom = this.$refs.Render?.$refs['RenderCard' + config.parentCode][0]?.$refs[config.parentCode]?.$refs['RenderCard' + config.code]?.$refs[config.code]
  451. if (dom) {
  452. dom?.changeStyle(cloneDeep(config))
  453. }
  454. } else {
  455. if (this.$refs.Render?.$refs['RenderCard' + config.code]) {
  456. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  457. config.code
  458. ]?.changeStyle(cloneDeep(config))
  459. }
  460. }
  461. },
  462. // 动态属性更新
  463. updateDataSetting (config) {
  464. config.key = new Date().getTime()
  465. this.changeChartConfig(config)
  466. },
  467. onSelectArea (area) {
  468. const { startX, startY, endX, endY } = area
  469. // 计算所有在此区域中的组件,如果在此区域中,将其code添加到activeCodes数组中
  470. const activeCodes = this.chartList
  471. ?.filter((chart) => {
  472. const { x, y, w, h } = chart
  473. return startX <= x && x + w <= endX && startY <= y && y + h <= endY
  474. })
  475. ?.map((chart) => chart.code)
  476. this.changeActiveCodes(activeCodes)
  477. },
  478. changeStart ({ x, y }) {
  479. this.ruleStartX = x
  480. this.ruleStartY = y
  481. },
  482. // 保存并预览
  483. saveAndPreview () {
  484. this.$refs.PageTopSetting.execRun()
  485. },
  486. // 保存
  487. save () {
  488. this.$refs.PageTopSetting.save('saveLoading')
  489. },
  490. changeScreenZoom (zoom) {
  491. // 自适应
  492. if (zoom === 'auto') {
  493. this.$refs.Rules.initZoom()
  494. } else {
  495. this.changeZoom(zoom)
  496. }
  497. },
  498. updateRightVisiable (visiable) {
  499. this.rightVisiable = visiable
  500. this.$refs.Rules.initRuleHeight()
  501. },
  502. toggleLeftSidebar () {
  503. this.$refs.Rules.initRuleHeight()
  504. },
  505. showPageInfo () {
  506. this.pageInfoVisiable = true
  507. this.rightVisiable = true
  508. this.changeActiveCode('')
  509. },
  510. // 页面信息更改
  511. updatePage () {
  512. this.$refs.Rules.initZoom()
  513. }
  514. }
  515. }
  516. </script>
  517. <style lang="scss" scoped>
  518. .bs-page-design-wrap {
  519. overflow: hidden;
  520. .drag-wrap {
  521. display: flex;
  522. background-color: #1d1e20;
  523. height: calc(100vh - 40px);
  524. overflow: hidden;
  525. .grid-wrap-box {
  526. flex: 1;
  527. overflow: hidden;
  528. position: relative;
  529. margin: 8px 0 0 8px;
  530. .footer-tools-bar {
  531. position: absolute;
  532. bottom: 0;
  533. width: 100%;
  534. height: 30px;
  535. display: flex;
  536. justify-content: flex-end;
  537. align-items: center;
  538. z-index: 1000;
  539. background-color: var(--bs-background-2);
  540. .bs-select-wrap {
  541. margin-right: 16px;
  542. }
  543. .select-zoom-text {
  544. color: var(--bs-el-title);
  545. margin-right: 16px;
  546. }
  547. ::v-deep .el-select {
  548. width: 150px !important;
  549. }
  550. }
  551. }
  552. ::v-deep .el-loading-mask {
  553. background-color: transparent !important;
  554. }
  555. }
  556. }
  557. </style>