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 cloneDeep from 'lodash/cloneDeep'
  192. import { G2 } from '@antv/g2plot'
  193. export default {
  194. name: 'OverallSetting',
  195. components: {
  196. ColorPicker,
  197. SettingTitle,
  198. BgImg
  199. },
  200. directives: {
  201. block: {
  202. bind (el, binding) {
  203. el.style.width = binding.value || '100%'
  204. }
  205. }
  206. },
  207. data () {
  208. return {
  209. resolutionRatioValue: '',
  210. // 自适应模式 无(none) 、自动(auto)、宽度铺满(fitWidth)、高度铺满(fitHeight)和 双向铺满(cover) 5 种自适应模式
  211. autoModeOptions: [
  212. {
  213. value: 'none',
  214. label: '无'
  215. },
  216. {
  217. value: 'auto',
  218. label: '自动'
  219. },
  220. {
  221. value: 'fitWidth',
  222. label: '宽度铺满'
  223. },
  224. {
  225. value: 'fitHeight',
  226. label: '高度铺满'
  227. },
  228. {
  229. value: 'cover',
  230. label: '双向铺满'
  231. }
  232. ],
  233. drawerVisible: false,
  234. resolutionRatioOptions: [
  235. {
  236. value: '1024*768',
  237. label: '1024*768'
  238. },
  239. {
  240. value: '1280*720',
  241. label: '1280*720'
  242. },
  243. {
  244. value: '1920*1080',
  245. label: '1920*1080'
  246. },
  247. {
  248. value: '2560*1440',
  249. label: '2560*1440'
  250. },
  251. {
  252. value: '3840*2160',
  253. label: '3840*2160'
  254. },
  255. {
  256. value: '5120*2880',
  257. label: '5120*2880'
  258. },
  259. {
  260. value: '7680*4320',
  261. label: '7680*4320'
  262. }
  263. ],
  264. themeOptions: [
  265. {
  266. value: 'dark',
  267. label: '暗黑'
  268. },
  269. {
  270. value: 'light',
  271. label: '明亮'
  272. },
  273. {
  274. value: 'auto',
  275. label: '透明'
  276. },
  277. {
  278. value: 'custom',
  279. label: '自定义'
  280. }
  281. ],
  282. form: {
  283. w: 1920,
  284. h: 1080,
  285. bg: '',
  286. bgColor: '#151a26', // 背景色
  287. opacity: 100,
  288. customTheme: 'auto',
  289. themeJson: {},
  290. cacheDataSets: [],
  291. refreshConfig: [],
  292. fitMode: 'none'
  293. },
  294. // 预设主题色
  295. predefineColors: [
  296. '#007aff',
  297. '#1aa97b',
  298. '#ff4d53',
  299. '#1890FF',
  300. '#DF0E1B',
  301. '#0086CC',
  302. '#2B74CF',
  303. '#00BC9D',
  304. '#ED7D32'
  305. ],
  306. // 图表列表
  307. chartOptions: []
  308. }
  309. },
  310. computed: {
  311. ...mapState({
  312. pageInfo: state => state.bigScreen.pageInfo,
  313. config: state => state.bigScreen.activeItemConfig
  314. }),
  315. dsValue () {
  316. return this.form.cacheDataSets?.map(dSet => ({
  317. id: dSet.dataSetId,
  318. name: dSet.name
  319. })) || []
  320. }
  321. },
  322. watch: {
  323. form: {
  324. handler (val) {
  325. this.changePageConfig(val)
  326. // 改变大屏的整体配置后,需要判断元素是否在大屏内,如果不在大屏内,需要将元素尽量往内部靠拢
  327. this.pageInfo.chartList.forEach(item => {
  328. if (item.x + item.w > this.form.w) {
  329. item.x = this.form.w - item.w
  330. }
  331. if (item.y + item.h > this.form.h) {
  332. item.y = this.form.h - item.h
  333. }
  334. })
  335. },
  336. deep: true
  337. },
  338. 'pageInfo.pageConfig.refreshConfig': {
  339. handler (val) {
  340. if (Array.isArray(val) && val.length) {
  341. this.chartOptions.forEach(chart => {
  342. chart.disabled = val?.findIndex(item => item.code === chart.code) !== -1
  343. })
  344. }
  345. },
  346. deep: true
  347. }
  348. },
  349. created () { },
  350. mounted () {
  351. this.initResolution()
  352. this.init()
  353. },
  354. methods: {
  355. ...mapMutations('bigScreen', [
  356. 'changePageLoading',
  357. 'changePageConfig',
  358. 'changeLayout',
  359. 'changeChartKey',
  360. 'changeRefreshConfig'
  361. ]),
  362. init () {
  363. if (!this.pageInfo.pageConfig.refreshConfig) {
  364. this.pageInfo.pageConfig.refreshConfig = []
  365. }
  366. this.form = { ...this.pageInfo.pageConfig }
  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-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>