index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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[currentBg]"
  82. type="primary"
  83. @click="$refs.bgImg.init()"
  84. >
  85. 选择背景图
  86. </el-button>
  87. <el-image
  88. v-if="form[currentBg]"
  89. class="bg-img bs-el-img"
  90. :src="form[currentBg]"
  91. fit="cover"
  92. @click="$refs.bgImg.init()"
  93. />
  94. <div
  95. v-show="form[currentBg]"
  96. @click="form[currentBg] = ''"
  97. >
  98. <i class="el-icon-circle-close close-icon" />
  99. </div>
  100. <span
  101. v-if="form[currentBg]"
  102. class="description"
  103. >(背景图优先级高于背景色,设置后将覆盖背景色)</span>
  104. <BgImg
  105. ref="bgImg"
  106. :form="form"
  107. @imgUrl="form[currentBg] = $event"
  108. />
  109. </el-form-item>
  110. <el-form-item label="背景色">
  111. <ColorPicker
  112. v-model="form[currentBgColor]"
  113. :placeholder="form[currentBg] ? '' : '请选择背景色'"
  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 { themeToSetting } from 'data-room-ui/js/utils/themeFormatting'
  191. import {predefineColors} from 'data-room-ui/js/utils/colorList'
  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. lightBg: '',
  287. lightBgColor: '#f5f7fa',
  288. opacity: 100,
  289. customTheme: 'dark',
  290. themeJson: {},
  291. cacheDataSets: [],
  292. refreshConfig: [],
  293. fitMode: 'none'
  294. },
  295. // 预设主题色
  296. predefineColors,
  297. // 图表列表
  298. chartOptions: []
  299. }
  300. },
  301. computed: {
  302. ...mapState({
  303. pageInfo: state => state.bigScreen.pageInfo,
  304. config: state => state.bigScreen.activeItemConfig
  305. }),
  306. isPreview () {
  307. return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
  308. },
  309. // 根据主题色来决定背景色和背景图绑定什么变量
  310. currentBgColor () {
  311. return this.form.customTheme === 'light' ? 'lightBgColor' : 'bgColor'
  312. },
  313. currentBg () {
  314. return this.form.customTheme === 'light' ? 'lightBg' : 'bg'
  315. },
  316. dsValue () {
  317. return this.form.cacheDataSets?.map(dSet => ({
  318. id: dSet.dataSetId,
  319. name: dSet.name
  320. })) || []
  321. }
  322. },
  323. watch: {
  324. form: {
  325. handler (val) {
  326. this.changePageConfig(val)
  327. // 改变大屏的整体配置后,需要判断元素是否在大屏内,如果不在大屏内,需要将元素尽量往内部靠拢
  328. this.pageInfo.chartList.forEach(item => {
  329. if (item.x + item.w > this.form.w) {
  330. item.x = this.form.w - item.w
  331. }
  332. if (item.y + item.h > this.form.h) {
  333. item.y = this.form.h - item.h
  334. }
  335. })
  336. },
  337. deep: true
  338. },
  339. 'pageInfo.pageConfig.refreshConfig': {
  340. handler (val) {
  341. if (Array.isArray(val) && val.length) {
  342. this.chartOptions.forEach(chart => {
  343. chart.disabled = val?.findIndex(item => item.code === chart.code) !== -1
  344. })
  345. }
  346. },
  347. deep: true
  348. }
  349. },
  350. created () { },
  351. mounted () {
  352. this.initResolution()
  353. this.init()
  354. },
  355. methods: {
  356. ...mapMutations('bigScreen', [
  357. 'changePageLoading',
  358. 'changePageConfig',
  359. 'changeLayout',
  360. 'changeChartKey',
  361. 'changeRefreshConfig',
  362. 'changePageInfo'
  363. ]),
  364. // 切换主题时更新主题配置
  365. changeTheme (theme) {
  366. const pageInfo = this.pageInfo
  367. pageInfo.chartList = themeToSetting(pageInfo.chartList, theme)
  368. this.changePageInfo(pageInfo)
  369. pageInfo.chartList.forEach(chart => {
  370. if (chart.type === 'remoteComponent') {
  371. this.$emit('styleHandler', chart)
  372. }
  373. })
  374. if (!this.isPreview) {
  375. const themeLabel = theme === 'light' ? '明亮' : '暗黑'
  376. const htmlStr = `<span>当前已切换到<strong>${themeLabel}</strong>主题,颜色设置针对当前主题生效</span>`
  377. this.$notify({
  378. title: '注意',
  379. dangerouslyUseHTMLString: true,
  380. message: htmlStr,
  381. customClass: 'ds-el-notify',
  382. type: 'warning'
  383. })
  384. }
  385. },
  386. init () {
  387. if (!this.pageInfo.pageConfig.refreshConfig) {
  388. this.pageInfo.pageConfig.refreshConfig = []
  389. }
  390. this.form = { ...this.pageInfo.pageConfig }
  391. this.drawerVisible = true
  392. if (this.pageInfo.chartList.length === 0) {
  393. this.pageInfo.pageConfig.refreshConfig = []
  394. this.changeRefreshConfig([])
  395. this.form.refreshConfig = []
  396. } else {
  397. this.pageInfo.chartList.forEach(chart => {
  398. if (chart.dataSource?.businessKey || chart.type === 'marquee') {
  399. this.chartOptions.push({
  400. code: chart.code,
  401. title: chart.title,
  402. disabled: false
  403. })
  404. } else {
  405. this.pageInfo.pageConfig.refreshConfig = this.pageInfo?.pageConfig?.refreshConfig?.filter(item => item.code !== chart.code) || []
  406. }
  407. })
  408. }
  409. },
  410. // 添加定时器
  411. createTimer () {
  412. const timer = {
  413. code: '',
  414. time: 0
  415. }
  416. if (!this.pageInfo.pageConfig.refreshConfig) {
  417. this.pageInfo.pageConfig.refreshConfig = []
  418. }
  419. this.pageInfo.pageConfig.refreshConfig.push(timer)
  420. },
  421. chartChange (val) {
  422. this.chartOptions.find(item => item.code === val).disabled = true
  423. },
  424. deleteTimer (timerIndex) {
  425. this.pageInfo.pageConfig.refreshConfig.splice(timerIndex, 1)
  426. },
  427. resolutionRatioValueHandel (val) {
  428. if (val) {
  429. this.form.w = Number(val.split('*')[0])
  430. this.form.h = Number(val.split('*')[1])
  431. } else {
  432. this.form.w = this.pageInfo.type === 'component' ? 1024 : 1920
  433. this.form.h = this.pageInfo.type === 'component' ? 768 : 1080
  434. }
  435. },
  436. initResolution () {
  437. this.resolutionRatioValue = this.pageInfo.pageConfig.w + '*' + this.pageInfo.pageConfig.h
  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 === '' && chart.type !== 'marquee')
  465. }
  466. }
  467. }
  468. </script>
  469. <style lang="scss" scoped>
  470. @import '../../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. ::v-deep .el-input__inner,
  488. ::v-deep .el-color-picker__color-inner,
  489. ::v-deep .el-input-number--mini,
  490. ::v-deep .el-textarea__inner,
  491. ::v-deep .el-input-group__append,
  492. ::v-deep .el-radio__label {
  493. background: var(--bs-el-background-1);
  494. color: var(--bs-el-text);
  495. border: 0 !important;
  496. }
  497. ::v-deep .el-form-item__label {
  498. color: var(--bs-el-title);
  499. font-size: 12px;
  500. }
  501. ::v-deep .el-radio {
  502. margin-right: 10px
  503. }
  504. ::v-deep .el-table {
  505. background: var(--bs-el-background-1);
  506. border-bottom: 1px solid var(--bs-el-title);
  507. }
  508. ::v-deep .el-table__cell {
  509. background: var(--bs-el-background-1) !important;
  510. color: var(--bs-el-title) !important;
  511. border-color: var(--bs-el-text) !important;
  512. }
  513. ::v-deep .el-input__inner {
  514. &:placeholder {
  515. color: var(--bs-el-text);
  516. }
  517. }
  518. }
  519. .bg-img {
  520. width: 180px;
  521. height: 150px;
  522. cursor: pointer;
  523. position: relative;
  524. }
  525. .close-icon {
  526. left: 150px;
  527. top: 10px;
  528. font-size: 24px;
  529. cursor: pointer;
  530. color: #ffffff;
  531. position: absolute;
  532. }
  533. .select {
  534. display: table-footer-group;
  535. }
  536. .description {
  537. display: block;
  538. margin-top: 8px;
  539. font-size: 12px;
  540. }
  541. .toolbar {
  542. width: 320px;
  543. height: 50px;
  544. bottom: 0;
  545. z-index: 10;
  546. position: fixed;
  547. text-align: center;
  548. display: flex;
  549. align-items: center;
  550. justify-content: center;
  551. background: var(--bs-background-1);
  552. .el-button {
  553. margin-right: 10px;
  554. }
  555. }
  556. ::v-deep .el-drawer__wrapper {
  557. z-index: 2000 !important;
  558. .setting-body {
  559. padding: 16px;
  560. }
  561. }
  562. ::v-deep .el-drawer__body {
  563. padding: 0;
  564. margin-bottom: 0;
  565. overflow: hidden;
  566. }
  567. ::v-deep .el-drawer__container {
  568. height: calc(100% - 40px) !important;
  569. top: 40px !important;
  570. position: relative;
  571. left: 0;
  572. right: 0;
  573. bottom: 0;
  574. width: 100%;
  575. }
  576. .select-item {
  577. display: flex;
  578. margin-bottom: 8px;
  579. cursor: pointer;
  580. align-items: center;
  581. border: 1px solid #fff;
  582. padding: 4px;
  583. .input-wrap {
  584. flex: 1;
  585. display: flex;
  586. justify-content: center;
  587. margin-right: 2px;
  588. color: #36474f;
  589. ::v-deep.el-form-item {
  590. margin-bottom: 0 !important;
  591. }
  592. .el-input-number--mini {
  593. width: 90px !important;
  594. }
  595. }
  596. .input-wrap-right {
  597. width: 30px;
  598. flex: unset;
  599. }
  600. .input-wrap_left {
  601. flex: 1;
  602. display: flex;
  603. align-items: center;
  604. justify-content: left;
  605. }
  606. .select-line-icon {
  607. width: 30px;
  608. font-size: 18px;
  609. cursor: pointer;
  610. text-align: center;
  611. }
  612. .option-delete {
  613. color: #f56c6c;
  614. }
  615. }
  616. ::v-deep .el-color-picker--mini .el-color-picker__trigger {
  617. height: 32px;
  618. width: 32px;
  619. border: 1px solid var(--bs-el-background-1);
  620. background: var(--bs-el-background-1);
  621. .el-color-picker__color {
  622. background: var(--bs-el-background-1);
  623. border: 0 !important;
  624. }
  625. }
  626. .side-catalog-box {
  627. height: calc(100% - 50px);
  628. overflow-y: auto;
  629. }
  630. </style>
  631. <style lang="scss">
  632. //修改notify的样式
  633. .ds-el-notify {
  634. background-color: var(--bs-el-background-1)!important;
  635. border: var(--bs-el-border)!important;
  636. .el-notification__title{
  637. color: #fff!important;
  638. }
  639. .el-notification__content{
  640. color: #fff!important;
  641. }
  642. .el-notification__closeBtn{
  643. color: #fff!important;
  644. }
  645. }
  646. </style>