index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. console.log('this.form', this.form)
  367. this.drawerVisible = true
  368. if (this.pageInfo.chartList.length === 0) {
  369. this.pageInfo.pageConfig.refreshConfig = []
  370. this.changeRefreshConfig([])
  371. this.form.refreshConfig = []
  372. } else {
  373. this.pageInfo.chartList.forEach(chart => {
  374. if (chart.dataSource.businessKey) {
  375. this.chartOptions.push({
  376. code: chart.code,
  377. title: chart.title,
  378. disabled: false
  379. })
  380. } else {
  381. this.pageInfo.pageConfig.refreshConfig = this.pageInfo?.pageConfig?.refreshConfig?.filter(item => item.code !== chart.code) || []
  382. }
  383. })
  384. }
  385. },
  386. // 添加定时器
  387. createTimer () {
  388. const timer = {
  389. code: '',
  390. time: 0
  391. }
  392. if (!this.pageInfo.pageConfig.refreshConfig) {
  393. this.pageInfo.pageConfig.refreshConfig = []
  394. }
  395. this.pageInfo.pageConfig.refreshConfig.push(timer)
  396. },
  397. chartChange (val) {
  398. this.chartOptions.find(item => item.code === val).disabled = true
  399. },
  400. deleteTimer (timerIndex) {
  401. this.pageInfo.pageConfig.refreshConfig.splice(timerIndex, 1)
  402. },
  403. resolutionRatioValueHandel (val) {
  404. if (val) {
  405. this.form.w = Number(val.split('*')[0])
  406. this.form.h = Number(val.split('*')[1])
  407. } else {
  408. this.form.w = this.pageInfo.type === 'component' ? 1024 : 1920
  409. this.form.h = this.pageInfo.type === 'component' ? 768 : 1080
  410. }
  411. },
  412. initResolution () {
  413. this.resolutionRatioValue = this.pageInfo.pageConfig.w + '*' + this.pageInfo.pageConfig.h
  414. },
  415. getThemeConfig (themeName) {
  416. // this.changePageLoading(true)
  417. if (!['dark', 'light', 'auto'].includes(themeName)) {
  418. getThemeConfig().then(res => {
  419. this.form.themeJson = res
  420. this.changePageConfig(_.cloneDeep(this.form))
  421. // 统一注册主题
  422. const { registerTheme } = G2
  423. registerTheme(themeName, { ...res.chart })
  424. this.changeChart(themeName)
  425. })
  426. } else {
  427. this.form.themeJson = {}
  428. this.changePageConfig(this.form)
  429. this.changeChart(themeName)
  430. }
  431. },
  432. // 改变
  433. changeChart (themeName) {
  434. // 统一改变组件的主题
  435. const newChartList = _.cloneDeep(this.pageInfo.chartList)
  436. const chartList = newChartList.map(chart => {
  437. chart.option.theme = themeName
  438. chart.key = new Date().getTime()
  439. // this.changeChartKey(chart.code)
  440. return chart
  441. })
  442. // 可能需要强制性更新chartList
  443. this.changeLayout(chartList)
  444. },
  445. // 新增数据集
  446. addCacheDataSet () {
  447. this.form.cacheDataSets.push({
  448. // 数据集名称
  449. name: '',
  450. // 数据集id
  451. dataSetId: ''
  452. })
  453. },
  454. // 删除数据集
  455. deleteCacheDataSet (index) {
  456. this.form.cacheDataSets.splice(index, 1)
  457. },
  458. // 选择数据集
  459. getSelectDs (selectDs) {
  460. this.form.cacheDataSets = selectDs?.map(ds => ({
  461. name: ds.name,
  462. dataSetId: ds.id
  463. }))
  464. },
  465. close () {
  466. this.drawerVisible = false
  467. this.$emit('close')
  468. },
  469. timerEmptyState () {
  470. return this.pageInfo.chartList.every(chart => chart.dataSource.businessKey === '')
  471. }
  472. }
  473. }
  474. </script>
  475. <style lang="scss" scoped>
  476. @import '../../assets/style/bsTheme.scss';
  477. .bs-overall-wrap {
  478. position: relative;
  479. height: 100%;
  480. background: var(--bs-background-2);
  481. .bs-overall-setting-wrap {
  482. padding: 16px;
  483. .title {
  484. display: flex;
  485. justify-content: space-around;
  486. margin-bottom: 18px;
  487. }
  488. .bs-timer-item {
  489. display: flex;
  490. margin-bottom: 18px;
  491. }
  492. }
  493. ::v-deep .el-input__inner,
  494. ::v-deep .el-color-picker__color-inner,
  495. ::v-deep .el-radio__inner,
  496. ::v-deep .el-input-number--mini,
  497. ::v-deep .el-textarea__inner,
  498. ::v-deep .el-input-group__append,
  499. ::v-deep .el-radio__label {
  500. background: var(--bs-el-background-1);
  501. color: var(--bs-el-text);
  502. border: 0 !important;
  503. }
  504. ::v-deep .el-form-item__label {
  505. color: var(--bs-el-title);
  506. font-size: 12px;
  507. }
  508. ::v-deep .el-radio {
  509. margin-right: 10px
  510. }
  511. ::v-deep .el-table {
  512. background: var(--bs-el-background-1);
  513. border-bottom: 1px solid var(--bs-el-title);
  514. }
  515. ::v-deep .el-table__cell {
  516. background: var(--bs-el-background-1) !important;
  517. color: var(--bs-el-title) !important;
  518. border-color: var(--bs-el-text) !important;
  519. }
  520. ::v-deep .el-input__inner {
  521. &:placeholder {
  522. color: var(--bs-el-text);
  523. }
  524. }
  525. }
  526. .bg-img {
  527. width: 180px;
  528. height: 150px;
  529. cursor: pointer;
  530. position: relative;
  531. }
  532. .close-icon {
  533. left: 150px;
  534. top: 10px;
  535. font-size: 24px;
  536. cursor: pointer;
  537. color: #ffffff;
  538. position: absolute;
  539. }
  540. .select {
  541. display: table-footer-group;
  542. }
  543. .description {
  544. display: block;
  545. margin-top: 8px;
  546. font-size: 12px;
  547. }
  548. .toolbar {
  549. width: 320px;
  550. height: 50px;
  551. bottom: 0;
  552. z-index: 10;
  553. position: fixed;
  554. text-align: center;
  555. display: flex;
  556. align-items: center;
  557. justify-content: center;
  558. background: var(--bs-background-1);
  559. .el-button {
  560. margin-right: 10px;
  561. }
  562. }
  563. ::v-deep .el-drawer__wrapper {
  564. z-index: 2000 !important;
  565. .setting-body {
  566. padding: 16px;
  567. }
  568. }
  569. ::v-deep .el-drawer__body {
  570. padding: 0;
  571. margin-bottom: 0;
  572. overflow: hidden;
  573. }
  574. ::v-deep .el-drawer__container {
  575. height: calc(100% - 40px) !important;
  576. top: 40px !important;
  577. position: relative;
  578. left: 0;
  579. right: 0;
  580. bottom: 0;
  581. width: 100%;
  582. }
  583. .select-item {
  584. display: flex;
  585. margin-bottom: 8px;
  586. cursor: pointer;
  587. align-items: center;
  588. border: 1px solid #fff;
  589. padding: 4px;
  590. .input-wrap {
  591. flex: 1;
  592. display: flex;
  593. justify-content: center;
  594. margin-right: 2px;
  595. color: #36474f;
  596. ::v-deep.el-form-item {
  597. margin-bottom: 0 !important;
  598. }
  599. .el-input-number--mini {
  600. width: 90px !important;
  601. }
  602. }
  603. .input-wrap-right {
  604. width: 30px;
  605. flex: unset;
  606. }
  607. .input-wrap_left {
  608. flex: 1;
  609. display: flex;
  610. align-items: center;
  611. justify-content: left;
  612. }
  613. .select-line-icon {
  614. width: 30px;
  615. font-size: 18px;
  616. cursor: pointer;
  617. text-align: center;
  618. }
  619. .option-delete {
  620. color: #f56c6c;
  621. }
  622. }
  623. ::v-deep .el-color-picker--mini .el-color-picker__trigger {
  624. height: 32px;
  625. width: 32px;
  626. border: 1px solid var(--bs-el-background-1);
  627. background: var(--bs-el-background-1);
  628. .el-color-picker__color {
  629. background: var(--bs-el-background-1);
  630. border: 0 !important;
  631. }
  632. }
  633. .side-catalog-box {
  634. height: calc(100% - 50px);
  635. overflow-y: auto;
  636. }
  637. </style>