PageDesignTop.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <template>
  2. <div class="page-top-setting-wrap">
  3. <div class="logo-wrap item-wrap">
  4. <img
  5. class="menu-img"
  6. src="../BigScreenDesign/images/app.png"
  7. alt="返回"
  8. @click="goBackManage"
  9. >
  10. <span class="logo-text name-span">{{ pageInfo.name }}</span>
  11. </div>
  12. <div class="head-btn-group">
  13. <span style="margin-right:8px;font-size:12px">缩放比例</span>
  14. <el-input-number
  15. class="bs-el-input-number"
  16. style="margin-right:20px"
  17. :value="zoom"
  18. :min="1"
  19. :max="100"
  20. label="描述文字"
  21. @change="changeZoom"
  22. />
  23. <el-dropdown
  24. trigger="click"
  25. class="align-list-dropdown"
  26. >
  27. <CusBtn
  28. type="primary"
  29. >
  30. 对齐方式<i class="el-icon-arrow-down el-icon--right" />
  31. </CusBtn>
  32. <el-dropdown-menu
  33. slot="dropdown"
  34. class="align-dropdown-menu"
  35. >
  36. <el-dropdown-item
  37. v-for="(mode,index) in alignList"
  38. :key="mode.value"
  39. @click.native="setAlign(mode.value)"
  40. >
  41. <icon-svg
  42. style="padding:3px 8px"
  43. :name="iconList[index]"
  44. />
  45. <span style="color: #bcc9d4">{{ mode.label }}</span>
  46. </el-dropdown-item>
  47. </el-dropdown-menu>
  48. </el-dropdown>
  49. <CusBtn
  50. :loading="saveAndPreviewLoading"
  51. @click.native="designAssign()"
  52. >
  53. 设计分工
  54. </CusBtn>
  55. <CusBtn
  56. @click.native="showHostory"
  57. >
  58. 历史操作
  59. </CusBtn>
  60. <CusBtn
  61. :disabled="undoDisabled"
  62. @click.native="undo(true)"
  63. >
  64. <i class="iconfont-bigscreen icon-jiantouqianjin icon-reverse" />
  65. </CusBtn>
  66. <CusBtn
  67. :disabled="redoDisabled"
  68. @click.native="undo(false)"
  69. >
  70. <i class="iconfont-bigscreen icon-jiantouqianjin" />
  71. </CusBtn>
  72. <CusBtn
  73. :loading="saveAndPreviewLoading"
  74. @click.native="createdImg()"
  75. >
  76. 生成图片
  77. </CusBtn>
  78. <CusBtn
  79. :loading="saveAndPreviewLoading"
  80. @click.native="execRun()"
  81. >
  82. 预览
  83. </CusBtn>
  84. <CusBtn
  85. :loading="saveLoading"
  86. @click="save('saveLoading')"
  87. >
  88. 保存
  89. </CusBtn>
  90. <CusBtn @click="empty">
  91. 清空
  92. </CusBtn>
  93. <CusBtn @click="showPageInfo">
  94. 设置
  95. </CusBtn>
  96. <CusBtn @click="updateRightVisiable">
  97. <i
  98. class="iconfont-bigscreen"
  99. :class="rightFold ? 'icon-zhankaicaidan' : 'icon-shouqicaidan'"
  100. />
  101. </CusBtn>
  102. </div>
  103. <ChooseTemplateDialog
  104. ref="ChooseTemplateDialog"
  105. :has-create="false"
  106. :page-info="pageInfo"
  107. @replaceItByTemplate="replaceItByTemplate"
  108. />
  109. <CloseDialog
  110. ref="CloseDialog"
  111. @back="backManagement"
  112. @backSave="backSave"
  113. />
  114. <AssignDialog ref="AssignDialog" />
  115. <HistoryList ref="HistoryList" />
  116. </div>
  117. </template>
  118. <script>
  119. import { EventBus } from 'data-room-ui/js/utils/eventBus'
  120. import { toJpeg, toPng } from 'html-to-image'
  121. import { mapMutations, mapActions, mapState } from 'vuex'
  122. import { saveScreen } from 'data-room-ui/js/api/bigScreenApi'
  123. import ChooseTemplateDialog from 'data-room-ui/BigScreenManagement/ChooseTemplateDialog.vue'
  124. // import _ from 'lodash'
  125. import cloneDeep from 'lodash/cloneDeep'
  126. import uniqBy from 'lodash/uniqBy'
  127. import { stringifyObjectFunctions } from 'data-room-ui/js/utils/evalFunctions'
  128. import AssignDialog from 'data-room-ui/BigScreenDesign/AssignDialog/index.vue'
  129. import CloseDialog from 'data-room-ui/BigScreenDesign/CloseDialog/index.vue'
  130. import HistoryList from 'data-room-ui/BigScreenDesign/HistoryList/index.vue'
  131. import CusBtn from './BtnLoading'
  132. import icons from 'data-room-ui/assets/images/alignIcon/export'
  133. import IconSvg from 'data-room-ui/SvgIcon'
  134. import {
  135. showSize,
  136. dataURLtoBlob,
  137. translateBlobToBase64
  138. } from 'data-room-ui/js/utils/compressImg'
  139. import * as imageConversion from 'image-conversion'
  140. export default {
  141. name: 'PageTopSetting',
  142. components: {
  143. IconSvg,
  144. ChooseTemplateDialog,
  145. AssignDialog,
  146. CusBtn,
  147. HistoryList,
  148. CloseDialog
  149. },
  150. props: {
  151. code: {
  152. type: String,
  153. default: ''
  154. },
  155. rightFold: {
  156. type: Boolean,
  157. default: false
  158. }
  159. },
  160. data () {
  161. return {
  162. iconList: icons.getNameList(),
  163. alignList: [
  164. {
  165. label: '左侧对齐',
  166. value: 'left'
  167. },
  168. {
  169. label: '居中对齐',
  170. value: 'center'
  171. },
  172. {
  173. label: '右侧对齐',
  174. value: 'right'
  175. },
  176. {
  177. label: '顶部对齐',
  178. value: 'top'
  179. },
  180. {
  181. label: '中部对齐',
  182. value: 'middle'
  183. },
  184. {
  185. label: '底部对齐',
  186. value: 'bottom'
  187. },
  188. {
  189. label: '水平均分',
  190. value: 'levelAround'
  191. },
  192. {
  193. label: '垂直均分',
  194. value: 'verticalAround'
  195. }
  196. ],
  197. appInfo: '',
  198. saveLoading: false,
  199. createdImgLoading: false,
  200. saveAndPreviewLoading: false
  201. }
  202. },
  203. computed: {
  204. ...mapState({
  205. pageInfo: (state) => state.bigScreen.pageInfo,
  206. timelineStore: (state) => state.bigScreen.timelineStore,
  207. currentTimeLine: (state) => state.bigScreen.currentTimeLine,
  208. activeCodes: state => state.bigScreen.activeCodes,
  209. zoom: (state) => state.bigScreen.zoom
  210. }),
  211. pageCode () {
  212. return this.$route.query.code || this.code
  213. },
  214. undoDisabled () {
  215. return Boolean(this.currentTimeLine <= 1)
  216. },
  217. redoDisabled () {
  218. return Boolean(
  219. !this.timelineStore?.length ||
  220. (
  221. this.currentTimeLine &&
  222. this.currentTimeLine === this.timelineStore?.length
  223. )
  224. )
  225. }
  226. },
  227. methods: {
  228. ...mapActions({
  229. initLayout: 'bigScreen/initLayout'
  230. }),
  231. ...mapMutations({
  232. changeActiveCode: 'bigScreen/changeActiveCode',
  233. changeActiveItem: 'bigScreen/changeActiveItem',
  234. changePageInfo: 'bigScreen/changePageInfo',
  235. undoTimeLine: 'bigScreen/undoTimeLine',
  236. saveTimeLine: 'bigScreen/saveTimeLine'
  237. }),
  238. changeZoom (val) {
  239. this.$emit('changeZoom', val)
  240. // console.log(val)
  241. },
  242. // 切换主题
  243. changeTheme (val) {
  244. // 调取每个组件内部切换主题的方法
  245. this.$emit('updateTheme', val)
  246. },
  247. setAlign (command) {
  248. const pageInfo = cloneDeep(this.pageInfo)
  249. // 获取所有选中的组件
  250. let activeChartList = pageInfo.chartList.filter((chart) => {
  251. return this.activeCodes.some(code => (code === chart.code))
  252. })
  253. // 找到选中组件内的xy最大最小值
  254. const maxXW = Math.max.apply(Math, activeChartList.map(item => { return item.x + item.w }))
  255. let maxX = Math.max.apply(Math, activeChartList.map(item => { return item.x }))
  256. const minX = Math.min.apply(Math, activeChartList.map(item => { return item.x }))
  257. const maxYH = Math.max.apply(Math, activeChartList.map(item => { return item.y + item.h }))
  258. const maxY = Math.max.apply(Math, activeChartList.map(item => { return item.y }))
  259. const minY = Math.min.apply(Math, activeChartList.map(item => { return item.y }))
  260. const centerW = maxXW - minX
  261. const centerH = maxY - minY
  262. switch (command) {
  263. case 'left':
  264. activeChartList.forEach((chart) => {
  265. chart.x = minX
  266. })
  267. break
  268. case 'center':
  269. // eslint-disable-next-line no-case-declarations
  270. activeChartList.forEach((chart) => {
  271. chart.x = (centerW - chart.w) / 2 + minX
  272. })
  273. break
  274. case 'right':
  275. activeChartList.forEach((chart) => {
  276. chart.x = maxXW - chart.w
  277. })
  278. break
  279. case 'top':
  280. activeChartList.forEach((chart) => {
  281. chart.y = minY
  282. })
  283. break
  284. case 'middle':
  285. activeChartList.forEach((chart) => {
  286. chart.y = (centerH - chart.h) / 2 + minY
  287. })
  288. break
  289. case 'bottom':
  290. activeChartList.forEach((chart) => {
  291. chart.y = maxYH - chart.h
  292. })
  293. break
  294. case 'levelAround':
  295. // 先让数组根据x的属性进行排序
  296. activeChartList = activeChartList.sort(this.compare('x'))
  297. // eslint-disable-next-line no-case-declarations
  298. const minXW = activeChartList[0].x + activeChartList[0].w
  299. maxX = Math.max.apply(Math, activeChartList.map(item => { return item.x }))
  300. // 中间总的宽度
  301. // eslint-disable-next-line no-case-declarations
  302. let totalW = 0
  303. for (let i = 1; i < activeChartList.length - 1; i++) {
  304. totalW = totalW + activeChartList[i].w
  305. }
  306. // 中间剩余的空格
  307. // eslint-disable-next-line no-case-declarations
  308. const padding = (maxX - minXW - totalW) / (activeChartList.length - 1)
  309. // eslint-disable-next-line no-case-declarations
  310. let useW = 0
  311. for (let i = 1; i < activeChartList.length - 1; i++) {
  312. activeChartList[i].x = minXW + padding * i + useW
  313. useW = useW + activeChartList[i].w
  314. }
  315. break
  316. case 'verticalAround':
  317. // 先让数组根据y的属性进行排序
  318. activeChartList = activeChartList.sort(this.compare('y'))
  319. // eslint-disable-next-line no-case-declarations
  320. const minYH = activeChartList[0].y + activeChartList[0].h
  321. // eslint-disable-next-line no-case-declarations
  322. let totalH = 0
  323. for (let i = 1; i < activeChartList.length - 1; i++) {
  324. totalH = totalH + activeChartList[i].h
  325. }
  326. // eslint-disable-next-line no-case-declarations
  327. const paddingBottom = (maxY - minYH - totalH) / (activeChartList.length - 1)
  328. // eslint-disable-next-line no-case-declarations
  329. let useH = 0
  330. for (let i = 1; i < activeChartList.length - 1; i++) {
  331. activeChartList[i].y = minYH + paddingBottom * i + useH
  332. useH = useH + activeChartList[i].h
  333. }
  334. break
  335. }
  336. pageInfo.chartList = [...pageInfo.chartList, ...activeChartList]
  337. pageInfo.chartList = uniqBy(pageInfo.chartList, 'code')
  338. this.changePageInfo(pageInfo)
  339. },
  340. compare (property) {
  341. return function (obj1, obj2) {
  342. const value1 = obj1[property]
  343. const value2 = obj2[property]
  344. return value1 - value2 // 升序
  345. }
  346. },
  347. goBackManage () {
  348. this.$refs.CloseDialog.init()
  349. },
  350. async backSave () {
  351. await this.save()
  352. this.backManagement()
  353. },
  354. backManagement () {
  355. this.$router.push({ path: this.pageInfo.type === 'component' ? (window.BS_CONFIG?.routers?.componentUrl || '/big-screen-components') : (window.BS_CONFIG?.routers?.pageManagementUrl || '/home') })
  356. const data = { componentsManagementType: 'component' }
  357. this.$router.app.$options.globalData = data // 将数据存储在全局变量中
  358. },
  359. undo (isUndo) {
  360. this.undoTimeLine(isUndo)
  361. },
  362. // 清空
  363. empty () {
  364. this.changeActiveCode('')
  365. this.$emit('empty')
  366. },
  367. // 预览
  368. async execRun () {
  369. this.save('saveAndPreviewLoading').then((res) => {
  370. this.preview()
  371. })
  372. },
  373. // 预览
  374. preview () {
  375. const { href } = this.$router.resolve({
  376. path: window.BS_CONFIG?.routers?.previewUrl || '/big-screen/preview',
  377. query: {
  378. code: this.pageCode
  379. }
  380. })
  381. window.open(href, '_blank')
  382. },
  383. // 保存
  384. save (loadingType = 'saveLoading', hasPageTemplateId = false) {
  385. const pageInfo = cloneDeep(this.handleSaveData())
  386. // 保存页面
  387. this[loadingType] = true
  388. return new Promise((resolve, reject) => {
  389. if (!hasPageTemplateId) {
  390. delete pageInfo.pageTemplateId
  391. }
  392. const node = document.querySelector('.render-theme-wrap')
  393. toJpeg(node, { quality: 0.2 })
  394. .then((dataUrl) => {
  395. const that = this
  396. if (showSize(dataUrl) > 200) {
  397. const url = dataURLtoBlob(dataUrl)
  398. // 压缩到500KB,这里的500就是要压缩的大小,可自定义
  399. imageConversion
  400. .compressAccurately(url, {
  401. size: 200, // 图片大小压缩到100kb
  402. width: 1280, // 宽度压缩到1280
  403. height: 720 // 高度压缩到720
  404. })
  405. .then((res) => {
  406. translateBlobToBase64(res, function (e) {
  407. pageInfo.coverPicture = e.result
  408. saveScreen(pageInfo)
  409. .then((res) => {
  410. that.$message.success('保存成功')
  411. resolve(res)
  412. })
  413. .finally(() => {
  414. that[loadingType] = false
  415. })
  416. })
  417. })
  418. } else {
  419. pageInfo.coverPicture = dataUrl
  420. saveScreen(pageInfo)
  421. .then((res) => {
  422. this.$message.success('保存成功')
  423. resolve(res)
  424. })
  425. .finally(() => {
  426. this[loadingType] = false
  427. })
  428. }
  429. })
  430. .catch(() => {
  431. this[loadingType] = false
  432. })
  433. })
  434. },
  435. goBack (path) {
  436. this.$router.push({
  437. path: `/${path}`
  438. })
  439. },
  440. // 得到模板列表
  441. getTemplateList (type) {
  442. this.$nextTick(() => {
  443. this.$refs.ChooseTemplateDialog.init(undefined, type)
  444. })
  445. },
  446. // 选择模版后覆盖配置
  447. selectTemplate (template) {
  448. this.pageInfo.pageTemplateId = template.id
  449. this.save('saveLoading', true).then(() => {
  450. this.initLayout(this.pageCode)
  451. })
  452. },
  453. replaceItByTemplate (config) {
  454. this.changePageInfo(config)
  455. },
  456. // 处理保存数据
  457. handleSaveData () {
  458. const pageInfo = cloneDeep(this.pageInfo)
  459. const chartList = cloneDeep(this.pageInfo.chartList)
  460. pageInfo.pageConfig.cacheDataSets =
  461. pageInfo.pageConfig.cacheDataSets?.map((cache) => ({
  462. name: cache.name,
  463. dataSetId: cache.dataSetId
  464. })) || []
  465. const newChartList = chartList?.map((chart) => {
  466. // 如果是自定义组件,需要将option转换为json字符串,因为其中可能有函数
  467. if (['customComponent', 'remoteComponent'].includes(chart.type)) {
  468. chart.option.data = []
  469. chart.option = stringifyObjectFunctions(chart.option)
  470. }
  471. return chart
  472. })
  473. return cloneDeep({
  474. ...this.pageInfo,
  475. chartList: newChartList
  476. })
  477. },
  478. updateRightVisiable () {
  479. this.$emit('updateRightVisiable', !this.rightFold)
  480. },
  481. showPageInfo () {
  482. this.$emit('showPageInfo')
  483. },
  484. designAssign () {
  485. this.$refs.AssignDialog.init()
  486. },
  487. showHostory () {
  488. this.$refs.HistoryList.init()
  489. },
  490. createdImg () {
  491. this.saveAndPreviewLoading = true
  492. // 暂停跑马灯动画
  493. EventBus.$emit('stopMarquee')
  494. const node = document.querySelector('.render-theme-wrap')
  495. toPng(node)
  496. .then((dataUrl) => {
  497. const link = document.createElement('a')
  498. link.download = `${this.pageInfo.name}.png`
  499. link.href = dataUrl
  500. link.click()
  501. link.addEventListener('click', () => {
  502. link.remove()
  503. })
  504. this.saveAndPreviewLoading = false
  505. // 恢复跑马灯动画
  506. EventBus.$emit('startMarquee')
  507. })
  508. .catch(() => {
  509. this.$message.warning('出现未知错误,请重试')
  510. this.saveAndPreviewLoading = false
  511. })
  512. }
  513. }
  514. }
  515. </script>
  516. <style lang="scss" scoped>
  517. @import '../BigScreenDesign/fonts/iconfont.css';
  518. .default-layout-box {
  519. display: flex;
  520. flex-wrap: wrap;
  521. .default-layout-item {
  522. cursor: pointer;
  523. width: 42%;
  524. margin: 9px;
  525. display: flex;
  526. flex-direction: column;
  527. align-items: center;
  528. .component-name {
  529. font-size: 12px;
  530. }
  531. .sampleImg {
  532. margin: 0 auto;
  533. width: 102px;
  534. height: 73px;
  535. display: block;
  536. }
  537. .img_dispaly {
  538. margin: 0 auto;
  539. text-align: center;
  540. width: 100px;
  541. height: 70px;
  542. line-height: 70px;
  543. background-color: #d7d7d7;
  544. color: #999;
  545. }
  546. .demonstration {
  547. text-align: center;
  548. }
  549. }
  550. .default-layout-item:hover {
  551. cursor: pointer;
  552. }
  553. ::v-deep .el-radio__label {
  554. display: none;
  555. }
  556. }
  557. .page-top-setting-wrap {
  558. height: 40px;
  559. background-color: var(--bs-background-2);
  560. display: flex;
  561. align-items: center;
  562. justify-content: space-between;
  563. position: relative;
  564. color: #ffffff;
  565. padding: 0 5px;
  566. .app-name {
  567. cursor: pointer;
  568. }
  569. .head-btn-group {
  570. display: flex;
  571. margin-left: 50px;
  572. align-items: center;
  573. i {
  574. font-size: 14px;
  575. }
  576. .icon-reverse {
  577. transform: rotate(180deg);
  578. }
  579. }
  580. .item-wrap {
  581. display: flex;
  582. align-items: center;
  583. .menu-img {
  584. width: 18px;
  585. height: 18px;
  586. margin-left: 9px;
  587. margin-right: 15px;
  588. cursor: pointer;
  589. }
  590. .logo-text {
  591. user-select: none;
  592. margin-left: 9px;
  593. font-size: 14px;
  594. color: #ffffff;
  595. }
  596. .name-span {
  597. max-width: 300px;
  598. overflow: hidden;
  599. white-space: nowrap;
  600. text-overflow: ellipsis;
  601. }
  602. }
  603. .theme-switch{
  604. margin-right: 10px;
  605. /deep/.el-switch__label{
  606. color: #bcc9d4!important;
  607. }
  608. /deep/.el-switch__label.is-active{
  609. color: var(--bs-el-color-primary)!important;
  610. }
  611. }
  612. .align-list-dropdown{
  613. width: 100px !important;
  614. color: #ffffff!important;
  615. }
  616. }
  617. // 自定义dropdown的样式
  618. .align-dropdown-menu{
  619. background-color: var(--bs-background-2)!important;
  620. border: 1px solid var(--bs-border-1);
  621. /deep/ .el-dropdown-menu__item{
  622. background-color: var(--bs-background-2)!important;
  623. &:hover {
  624. color: var(--bs-el-color-primary) !important;
  625. background-color: var(--bs-el-background-3) !important;
  626. }
  627. }
  628. }
  629. ::v-deep .el-input__inner,
  630. ::v-deep .el-color-picker__color-inner,
  631. ::v-deep .el-input-number--mini,
  632. ::v-deep .el-textarea__inner,
  633. ::v-deep .el-input-group__append {
  634. background: var(--bs-el-background-1);
  635. color: var(--bs-el-text);
  636. border: 0 !important;
  637. }
  638. </style>