PageDesignTop.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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. setAlign (command) {
  243. const pageInfo = cloneDeep(this.pageInfo)
  244. // 获取所有选中的组件
  245. let activeChartList = pageInfo.chartList.filter((chart) => {
  246. return this.activeCodes.some(code => (code === chart.code))
  247. })
  248. // 找到选中组件内的xy最大最小值
  249. const maxXW = Math.max.apply(Math, activeChartList.map(item => { return item.x + item.w }))
  250. let maxX = Math.max.apply(Math, activeChartList.map(item => { return item.x }))
  251. const minX = Math.min.apply(Math, activeChartList.map(item => { return item.x }))
  252. const maxYH = Math.max.apply(Math, activeChartList.map(item => { return item.y + item.h }))
  253. const maxY = Math.max.apply(Math, activeChartList.map(item => { return item.y }))
  254. const minY = Math.min.apply(Math, activeChartList.map(item => { return item.y }))
  255. const centerW = maxXW - minX
  256. const centerH = maxY - minY
  257. switch (command) {
  258. case 'left':
  259. activeChartList.forEach((chart) => {
  260. chart.x = minX
  261. })
  262. break
  263. case 'center':
  264. // eslint-disable-next-line no-case-declarations
  265. activeChartList.forEach((chart) => {
  266. chart.x = (centerW - chart.w) / 2 + minX
  267. })
  268. break
  269. case 'right':
  270. activeChartList.forEach((chart) => {
  271. chart.x = maxXW - chart.w
  272. })
  273. break
  274. case 'top':
  275. activeChartList.forEach((chart) => {
  276. chart.y = minY
  277. })
  278. break
  279. case 'middle':
  280. activeChartList.forEach((chart) => {
  281. chart.y = (centerH - chart.h) / 2 + minY
  282. })
  283. break
  284. case 'bottom':
  285. activeChartList.forEach((chart) => {
  286. chart.y = maxYH - chart.h
  287. })
  288. break
  289. case 'levelAround':
  290. // 先让数组根据x的属性进行排序
  291. activeChartList = activeChartList.sort(this.compare('x'))
  292. // eslint-disable-next-line no-case-declarations
  293. const minXW = activeChartList[0].x + activeChartList[0].w
  294. maxX = Math.max.apply(Math, activeChartList.map(item => { return item.x }))
  295. // 中间总的宽度
  296. // eslint-disable-next-line no-case-declarations
  297. let totalW = 0
  298. for (let i = 1; i < activeChartList.length - 1; i++) {
  299. totalW = totalW + activeChartList[i].w
  300. }
  301. // 中间剩余的空格
  302. // eslint-disable-next-line no-case-declarations
  303. const padding = (maxX - minXW - totalW) / (activeChartList.length - 1)
  304. // eslint-disable-next-line no-case-declarations
  305. let useW = 0
  306. for (let i = 1; i < activeChartList.length - 1; i++) {
  307. activeChartList[i].x = minXW + padding * i + useW
  308. useW = useW + activeChartList[i].w
  309. }
  310. break
  311. case 'verticalAround':
  312. // 先让数组根据y的属性进行排序
  313. activeChartList = activeChartList.sort(this.compare('y'))
  314. // eslint-disable-next-line no-case-declarations
  315. const minYH = activeChartList[0].y + activeChartList[0].h
  316. // eslint-disable-next-line no-case-declarations
  317. let totalH = 0
  318. for (let i = 1; i < activeChartList.length - 1; i++) {
  319. totalH = totalH + activeChartList[i].h
  320. }
  321. // eslint-disable-next-line no-case-declarations
  322. const paddingBottom = (maxY - minYH - totalH) / (activeChartList.length - 1)
  323. // eslint-disable-next-line no-case-declarations
  324. let useH = 0
  325. for (let i = 1; i < activeChartList.length - 1; i++) {
  326. activeChartList[i].y = minYH + paddingBottom * i + useH
  327. useH = useH + activeChartList[i].h
  328. }
  329. break
  330. }
  331. pageInfo.chartList = [...pageInfo.chartList, ...activeChartList]
  332. pageInfo.chartList = uniqBy(pageInfo.chartList, 'code')
  333. this.changePageInfo(pageInfo)
  334. },
  335. compare (property) {
  336. return function (obj1, obj2) {
  337. const value1 = obj1[property]
  338. const value2 = obj2[property]
  339. return value1 - value2 // 升序
  340. }
  341. },
  342. goBackManage () {
  343. this.$refs.CloseDialog.init()
  344. },
  345. async backSave () {
  346. await this.save()
  347. this.backManagement()
  348. },
  349. backManagement () {
  350. this.$router.push({ path: this.pageInfo.type === 'component' ? (window.BS_CONFIG?.routers?.componentUrl || '/big-screen-components') : (window.BS_CONFIG?.routers?.pageManagementUrl || '/home') })
  351. const data = { componentsManagementType: 'component' }
  352. this.$router.app.$options.globalData = data // 将数据存储在全局变量中
  353. },
  354. undo (isUndo) {
  355. this.undoTimeLine(isUndo)
  356. },
  357. // 清空
  358. empty () {
  359. this.changeActiveCode('')
  360. this.$emit('empty')
  361. },
  362. // 预览
  363. async execRun () {
  364. this.save('saveAndPreviewLoading').then((res) => {
  365. this.preview()
  366. })
  367. },
  368. // 预览
  369. preview () {
  370. const { href } = this.$router.resolve({
  371. path: window.BS_CONFIG?.routers?.previewUrl || '/big-screen/preview',
  372. query: {
  373. code: this.pageCode
  374. }
  375. })
  376. window.open(href, '_blank')
  377. },
  378. // 保存
  379. save (loadingType = 'saveLoading', hasPageTemplateId = false) {
  380. const pageInfo = cloneDeep(this.handleSaveData())
  381. // 保存页面
  382. this[loadingType] = true
  383. return new Promise((resolve, reject) => {
  384. if (!hasPageTemplateId) {
  385. delete pageInfo.pageTemplateId
  386. }
  387. const node = document.querySelector('.render-theme-wrap')
  388. toJpeg(node, { quality: 0.2 })
  389. .then((dataUrl) => {
  390. const that = this
  391. if (showSize(dataUrl) > 200) {
  392. const url = dataURLtoBlob(dataUrl)
  393. // 压缩到500KB,这里的500就是要压缩的大小,可自定义
  394. imageConversion
  395. .compressAccurately(url, {
  396. size: 200, // 图片大小压缩到100kb
  397. width: 1280, // 宽度压缩到1280
  398. height: 720 // 高度压缩到720
  399. })
  400. .then((res) => {
  401. translateBlobToBase64(res, function (e) {
  402. pageInfo.coverPicture = e.result
  403. saveScreen(pageInfo)
  404. .then((res) => {
  405. that.$message.success('保存成功')
  406. resolve(res)
  407. })
  408. .finally(() => {
  409. that[loadingType] = false
  410. })
  411. })
  412. })
  413. } else {
  414. pageInfo.coverPicture = dataUrl
  415. saveScreen(pageInfo)
  416. .then((res) => {
  417. this.$message.success('保存成功')
  418. resolve(res)
  419. })
  420. .finally(() => {
  421. this[loadingType] = false
  422. })
  423. }
  424. })
  425. .catch(() => {
  426. this[loadingType] = false
  427. })
  428. })
  429. },
  430. goBack (path) {
  431. this.$router.push({
  432. path: `/${path}`
  433. })
  434. },
  435. // 得到模板列表
  436. getTemplateList (type) {
  437. this.$nextTick(() => {
  438. this.$refs.ChooseTemplateDialog.init(undefined, type)
  439. })
  440. },
  441. // 选择模版后覆盖配置
  442. selectTemplate (template) {
  443. this.pageInfo.pageTemplateId = template.id
  444. this.save('saveLoading', true).then(() => {
  445. this.initLayout(this.pageCode)
  446. })
  447. },
  448. replaceItByTemplate (config) {
  449. this.changePageInfo(config)
  450. },
  451. // 处理保存数据
  452. handleSaveData () {
  453. const pageInfo = cloneDeep(this.pageInfo)
  454. const chartList = cloneDeep(this.pageInfo.chartList)
  455. pageInfo.pageConfig.cacheDataSets =
  456. pageInfo.pageConfig.cacheDataSets?.map((cache) => ({
  457. name: cache.name,
  458. dataSetId: cache.dataSetId
  459. })) || []
  460. const newChartList = chartList?.map((chart) => {
  461. // 如果是自定义组件,需要将option转换为json字符串,因为其中可能有函数
  462. if (['customComponent', 'remoteComponent'].includes(chart.type)) {
  463. // chart.option.data = []
  464. chart.option = stringifyObjectFunctions(chart.option)
  465. }
  466. return chart
  467. })
  468. return cloneDeep({
  469. ...this.pageInfo,
  470. chartList: newChartList
  471. })
  472. },
  473. updateRightVisiable () {
  474. this.$emit('updateRightVisiable', !this.rightFold)
  475. },
  476. showPageInfo () {
  477. this.$emit('showPageInfo')
  478. },
  479. designAssign () {
  480. this.$refs.AssignDialog.init()
  481. },
  482. showHostory () {
  483. this.$refs.HistoryList.init()
  484. },
  485. createdImg () {
  486. this.saveAndPreviewLoading = true
  487. // 暂停跑马灯动画
  488. EventBus.$emit('stopMarquee')
  489. const node = document.querySelector('.render-theme-wrap')
  490. toPng(node)
  491. .then((dataUrl) => {
  492. const link = document.createElement('a')
  493. link.download = `${this.pageInfo.name}.png`
  494. link.href = dataUrl
  495. link.click()
  496. link.addEventListener('click', () => {
  497. link.remove()
  498. })
  499. this.saveAndPreviewLoading = false
  500. // 恢复跑马灯动画
  501. EventBus.$emit('startMarquee')
  502. })
  503. .catch(() => {
  504. this.$message.warning('出现未知错误,请重试')
  505. this.saveAndPreviewLoading = false
  506. })
  507. }
  508. }
  509. }
  510. </script>
  511. <style lang="scss" scoped>
  512. @import '../BigScreenDesign/fonts/iconfont.css';
  513. .default-layout-box {
  514. display: flex;
  515. flex-wrap: wrap;
  516. .default-layout-item {
  517. cursor: pointer;
  518. width: 42%;
  519. margin: 9px;
  520. display: flex;
  521. flex-direction: column;
  522. align-items: center;
  523. .component-name {
  524. font-size: 12px;
  525. }
  526. .sampleImg {
  527. margin: 0 auto;
  528. width: 102px;
  529. height: 73px;
  530. display: block;
  531. }
  532. .img_dispaly {
  533. margin: 0 auto;
  534. text-align: center;
  535. width: 100px;
  536. height: 70px;
  537. line-height: 70px;
  538. background-color: #d7d7d7;
  539. color: #999;
  540. }
  541. .demonstration {
  542. text-align: center;
  543. }
  544. }
  545. .default-layout-item:hover {
  546. cursor: pointer;
  547. }
  548. ::v-deep .el-radio__label {
  549. display: none;
  550. }
  551. }
  552. .page-top-setting-wrap {
  553. height: 40px;
  554. background-color: var(--bs-background-2);
  555. display: flex;
  556. align-items: center;
  557. justify-content: space-between;
  558. position: relative;
  559. color: #ffffff;
  560. padding: 0 5px;
  561. .app-name {
  562. cursor: pointer;
  563. }
  564. .head-btn-group {
  565. display: flex;
  566. margin-left: 50px;
  567. align-items: center;
  568. i {
  569. font-size: 14px;
  570. }
  571. .icon-reverse {
  572. transform: rotate(180deg);
  573. }
  574. }
  575. .item-wrap {
  576. display: flex;
  577. align-items: center;
  578. .menu-img {
  579. width: 18px;
  580. height: 18px;
  581. margin-left: 9px;
  582. margin-right: 15px;
  583. cursor: pointer;
  584. }
  585. .logo-text {
  586. user-select: none;
  587. margin-left: 9px;
  588. font-size: 14px;
  589. color: #ffffff;
  590. }
  591. .name-span {
  592. max-width: 300px;
  593. overflow: hidden;
  594. white-space: nowrap;
  595. text-overflow: ellipsis;
  596. }
  597. }
  598. .theme-switch{
  599. margin-right: 10px;
  600. /deep/.el-switch__label{
  601. color: #bcc9d4!important;
  602. }
  603. /deep/.el-switch__label.is-active{
  604. color: var(--bs-el-color-primary)!important;
  605. }
  606. }
  607. .align-list-dropdown{
  608. width: 100px !important;
  609. color: #ffffff!important;
  610. }
  611. }
  612. // 自定义dropdown的样式
  613. .align-dropdown-menu{
  614. background-color: var(--bs-background-2)!important;
  615. border: 1px solid var(--bs-border-1);
  616. /deep/ .el-dropdown-menu__item{
  617. background-color: var(--bs-background-2)!important;
  618. &:hover {
  619. color: var(--bs-el-color-primary) !important;
  620. background-color: var(--bs-el-background-3) !important;
  621. }
  622. }
  623. }
  624. ::v-deep .el-input__inner,
  625. ::v-deep .el-color-picker__color-inner,
  626. ::v-deep .el-input-number--mini,
  627. ::v-deep .el-textarea__inner,
  628. ::v-deep .el-input-group__append {
  629. background: var(--bs-el-background-1);
  630. color: var(--bs-el-text);
  631. border: 0 !important;
  632. }
  633. </style>