index.vue 16 KB

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