index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. 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. res.chartList.forEach((item) => {
  300. if (!item.border) {
  301. item.border={type:'',titleHeight:60,fontSize:30,isTitle:true,padding:[0,0,0,0]}
  302. }
  303. if(!item.border.padding){
  304. item.border.padding=[0,0,0,0]
  305. }
  306. if (item.type == 'customComponent'){
  307. plotSettings[Symbol.iterator]=function*(){
  308. let keys=Object.keys(plotSettings)
  309. for(let k of keys){
  310. yield [k,plotSettings[k]]
  311. }
  312. }
  313. for(let [key,value] of plotSettings){
  314. if (item.name == value.name) {
  315. const settings=JSON.parse(JSON.stringify(value.setting))
  316. item.setting=settings.map((x)=>{
  317. const index=item.setting.findIndex(y=>y.field==x.field)
  318. x.field = item.setting[index].field
  319. x.value=item.setting[index].value
  320. return x
  321. })
  322. }
  323. }
  324. }
  325. })
  326. // 给组件库导入的组件加入统一的前缀
  327. const randomStr = randomString(8)
  328. const pageInfo = handleResData(res)
  329. const chartList = pageInfo.chartList.reverse()
  330. chartList.forEach((chart) => {
  331. // 如果组件存在数据联动,则将数据联动的code也加上相同的前缀
  332. if (chart.linkage && chart.linkage.components && chart.linkage.components.length) {
  333. chart.linkage.components.forEach((com) => { com.componentKey = randomStr + com.componentKey })
  334. }
  335. const newChart = {
  336. ...chart,
  337. offsetX: 0,
  338. group: randomStr,
  339. code: randomStr + chart.code
  340. }
  341. // 如果是从组件库中添加的自定义组件,则不需要初始化theme
  342. const isComponent = true
  343. this.$refs.Render.addChart(newChart, { x: chart.x, y: chart.y }, isComponent)
  344. this.updateRightVisiable(false)
  345. })
  346. })
  347. },
  348. // 添加远程组件
  349. setRemoteComponent (component) {
  350. const newChart = {
  351. ...component,
  352. offsetX: 0,
  353. offsetY: 0,
  354. code: randomString(8)
  355. }
  356. this.$refs.Render.addChart(newChart, { x: 0, y: 0 })
  357. },
  358. setImg (val) {
  359. this.$refs.Render.addSourceChart(
  360. JSON.stringify({
  361. title: val.originalName,
  362. name: val.originalName,
  363. icon: null,
  364. className:
  365. 'com.gccloud.dataroom.core.module.chart.components.ScreenPictureChart',
  366. w: 300,
  367. h: 300,
  368. x: 0,
  369. y: 0,
  370. type: 'picture',
  371. option: {
  372. ...cloneDeep(settingConfig)
  373. },
  374. setting: {}, // 右侧面板自定义配置
  375. dataHandler: {}, // 数据自定义处理js脚本
  376. ...cloneDeep(dataConfig),
  377. customize: {
  378. url: val.url,
  379. radius: 0,
  380. opacity: 100
  381. }
  382. }),
  383. { x: 150, y: 100 }
  384. )
  385. },
  386. init () {
  387. this.changePageLoading(true)
  388. this.initLayout(this.pageCode)
  389. .then(() => {
  390. this.changePageLoading(false)
  391. })
  392. .finally(() => {
  393. setTimeout(() => {
  394. this.resetPresetLine()
  395. }, 500)
  396. })
  397. },
  398. // 点击当前组件时打开右侧面板
  399. openRightPanel (card) {
  400. this.rightVisiable = true
  401. this.pageInfoVisiable = false
  402. },
  403. openDataViewDialog (config) {
  404. this.$refs.dataViewDialog.init(config)
  405. },
  406. /**
  407. * @description: 清空页面
  408. */
  409. empty () {
  410. this.$confirm('确定清空页面吗?', '提示', {
  411. confirmButtonText: '确定',
  412. cancelButtonText: '取消',
  413. type: 'warning',
  414. customClass: 'bs-el-message-box'
  415. })
  416. .then(() => {
  417. this.changeLayout([])
  418. this.resetPresetLine()
  419. this.saveTimeLine('清空画布')
  420. })
  421. .catch(() => {})
  422. },
  423. // 切换主题时针对远程组件触发样式修改的方法
  424. styleHandler (config) {
  425. this.$nextTick(() => {
  426. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  427. config.code
  428. ]?.changeStyle(cloneDeep(config), true)
  429. })
  430. },
  431. // 自定义属性更新
  432. updateSetting (config) {
  433. if (config.type === 'map' || config.type==='screenScrollBoard'|| config.type === 'remoteComponent' || config.type === 'video' || config.type === 'flyMap') {
  434. config.key = new Date().getTime()
  435. }
  436. this.changeChartConfig(cloneDeep(config))
  437. // 如果是tab内的组件
  438. if (config.parentCode) {
  439. const dom = this.$refs.Render?.$refs['RenderCard' + config.parentCode][0]?.$refs[config.parentCode]?.$refs['RenderCard' + config.code]?.$refs[config.code]
  440. if (dom) {
  441. dom?.changeStyle(cloneDeep(config))
  442. }
  443. } else {
  444. if (this.$refs.Render?.$refs['RenderCard' + config.code]) {
  445. this.$refs.Render?.$refs['RenderCard' + config.code][0]?.$refs[
  446. config.code
  447. ]?.changeStyle(cloneDeep(config))
  448. }
  449. }
  450. },
  451. // 动态属性更新
  452. updateDataSetting (config) {
  453. config.key = new Date().getTime()
  454. this.changeChartConfig(config)
  455. },
  456. onSelectArea (area) {
  457. const { startX, startY, endX, endY } = area
  458. // 计算所有在此区域中的组件,如果在此区域中,将其code添加到activeCodes数组中
  459. const activeCodes = this.chartList
  460. ?.filter((chart) => {
  461. const { x, y, w, h } = chart
  462. return startX <= x && x + w <= endX && startY <= y && y + h <= endY
  463. })
  464. ?.map((chart) => chart.code)
  465. this.changeActiveCodes(activeCodes)
  466. },
  467. changeStart ({ x, y }) {
  468. this.ruleStartX = x
  469. this.ruleStartY = y
  470. },
  471. // 保存并预览
  472. saveAndPreview () {
  473. this.$refs.PageTopSetting.execRun()
  474. },
  475. // 保存
  476. save () {
  477. this.$refs.PageTopSetting.save('saveLoading')
  478. },
  479. changeScreenZoom (zoom) {
  480. // 自适应
  481. if (zoom === 'auto') {
  482. this.$refs.Rules.initZoom()
  483. } else {
  484. this.changeZoom(zoom)
  485. }
  486. },
  487. updateRightVisiable (visiable) {
  488. this.rightVisiable = visiable
  489. this.$refs.Rules.initRuleHeight()
  490. },
  491. toggleLeftSidebar () {
  492. this.$refs.Rules.initRuleHeight()
  493. },
  494. showPageInfo () {
  495. this.pageInfoVisiable = true
  496. this.rightVisiable = true
  497. this.changeActiveCode('')
  498. },
  499. // 页面信息更改
  500. updatePage () {
  501. this.$refs.Rules.initZoom()
  502. }
  503. }
  504. }
  505. </script>
  506. <style lang="scss" scoped>
  507. .bs-page-design-wrap {
  508. overflow: hidden;
  509. .drag-wrap {
  510. display: flex;
  511. background-color: #1d1e20;
  512. height: calc(100vh - 40px);
  513. overflow: hidden;
  514. .grid-wrap-box {
  515. flex: 1;
  516. overflow: hidden;
  517. position: relative;
  518. margin: 8px 0 0 8px;
  519. .footer-tools-bar {
  520. position: absolute;
  521. bottom: 0;
  522. width: 100%;
  523. height: 30px;
  524. display: flex;
  525. justify-content: flex-end;
  526. align-items: center;
  527. z-index: 1000;
  528. background-color: var(--bs-background-2);
  529. .bs-select-wrap {
  530. margin-right: 16px;
  531. }
  532. .select-zoom-text {
  533. color: var(--bs-el-title);
  534. margin-right: 16px;
  535. }
  536. ::v-deep .el-select {
  537. width: 150px !important;
  538. }
  539. }
  540. }
  541. ::v-deep .el-loading-mask {
  542. background-color: transparent !important;
  543. }
  544. }
  545. }
  546. </style>