PageDesignTop.vue 18 KB

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