index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <template>
  2. <div class="bs-overall-wrap">
  3. <SettingTitle>整体布局</SettingTitle>
  4. <el-scrollbar class="side-catalog-box">
  5. <div class="bs-overall-setting-wrap">
  6. <el-form
  7. ref="form"
  8. v-model="form"
  9. label-width="100px"
  10. label-position="left"
  11. class="setting-body bs-el-form"
  12. >
  13. <el-form-item label="推荐分辨率">
  14. <el-select
  15. v-model="resolutionRatioValue"
  16. class="bs-el-select select"
  17. popper-class="bs-el-select"
  18. placeholder="请选择分辨率"
  19. clearable
  20. @change="resolutionRatioValueHandel"
  21. >
  22. <el-option
  23. v-for="resolutionRatio in resolutionRatioOptions"
  24. :key="resolutionRatio.value"
  25. :label="resolutionRatio.label"
  26. :value="resolutionRatio.value"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="大屏宽度">
  31. <el-input-number
  32. v-model="form.w"
  33. class="bs-el-input-number"
  34. :min="100"
  35. :max="8000"
  36. />
  37. </el-form-item>
  38. <el-form-item label="大屏高度">
  39. <el-input-number
  40. v-model="form.h"
  41. class="bs-el-input-number"
  42. :min="100"
  43. :max="8000"
  44. />
  45. </el-form-item>
  46. <el-form-item label="自适应模式">
  47. <el-select
  48. v-model="form.fitMode"
  49. class="bs-el-select"
  50. popper-class="bs-el-select"
  51. placeholder="自适应模式"
  52. clearable
  53. >
  54. <el-option
  55. v-for="mode in autoModeOptions"
  56. :key="mode.value"
  57. :label="mode.label"
  58. :value="mode.value"
  59. />
  60. </el-select>
  61. </el-form-item>
  62. <el-form-item label="主题">
  63. <el-select
  64. v-model="form.customTheme"
  65. class="bs-el-select select"
  66. popper-class="bs-el-select"
  67. placeholder="请选择主题"
  68. clearable
  69. @change="changeTheme"
  70. >
  71. <el-option
  72. v-for="themeItem in themeOptions"
  73. :key="themeItem.value"
  74. :label="themeItem.label"
  75. :value="themeItem.value"
  76. />
  77. </el-select>
  78. </el-form-item>
  79. <el-form-item label="背景图">
  80. <el-button
  81. v-if="!form[currentBg]"
  82. type="primary"
  83. @click="$refs.bgImg.init()"
  84. >
  85. 选择背景图
  86. </el-button>
  87. <el-image
  88. v-if="form.currentBg"
  89. class="bg-img bs-el-img"
  90. :src="form[currentBg]"
  91. fit="cover"
  92. @click="$refs.bgImg.init()"
  93. />
  94. <div
  95. v-show="form[currentBg]"
  96. @click="form[currentBg] = ''"
  97. >
  98. <i class="el-icon-circle-close close-icon" />
  99. </div>
  100. <span
  101. v-if="form[currentBg]"
  102. class="description"
  103. >(背景图优先级高于背景色,设置后将覆盖背景色)</span>
  104. <BgImg
  105. ref="bgImg"
  106. :form="form"
  107. @imgUrl="form[currentBg] = $event"
  108. />
  109. </el-form-item>
  110. <el-form-item label="背景色">
  111. <ColorPicker
  112. v-model="form[currentBgColor]"
  113. :placeholder="form[currentBg] ? '' : '请选择背景色'"
  114. :predefine-colors="predefineColors"
  115. />
  116. </el-form-item>
  117. </el-form>
  118. </div>
  119. <div>
  120. <SettingTitle>定时器</SettingTitle>
  121. <!-- 定时器空数据 -->
  122. <el-empty
  123. v-if="timerEmptyState()"
  124. description="请添加图表,并绑定数据集"
  125. />
  126. <div
  127. v-else
  128. class="bs-overall-setting-wrap"
  129. >
  130. <div class="title">
  131. <span>时间(秒)</span>
  132. <span>图表</span>
  133. <span />
  134. </div>
  135. <div
  136. v-for="(timer, index) in pageInfo.pageConfig.refreshConfig"
  137. :key="index"
  138. class="bs-timer-item"
  139. >
  140. <el-input-number
  141. v-model="timer.time"
  142. class="bs-el-input-number"
  143. :min="0"
  144. :max="999999"
  145. :step="1"
  146. placeholder="请输入定时器时间"
  147. style="margin-right: 8px;"
  148. />
  149. <el-select
  150. v-model="timer.code"
  151. class="bs-el-select"
  152. popper-class="bs-el-select"
  153. placeholder="请选择需要刷新的图表"
  154. @change="chartChange"
  155. >
  156. <el-option
  157. v-for="chart in chartOptions"
  158. :key="chart.code"
  159. :label="chart.title"
  160. :value="chart.code"
  161. :disabled="chart.disabled"
  162. />
  163. </el-select>
  164. <el-button
  165. style="margin-left: 8px;"
  166. class="bs-el-button-default"
  167. @click="deleteTimer(index)"
  168. >
  169. 删除
  170. </el-button>
  171. </div>
  172. <el-button
  173. v-if="pageInfo.chartList.length !== pageInfo.pageConfig.refreshConfig.length"
  174. type="primary"
  175. style="width: 100%;"
  176. @click="createTimer"
  177. >
  178. 新建
  179. </el-button>
  180. </div>
  181. </div>
  182. </el-scrollbar>
  183. </div>
  184. </template>
  185. <script>
  186. import SettingTitle from 'data-room-ui/SettingTitle/index.vue'
  187. import ColorPicker from 'data-room-ui/ColorPicker/index.vue'
  188. import BgImg from './BgImgDialog.vue'
  189. import { mapState, mapMutations } from 'vuex'
  190. import { getThemeConfig } from 'data-room-ui/js/api/bigScreenApi'
  191. // import _ from 'lodash'
  192. import cloneDeep from 'lodash/cloneDeep'
  193. import { G2 } from '@antv/g2plot'
  194. import { themeToSetting } from 'data-room-ui/js/utils/themeFormatting'
  195. export default {
  196. name: 'OverallSetting',
  197. components: {
  198. ColorPicker,
  199. SettingTitle,
  200. BgImg
  201. },
  202. directives: {
  203. block: {
  204. bind (el, binding) {
  205. el.style.width = binding.value || '100%'
  206. }
  207. }
  208. },
  209. data () {
  210. return {
  211. resolutionRatioValue: '',
  212. // 自适应模式 无(none) 、自动(auto)、宽度铺满(fitWidth)、高度铺满(fitHeight)和 双向铺满(cover) 5 种自适应模式
  213. autoModeOptions: [
  214. {
  215. value: 'none',
  216. label: '无'
  217. },
  218. {
  219. value: 'auto',
  220. label: '自动'
  221. },
  222. {
  223. value: 'fitWidth',
  224. label: '宽度铺满'
  225. },
  226. {
  227. value: 'fitHeight',
  228. label: '高度铺满'
  229. },
  230. {
  231. value: 'cover',
  232. label: '双向铺满'
  233. }
  234. ],
  235. drawerVisible: false,
  236. resolutionRatioOptions: [
  237. {
  238. value: '1024*768',
  239. label: '1024*768'
  240. },
  241. {
  242. value: '1280*720',
  243. label: '1280*720'
  244. },
  245. {
  246. value: '1920*1080',
  247. label: '1920*1080'
  248. },
  249. {
  250. value: '2560*1440',
  251. label: '2560*1440'
  252. },
  253. {
  254. value: '3840*2160',
  255. label: '3840*2160'
  256. },
  257. {
  258. value: '5120*2880',
  259. label: '5120*2880'
  260. },
  261. {
  262. value: '7680*4320',
  263. label: '7680*4320'
  264. }
  265. ],
  266. themeOptions: [
  267. {
  268. value: 'dark',
  269. label: '暗黑'
  270. },
  271. {
  272. value: 'light',
  273. label: '明亮'
  274. }
  275. // {
  276. // value: 'auto',
  277. // label: '透明'
  278. // },
  279. // {
  280. // value: 'custom',
  281. // label: '自定义'
  282. // }
  283. ],
  284. form: {
  285. w: 1920,
  286. h: 1080,
  287. bg: '',
  288. bgColor: '#151a26', // 背景色
  289. lightBg: '',
  290. lightBgColor: '#151a26',
  291. opacity: 100,
  292. customTheme: 'dark',
  293. themeJson: {},
  294. cacheDataSets: [],
  295. refreshConfig: [],
  296. fitMode: 'none'
  297. },
  298. // 预设主题色
  299. predefineColors: [
  300. '#007aff',
  301. '#1aa97b',
  302. '#ff4d53',
  303. '#1890FF',
  304. '#DF0E1B',
  305. '#0086CC',
  306. '#2B74CF',
  307. '#00BC9D',
  308. '#ED7D32'
  309. ],
  310. // 图表列表
  311. chartOptions: []
  312. }
  313. },
  314. computed: {
  315. ...mapState({
  316. pageInfo: state => state.bigScreen.pageInfo,
  317. config: state => state.bigScreen.activeItemConfig
  318. }),
  319. // 根据主题色来决定背景色和背景图绑定什么变量
  320. currentBgColor () {
  321. return this.form.customTheme === 'dark' ? 'bgColor' : 'lightBgColor'
  322. },
  323. currentBg () {
  324. return this.form.customTheme === 'dark' ? 'bg' : 'lightBgColor'
  325. },
  326. dsValue () {
  327. return this.form.cacheDataSets?.map(dSet => ({
  328. id: dSet.dataSetId,
  329. name: dSet.name
  330. })) || []
  331. }
  332. },
  333. watch: {
  334. form: {
  335. handler (val) {
  336. this.changePageConfig(val)
  337. // 改变大屏的整体配置后,需要判断元素是否在大屏内,如果不在大屏内,需要将元素尽量往内部靠拢
  338. this.pageInfo.chartList.forEach(item => {
  339. if (item.x + item.w > this.form.w) {
  340. item.x = this.form.w - item.w
  341. }
  342. if (item.y + item.h > this.form.h) {
  343. item.y = this.form.h - item.h
  344. }
  345. })
  346. },
  347. deep: true
  348. },
  349. 'pageInfo.pageConfig.refreshConfig': {
  350. handler (val) {
  351. if (Array.isArray(val) && val.length) {
  352. this.chartOptions.forEach(chart => {
  353. chart.disabled = val?.findIndex(item => item.code === chart.code) !== -1
  354. })
  355. }
  356. },
  357. deep: true
  358. }
  359. },
  360. created () { },
  361. mounted () {
  362. this.initResolution()
  363. this.init()
  364. },
  365. methods: {
  366. ...mapMutations('bigScreen', [
  367. 'changePageLoading',
  368. 'changePageConfig',
  369. 'changeLayout',
  370. 'changeChartKey',
  371. 'changeRefreshConfig',
  372. 'changePageInfo'
  373. ]),
  374. // 切换主题时更新主题配置
  375. changeTheme (theme) {
  376. const pageInfo = this.pageInfo
  377. pageInfo.chartList = themeToSetting(pageInfo.chartList, theme)
  378. this.changePageInfo(pageInfo)
  379. },
  380. init () {
  381. if (!this.pageInfo.pageConfig.refreshConfig) {
  382. this.pageInfo.pageConfig.refreshConfig = []
  383. }
  384. this.form = { ...this.pageInfo.pageConfig }
  385. this.drawerVisible = true
  386. if (this.pageInfo.chartList.length === 0) {
  387. this.pageInfo.pageConfig.refreshConfig = []
  388. this.changeRefreshConfig([])
  389. this.form.refreshConfig = []
  390. } else {
  391. this.pageInfo.chartList.forEach(chart => {
  392. if (chart.dataSource?.businessKey || chart.type === 'marquee') {
  393. this.chartOptions.push({
  394. code: chart.code,
  395. title: chart.title,
  396. disabled: false
  397. })
  398. } else {
  399. this.pageInfo.pageConfig.refreshConfig = this.pageInfo?.pageConfig?.refreshConfig?.filter(item => item.code !== chart.code) || []
  400. }
  401. })
  402. }
  403. },
  404. // 添加定时器
  405. createTimer () {
  406. const timer = {
  407. code: '',
  408. time: 0
  409. }
  410. if (!this.pageInfo.pageConfig.refreshConfig) {
  411. this.pageInfo.pageConfig.refreshConfig = []
  412. }
  413. this.pageInfo.pageConfig.refreshConfig.push(timer)
  414. },
  415. chartChange (val) {
  416. this.chartOptions.find(item => item.code === val).disabled = true
  417. },
  418. deleteTimer (timerIndex) {
  419. this.pageInfo.pageConfig.refreshConfig.splice(timerIndex, 1)
  420. },
  421. resolutionRatioValueHandel (val) {
  422. if (val) {
  423. this.form.w = Number(val.split('*')[0])
  424. this.form.h = Number(val.split('*')[1])
  425. } else {
  426. this.form.w = this.pageInfo.type === 'component' ? 1024 : 1920
  427. this.form.h = this.pageInfo.type === 'component' ? 768 : 1080
  428. }
  429. },
  430. initResolution () {
  431. this.resolutionRatioValue = this.pageInfo.pageConfig.w + '*' + this.pageInfo.pageConfig.h
  432. },
  433. getThemeConfig (themeName) {
  434. // this.changePageLoading(true)
  435. if (!['dark', 'light', 'auto'].includes(themeName)) {
  436. getThemeConfig().then(res => {
  437. this.form.themeJson = res
  438. this.changePageConfig(cloneDeep(this.form))
  439. // 统一注册主题
  440. const { registerTheme } = G2
  441. registerTheme(themeName, { ...res.chart })
  442. this.changeChart(themeName)
  443. })
  444. } else {
  445. this.form.themeJson = {}
  446. this.changePageConfig(this.form)
  447. this.changeChart(themeName)
  448. }
  449. },
  450. // 改变
  451. // changeChart (themeName) {
  452. // // 统一改变组件的主题
  453. // const newChartList = cloneDeep(this.pageInfo.chartList)
  454. // const chartList = newChartList.map(chart => {
  455. // chart.option.theme = themeName
  456. // chart.key = new Date().getTime()
  457. // // this.changeChartKey(chart.code)
  458. // return chart
  459. // })
  460. // // 可能需要强制性更新chartList
  461. // this.changeLayout(chartList)
  462. // },
  463. // 新增数据集
  464. addCacheDataSet () {
  465. this.form.cacheDataSets.push({
  466. // 数据集名称
  467. name: '',
  468. // 数据集id
  469. dataSetId: ''
  470. })
  471. },
  472. // 删除数据集
  473. deleteCacheDataSet (index) {
  474. this.form.cacheDataSets.splice(index, 1)
  475. },
  476. // 选择数据集
  477. getSelectDs (selectDs) {
  478. this.form.cacheDataSets = selectDs?.map(ds => ({
  479. name: ds.name,
  480. dataSetId: ds.id
  481. }))
  482. },
  483. close () {
  484. this.drawerVisible = false
  485. this.$emit('close')
  486. },
  487. timerEmptyState () {
  488. return this.pageInfo.chartList.every(chart => chart.dataSource?.businessKey === '')
  489. }
  490. }
  491. }
  492. </script>
  493. <style lang="scss" scoped>
  494. @import '../../assets/style/bsTheme.scss';
  495. .bs-overall-wrap {
  496. position: relative;
  497. height: 100%;
  498. background: var(--bs-background-2);
  499. .bs-overall-setting-wrap {
  500. padding: 16px;
  501. .title {
  502. display: flex;
  503. justify-content: space-around;
  504. margin-bottom: 18px;
  505. }
  506. .bs-timer-item {
  507. display: flex;
  508. margin-bottom: 18px;
  509. }
  510. }
  511. ::v-deep .el-input__inner,
  512. ::v-deep .el-color-picker__color-inner,
  513. ::v-deep .el-input-number--mini,
  514. ::v-deep .el-textarea__inner,
  515. ::v-deep .el-input-group__append,
  516. ::v-deep .el-radio__label {
  517. background: var(--bs-el-background-1);
  518. color: var(--bs-el-text);
  519. border: 0 !important;
  520. }
  521. ::v-deep .el-form-item__label {
  522. color: var(--bs-el-title);
  523. font-size: 12px;
  524. }
  525. ::v-deep .el-radio {
  526. margin-right: 10px
  527. }
  528. ::v-deep .el-table {
  529. background: var(--bs-el-background-1);
  530. border-bottom: 1px solid var(--bs-el-title);
  531. }
  532. ::v-deep .el-table__cell {
  533. background: var(--bs-el-background-1) !important;
  534. color: var(--bs-el-title) !important;
  535. border-color: var(--bs-el-text) !important;
  536. }
  537. ::v-deep .el-input__inner {
  538. &:placeholder {
  539. color: var(--bs-el-text);
  540. }
  541. }
  542. }
  543. .bg-img {
  544. width: 180px;
  545. height: 150px;
  546. cursor: pointer;
  547. position: relative;
  548. }
  549. .close-icon {
  550. left: 150px;
  551. top: 10px;
  552. font-size: 24px;
  553. cursor: pointer;
  554. color: #ffffff;
  555. position: absolute;
  556. }
  557. .select {
  558. display: table-footer-group;
  559. }
  560. .description {
  561. display: block;
  562. margin-top: 8px;
  563. font-size: 12px;
  564. }
  565. .toolbar {
  566. width: 320px;
  567. height: 50px;
  568. bottom: 0;
  569. z-index: 10;
  570. position: fixed;
  571. text-align: center;
  572. display: flex;
  573. align-items: center;
  574. justify-content: center;
  575. background: var(--bs-background-1);
  576. .el-button {
  577. margin-right: 10px;
  578. }
  579. }
  580. ::v-deep .el-drawer__wrapper {
  581. z-index: 2000 !important;
  582. .setting-body {
  583. padding: 16px;
  584. }
  585. }
  586. ::v-deep .el-drawer__body {
  587. padding: 0;
  588. margin-bottom: 0;
  589. overflow: hidden;
  590. }
  591. ::v-deep .el-drawer__container {
  592. height: calc(100% - 40px) !important;
  593. top: 40px !important;
  594. position: relative;
  595. left: 0;
  596. right: 0;
  597. bottom: 0;
  598. width: 100%;
  599. }
  600. .select-item {
  601. display: flex;
  602. margin-bottom: 8px;
  603. cursor: pointer;
  604. align-items: center;
  605. border: 1px solid #fff;
  606. padding: 4px;
  607. .input-wrap {
  608. flex: 1;
  609. display: flex;
  610. justify-content: center;
  611. margin-right: 2px;
  612. color: #36474f;
  613. ::v-deep.el-form-item {
  614. margin-bottom: 0 !important;
  615. }
  616. .el-input-number--mini {
  617. width: 90px !important;
  618. }
  619. }
  620. .input-wrap-right {
  621. width: 30px;
  622. flex: unset;
  623. }
  624. .input-wrap_left {
  625. flex: 1;
  626. display: flex;
  627. align-items: center;
  628. justify-content: left;
  629. }
  630. .select-line-icon {
  631. width: 30px;
  632. font-size: 18px;
  633. cursor: pointer;
  634. text-align: center;
  635. }
  636. .option-delete {
  637. color: #f56c6c;
  638. }
  639. }
  640. ::v-deep .el-color-picker--mini .el-color-picker__trigger {
  641. height: 32px;
  642. width: 32px;
  643. border: 1px solid var(--bs-el-background-1);
  644. background: var(--bs-el-background-1);
  645. .el-color-picker__color {
  646. background: var(--bs-el-background-1);
  647. border: 0 !important;
  648. }
  649. }
  650. .side-catalog-box {
  651. height: calc(100% - 50px);
  652. overflow-y: auto;
  653. }
  654. </style>