index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. this.$refs.Rules.initRuleHeight()
  414. },
  415. openDataViewDialog (config) {
  416. this.$refs.dataViewDialog.init(config)
  417. },
  418. /**
  419. * @description: 清空页面
  420. */
  421. empty () {
  422. this.$confirm('确定清空页面吗?', '提示', {
  423. confirmButtonText: '确定',
  424. cancelButtonText: '取消',
  425. type: 'warning',
  426. customClass: 'bs-el-message-box'
  427. })
  428. .then(() => {
  429. this.changeLayout([])
  430. this.resetPresetLine()
  431. this.saveTimeLine('清空画布')
  432. })
  433. .catch(() => {})
  434. },
  435. // 切换主题时针对远程组件触发样式修改的方法
  436. styleHandler (config) {
  437. this.$nextTick(() => {
  438. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  439. config.code
  440. ]?.changeStyle(cloneDeep(config), true)
  441. })
  442. },
  443. // 自定义属性更新
  444. updateSetting (config) {
  445. if (config.type === 'map' || config.type === 'screenScrollBoard' || config.type === 'remoteComponent' || config.type === 'video' || config.type === 'flyMap') {
  446. config.key = new Date().getTime()
  447. }
  448. this.changeChartConfig(cloneDeep(config))
  449. // 如果是tab内的组件
  450. if (config.parentCode) {
  451. const dom = this.$refs.Render?.$refs['RenderCard' + config.parentCode][0]?.$refs[config.parentCode]?.$refs['RenderCard' + config.code]?.$refs[config.code]
  452. if (dom) {
  453. dom?.changeStyle(cloneDeep(config))
  454. }
  455. } else {
  456. if (this.$refs.Render?.$refs['RenderCard' + config.code]) {
  457. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  458. config.code
  459. ]?.changeStyle(cloneDeep(config))
  460. }
  461. }
  462. },
  463. // 动态属性更新
  464. updateDataSetting (config) {
  465. config.key = new Date().getTime()
  466. this.changeChartConfig(config)
  467. },
  468. onSelectArea (area) {
  469. const { startX, startY, endX, endY } = area
  470. // 计算所有在此区域中的组件,如果在此区域中,将其code添加到activeCodes数组中
  471. const activeCodes = this.chartList
  472. ?.filter((chart) => {
  473. const { x, y, w, h } = chart
  474. return startX <= x && x + w <= endX && startY <= y && y + h <= endY
  475. })
  476. ?.map((chart) => chart.code)
  477. this.changeActiveCodes(activeCodes)
  478. },
  479. changeStart ({ x, y }) {
  480. this.ruleStartX = x
  481. this.ruleStartY = y
  482. },
  483. // 保存并预览
  484. saveAndPreview () {
  485. this.$refs.PageTopSetting.execRun()
  486. },
  487. // 保存
  488. save () {
  489. this.$refs.PageTopSetting.save('saveLoading')
  490. },
  491. changeScreenZoom (zoom) {
  492. // 自适应
  493. if (zoom === 'auto') {
  494. this.$refs.Rules.initZoom()
  495. } else {
  496. this.changeZoom(zoom)
  497. }
  498. },
  499. updateRightVisiable (visiable) {
  500. this.rightVisiable = visiable
  501. this.$refs.Rules.initRuleHeight()
  502. },
  503. toggleLeftSidebar () {
  504. this.$refs.Rules.initRuleHeight()
  505. },
  506. showPageInfo () {
  507. this.pageInfoVisiable = true
  508. this.rightVisiable = true
  509. this.changeActiveCode('')
  510. },
  511. // 页面信息更改
  512. updatePage () {
  513. this.$refs.Rules.initZoom()
  514. }
  515. }
  516. }
  517. </script>
  518. <style lang="scss" scoped>
  519. .bs-page-design-wrap {
  520. overflow: hidden;
  521. .drag-wrap {
  522. display: flex;
  523. background-color: #1d1e20;
  524. height: calc(100vh - 40px);
  525. overflow: hidden;
  526. .grid-wrap-box {
  527. flex: 1;
  528. overflow: hidden;
  529. position: relative;
  530. margin: 8px 0 0 8px;
  531. .footer-tools-bar {
  532. position: absolute;
  533. bottom: 0;
  534. width: 100%;
  535. height: 30px;
  536. display: flex;
  537. justify-content: flex-end;
  538. align-items: center;
  539. z-index: 1000;
  540. background-color: var(--bs-background-2);
  541. .bs-select-wrap {
  542. margin-right: 16px;
  543. }
  544. .select-zoom-text {
  545. color: var(--bs-el-title);
  546. margin-right: 16px;
  547. }
  548. ::v-deep .el-select {
  549. width: 150px !important;
  550. }
  551. }
  552. }
  553. ::v-deep .el-loading-mask {
  554. background-color: transparent !important;
  555. }
  556. }
  557. }
  558. </style>