index.vue 16 KB

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