index.vue 16 KB

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