index.vue 15 KB

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