index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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.bg"
  82. type="primary"
  83. @click="$refs.bgImg.init()"
  84. >
  85. 选择背景图
  86. </el-button>
  87. <el-image
  88. v-if="form.bg"
  89. class="bg-img bs-el-img"
  90. :src="form.bg"
  91. fit="cover"
  92. @click="$refs.bgImg.init()"
  93. />
  94. <div
  95. v-show="form.bg"
  96. @click="form.bg = ''"
  97. >
  98. <i class="el-icon-circle-close close-icon" />
  99. </div>
  100. <span
  101. v-if="form.bg"
  102. class="description"
  103. >(背景图优先级高于背景色,设置后将覆盖背景色)</span>
  104. <BgImg
  105. ref="bgImg"
  106. :form="form"
  107. @imgUrl="form.bg = $event"
  108. />
  109. </el-form-item>
  110. <el-form-item label="背景色">
  111. <ColorPicker
  112. v-model="form.bgColor"
  113. :placeholder="form.bg ? '' : '请选择背景色'"
  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. opacity: 100,
  290. customTheme: 'dark',
  291. themeJson: {},
  292. cacheDataSets: [],
  293. refreshConfig: [],
  294. fitMode: 'none'
  295. },
  296. // 预设主题色
  297. predefineColors: [
  298. '#007aff',
  299. '#1aa97b',
  300. '#ff4d53',
  301. '#1890FF',
  302. '#DF0E1B',
  303. '#0086CC',
  304. '#2B74CF',
  305. '#00BC9D',
  306. '#ED7D32'
  307. ],
  308. // 图表列表
  309. chartOptions: []
  310. }
  311. },
  312. computed: {
  313. ...mapState({
  314. pageInfo: state => state.bigScreen.pageInfo,
  315. config: state => state.bigScreen.activeItemConfig
  316. }),
  317. dsValue () {
  318. return this.form.cacheDataSets?.map(dSet => ({
  319. id: dSet.dataSetId,
  320. name: dSet.name
  321. })) || []
  322. }
  323. },
  324. watch: {
  325. form: {
  326. handler (val) {
  327. this.changePageConfig(val)
  328. // 改变大屏的整体配置后,需要判断元素是否在大屏内,如果不在大屏内,需要将元素尽量往内部靠拢
  329. this.pageInfo.chartList.forEach(item => {
  330. if (item.x + item.w > this.form.w) {
  331. item.x = this.form.w - item.w
  332. }
  333. if (item.y + item.h > this.form.h) {
  334. item.y = this.form.h - item.h
  335. }
  336. })
  337. },
  338. deep: true
  339. },
  340. 'pageInfo.pageConfig.refreshConfig': {
  341. handler (val) {
  342. if (Array.isArray(val) && val.length) {
  343. this.chartOptions.forEach(chart => {
  344. chart.disabled = val?.findIndex(item => item.code === chart.code) !== -1
  345. })
  346. }
  347. },
  348. deep: true
  349. }
  350. },
  351. created () { },
  352. mounted () {
  353. this.initResolution()
  354. this.init()
  355. },
  356. methods: {
  357. ...mapMutations('bigScreen', [
  358. 'changePageLoading',
  359. 'changePageConfig',
  360. 'changeLayout',
  361. 'changeChartKey',
  362. 'changeRefreshConfig'
  363. ]),
  364. // 切换主题时更新主题配置
  365. changeTheme (theme) {
  366. const pageInfo = this.pageInfo
  367. pageInfo.chartList = themeToSetting(pageInfo.chartList, theme)
  368. this.changePageInfo(pageInfo)
  369. },
  370. init () {
  371. if (!this.pageInfo.pageConfig.refreshConfig) {
  372. this.pageInfo.pageConfig.refreshConfig = []
  373. }
  374. this.form = { ...this.pageInfo.pageConfig }
  375. this.drawerVisible = true
  376. if (this.pageInfo.chartList.length === 0) {
  377. this.pageInfo.pageConfig.refreshConfig = []
  378. this.changeRefreshConfig([])
  379. this.form.refreshConfig = []
  380. } else {
  381. this.pageInfo.chartList.forEach(chart => {
  382. if (chart.dataSource?.businessKey) {
  383. this.chartOptions.push({
  384. code: chart.code,
  385. title: chart.title,
  386. disabled: false
  387. })
  388. } else {
  389. this.pageInfo.pageConfig.refreshConfig = this.pageInfo?.pageConfig?.refreshConfig?.filter(item => item.code !== chart.code) || []
  390. }
  391. })
  392. }
  393. },
  394. // 添加定时器
  395. createTimer () {
  396. const timer = {
  397. code: '',
  398. time: 0
  399. }
  400. if (!this.pageInfo.pageConfig.refreshConfig) {
  401. this.pageInfo.pageConfig.refreshConfig = []
  402. }
  403. this.pageInfo.pageConfig.refreshConfig.push(timer)
  404. },
  405. chartChange (val) {
  406. this.chartOptions.find(item => item.code === val).disabled = true
  407. },
  408. deleteTimer (timerIndex) {
  409. this.pageInfo.pageConfig.refreshConfig.splice(timerIndex, 1)
  410. },
  411. resolutionRatioValueHandel (val) {
  412. if (val) {
  413. this.form.w = Number(val.split('*')[0])
  414. this.form.h = Number(val.split('*')[1])
  415. } else {
  416. this.form.w = this.pageInfo.type === 'component' ? 1024 : 1920
  417. this.form.h = this.pageInfo.type === 'component' ? 768 : 1080
  418. }
  419. },
  420. initResolution () {
  421. this.resolutionRatioValue = this.pageInfo.pageConfig.w + '*' + this.pageInfo.pageConfig.h
  422. },
  423. getThemeConfig (themeName) {
  424. // this.changePageLoading(true)
  425. if (!['dark', 'light', 'auto'].includes(themeName)) {
  426. getThemeConfig().then(res => {
  427. this.form.themeJson = res
  428. this.changePageConfig(cloneDeep(this.form))
  429. // 统一注册主题
  430. const { registerTheme } = G2
  431. registerTheme(themeName, { ...res.chart })
  432. this.changeChart(themeName)
  433. })
  434. } else {
  435. this.form.themeJson = {}
  436. this.changePageConfig(this.form)
  437. this.changeChart(themeName)
  438. }
  439. },
  440. // 改变
  441. changeChart (themeName) {
  442. // 统一改变组件的主题
  443. const newChartList = cloneDeep(this.pageInfo.chartList)
  444. const chartList = newChartList.map(chart => {
  445. chart.option.theme = themeName
  446. chart.key = new Date().getTime()
  447. // this.changeChartKey(chart.code)
  448. return chart
  449. })
  450. // 可能需要强制性更新chartList
  451. this.changeLayout(chartList)
  452. },
  453. // 新增数据集
  454. addCacheDataSet () {
  455. this.form.cacheDataSets.push({
  456. // 数据集名称
  457. name: '',
  458. // 数据集id
  459. dataSetId: ''
  460. })
  461. },
  462. // 删除数据集
  463. deleteCacheDataSet (index) {
  464. this.form.cacheDataSets.splice(index, 1)
  465. },
  466. // 选择数据集
  467. getSelectDs (selectDs) {
  468. this.form.cacheDataSets = selectDs?.map(ds => ({
  469. name: ds.name,
  470. dataSetId: ds.id
  471. }))
  472. },
  473. close () {
  474. this.drawerVisible = false
  475. this.$emit('close')
  476. },
  477. timerEmptyState () {
  478. return this.pageInfo.chartList.every(chart => chart.dataSource?.businessKey === '')
  479. }
  480. }
  481. }
  482. </script>
  483. <style lang="scss" scoped>
  484. @import '../../assets/style/bsTheme.scss';
  485. .bs-overall-wrap {
  486. position: relative;
  487. height: 100%;
  488. background: var(--bs-background-2);
  489. .bs-overall-setting-wrap {
  490. padding: 16px;
  491. .title {
  492. display: flex;
  493. justify-content: space-around;
  494. margin-bottom: 18px;
  495. }
  496. .bs-timer-item {
  497. display: flex;
  498. margin-bottom: 18px;
  499. }
  500. }
  501. ::v-deep .el-input__inner,
  502. ::v-deep .el-color-picker__color-inner,
  503. ::v-deep .el-input-number--mini,
  504. ::v-deep .el-textarea__inner,
  505. ::v-deep .el-input-group__append,
  506. ::v-deep .el-radio__label {
  507. background: var(--bs-el-background-1);
  508. color: var(--bs-el-text);
  509. border: 0 !important;
  510. }
  511. ::v-deep .el-form-item__label {
  512. color: var(--bs-el-title);
  513. font-size: 12px;
  514. }
  515. ::v-deep .el-radio {
  516. margin-right: 10px
  517. }
  518. ::v-deep .el-table {
  519. background: var(--bs-el-background-1);
  520. border-bottom: 1px solid var(--bs-el-title);
  521. }
  522. ::v-deep .el-table__cell {
  523. background: var(--bs-el-background-1) !important;
  524. color: var(--bs-el-title) !important;
  525. border-color: var(--bs-el-text) !important;
  526. }
  527. ::v-deep .el-input__inner {
  528. &:placeholder {
  529. color: var(--bs-el-text);
  530. }
  531. }
  532. }
  533. .bg-img {
  534. width: 180px;
  535. height: 150px;
  536. cursor: pointer;
  537. position: relative;
  538. }
  539. .close-icon {
  540. left: 150px;
  541. top: 10px;
  542. font-size: 24px;
  543. cursor: pointer;
  544. color: #ffffff;
  545. position: absolute;
  546. }
  547. .select {
  548. display: table-footer-group;
  549. }
  550. .description {
  551. display: block;
  552. margin-top: 8px;
  553. font-size: 12px;
  554. }
  555. .toolbar {
  556. width: 320px;
  557. height: 50px;
  558. bottom: 0;
  559. z-index: 10;
  560. position: fixed;
  561. text-align: center;
  562. display: flex;
  563. align-items: center;
  564. justify-content: center;
  565. background: var(--bs-background-1);
  566. .el-button {
  567. margin-right: 10px;
  568. }
  569. }
  570. ::v-deep .el-drawer__wrapper {
  571. z-index: 2000 !important;
  572. .setting-body {
  573. padding: 16px;
  574. }
  575. }
  576. ::v-deep .el-drawer__body {
  577. padding: 0;
  578. margin-bottom: 0;
  579. overflow: hidden;
  580. }
  581. ::v-deep .el-drawer__container {
  582. height: calc(100% - 40px) !important;
  583. top: 40px !important;
  584. position: relative;
  585. left: 0;
  586. right: 0;
  587. bottom: 0;
  588. width: 100%;
  589. }
  590. .select-item {
  591. display: flex;
  592. margin-bottom: 8px;
  593. cursor: pointer;
  594. align-items: center;
  595. border: 1px solid #fff;
  596. padding: 4px;
  597. .input-wrap {
  598. flex: 1;
  599. display: flex;
  600. justify-content: center;
  601. margin-right: 2px;
  602. color: #36474f;
  603. ::v-deep.el-form-item {
  604. margin-bottom: 0 !important;
  605. }
  606. .el-input-number--mini {
  607. width: 90px !important;
  608. }
  609. }
  610. .input-wrap-right {
  611. width: 30px;
  612. flex: unset;
  613. }
  614. .input-wrap_left {
  615. flex: 1;
  616. display: flex;
  617. align-items: center;
  618. justify-content: left;
  619. }
  620. .select-line-icon {
  621. width: 30px;
  622. font-size: 18px;
  623. cursor: pointer;
  624. text-align: center;
  625. }
  626. .option-delete {
  627. color: #f56c6c;
  628. }
  629. }
  630. ::v-deep .el-color-picker--mini .el-color-picker__trigger {
  631. height: 32px;
  632. width: 32px;
  633. border: 1px solid var(--bs-el-background-1);
  634. background: var(--bs-el-background-1);
  635. .el-color-picker__color {
  636. background: var(--bs-el-background-1);
  637. border: 0 !important;
  638. }
  639. }
  640. .side-catalog-box {
  641. height: calc(100% - 50px);
  642. overflow-y: auto;
  643. }
  644. </style>