index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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. export default {
  192. name: 'OverallSetting',
  193. components: {
  194. ColorPicker,
  195. SettingTitle,
  196. BgImg
  197. },
  198. directives: {
  199. block: {
  200. bind (el, binding) {
  201. el.style.width = binding.value || '100%'
  202. }
  203. }
  204. },
  205. data () {
  206. return {
  207. resolutionRatioValue: '',
  208. // 自适应模式 无(none) 、自动(auto)、宽度铺满(fitWidth)、高度铺满(fitHeight)和 双向铺满(cover) 5 种自适应模式
  209. autoModeOptions: [
  210. {
  211. value: 'none',
  212. label: '无'
  213. },
  214. {
  215. value: 'auto',
  216. label: '自动'
  217. },
  218. {
  219. value: 'fitWidth',
  220. label: '宽度铺满'
  221. },
  222. {
  223. value: 'fitHeight',
  224. label: '高度铺满'
  225. },
  226. {
  227. value: 'cover',
  228. label: '双向铺满'
  229. }
  230. ],
  231. drawerVisible: false,
  232. resolutionRatioOptions: [
  233. {
  234. value: '1024*768',
  235. label: '1024*768'
  236. },
  237. {
  238. value: '1280*720',
  239. label: '1280*720'
  240. },
  241. {
  242. value: '1920*1080',
  243. label: '1920*1080'
  244. },
  245. {
  246. value: '2560*1440',
  247. label: '2560*1440'
  248. },
  249. {
  250. value: '3840*2160',
  251. label: '3840*2160'
  252. },
  253. {
  254. value: '5120*2880',
  255. label: '5120*2880'
  256. },
  257. {
  258. value: '7680*4320',
  259. label: '7680*4320'
  260. }
  261. ],
  262. themeOptions: [
  263. {
  264. value: 'dark',
  265. label: '暗黑'
  266. },
  267. {
  268. value: 'light',
  269. label: '明亮'
  270. }
  271. // {
  272. // value: 'auto',
  273. // label: '透明'
  274. // },
  275. // {
  276. // value: 'custom',
  277. // label: '自定义'
  278. // }
  279. ],
  280. form: {
  281. w: 1920,
  282. h: 1080,
  283. bg: '',
  284. bgColor: '#151a26', // 背景色
  285. lightBg: '',
  286. lightBgColor: '#f5f7fa',
  287. opacity: 100,
  288. customTheme: 'dark',
  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. isPreview () {
  316. return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
  317. },
  318. // 根据主题色来决定背景色和背景图绑定什么变量
  319. currentBgColor () {
  320. return this.form.customTheme === 'light' ? 'lightBgColor' : 'bgColor'
  321. },
  322. currentBg () {
  323. return this.form.customTheme === 'light' ? 'lightBgColor' : 'bg'
  324. },
  325. dsValue () {
  326. return this.form.cacheDataSets?.map(dSet => ({
  327. id: dSet.dataSetId,
  328. name: dSet.name
  329. })) || []
  330. }
  331. },
  332. watch: {
  333. form: {
  334. handler (val) {
  335. this.changePageConfig(val)
  336. // 改变大屏的整体配置后,需要判断元素是否在大屏内,如果不在大屏内,需要将元素尽量往内部靠拢
  337. this.pageInfo.chartList.forEach(item => {
  338. if (item.x + item.w > this.form.w) {
  339. item.x = this.form.w - item.w
  340. }
  341. if (item.y + item.h > this.form.h) {
  342. item.y = this.form.h - item.h
  343. }
  344. })
  345. },
  346. deep: true
  347. },
  348. 'pageInfo.pageConfig.refreshConfig': {
  349. handler (val) {
  350. if (Array.isArray(val) && val.length) {
  351. this.chartOptions.forEach(chart => {
  352. chart.disabled = val?.findIndex(item => item.code === chart.code) !== -1
  353. })
  354. }
  355. },
  356. deep: true
  357. }
  358. },
  359. created () { },
  360. mounted () {
  361. this.initResolution()
  362. this.init()
  363. },
  364. methods: {
  365. ...mapMutations('bigScreen', [
  366. 'changePageLoading',
  367. 'changePageConfig',
  368. 'changeLayout',
  369. 'changeChartKey',
  370. 'changeRefreshConfig',
  371. 'changePageInfo'
  372. ]),
  373. // 切换主题时更新主题配置
  374. changeTheme (theme) {
  375. const pageInfo = this.pageInfo
  376. pageInfo.chartList = themeToSetting(pageInfo.chartList, theme)
  377. this.changePageInfo(pageInfo)
  378. pageInfo.chartList.forEach(chart => {
  379. if (chart.type === 'remoteComponent') {
  380. this.$emit('styleHandler', chart)
  381. }
  382. })
  383. if (!this.isPreview) {
  384. const themeLabel = theme === 'light' ? '明亮' : '暗黑'
  385. const htmlStr = `<span>当前已切换到<strong>${themeLabel}</strong>主题,颜色设置针对当前主题生效</span>`
  386. this.$notify({
  387. title: '注意',
  388. dangerouslyUseHTMLString: true,
  389. message: htmlStr,
  390. customClass: 'ds-el-notify',
  391. type: 'warning'
  392. })
  393. }
  394. },
  395. init () {
  396. if (!this.pageInfo.pageConfig.refreshConfig) {
  397. this.pageInfo.pageConfig.refreshConfig = []
  398. }
  399. this.form = { ...this.pageInfo.pageConfig }
  400. this.drawerVisible = true
  401. if (this.pageInfo.chartList.length === 0) {
  402. this.pageInfo.pageConfig.refreshConfig = []
  403. this.changeRefreshConfig([])
  404. this.form.refreshConfig = []
  405. } else {
  406. this.pageInfo.chartList.forEach(chart => {
  407. if (chart.dataSource?.businessKey || chart.type === 'marquee') {
  408. this.chartOptions.push({
  409. code: chart.code,
  410. title: chart.title,
  411. disabled: false
  412. })
  413. } else {
  414. this.pageInfo.pageConfig.refreshConfig = this.pageInfo?.pageConfig?.refreshConfig?.filter(item => item.code !== chart.code) || []
  415. }
  416. })
  417. }
  418. },
  419. // 添加定时器
  420. createTimer () {
  421. const timer = {
  422. code: '',
  423. time: 0
  424. }
  425. if (!this.pageInfo.pageConfig.refreshConfig) {
  426. this.pageInfo.pageConfig.refreshConfig = []
  427. }
  428. this.pageInfo.pageConfig.refreshConfig.push(timer)
  429. },
  430. chartChange (val) {
  431. this.chartOptions.find(item => item.code === val).disabled = true
  432. },
  433. deleteTimer (timerIndex) {
  434. this.pageInfo.pageConfig.refreshConfig.splice(timerIndex, 1)
  435. },
  436. resolutionRatioValueHandel (val) {
  437. if (val) {
  438. this.form.w = Number(val.split('*')[0])
  439. this.form.h = Number(val.split('*')[1])
  440. } else {
  441. this.form.w = this.pageInfo.type === 'component' ? 1024 : 1920
  442. this.form.h = this.pageInfo.type === 'component' ? 768 : 1080
  443. }
  444. },
  445. initResolution () {
  446. this.resolutionRatioValue = this.pageInfo.pageConfig.w + '*' + this.pageInfo.pageConfig.h
  447. },
  448. // 新增数据集
  449. addCacheDataSet () {
  450. this.form.cacheDataSets.push({
  451. // 数据集名称
  452. name: '',
  453. // 数据集id
  454. dataSetId: ''
  455. })
  456. },
  457. // 删除数据集
  458. deleteCacheDataSet (index) {
  459. this.form.cacheDataSets.splice(index, 1)
  460. },
  461. // 选择数据集
  462. getSelectDs (selectDs) {
  463. this.form.cacheDataSets = selectDs?.map(ds => ({
  464. name: ds.name,
  465. dataSetId: ds.id
  466. }))
  467. },
  468. close () {
  469. this.drawerVisible = false
  470. this.$emit('close')
  471. },
  472. timerEmptyState () {
  473. return this.pageInfo.chartList.every(chart => chart.dataSource?.businessKey === '' && chart.type !== 'marquee')
  474. }
  475. }
  476. }
  477. </script>
  478. <style lang="scss" scoped>
  479. @import '../../assets/style/bsTheme.scss';
  480. .bs-overall-wrap {
  481. position: relative;
  482. height: 100%;
  483. background: var(--bs-background-2);
  484. .bs-overall-setting-wrap {
  485. padding: 16px;
  486. .title {
  487. display: flex;
  488. justify-content: space-around;
  489. margin-bottom: 18px;
  490. }
  491. .bs-timer-item {
  492. display: flex;
  493. margin-bottom: 18px;
  494. }
  495. }
  496. ::v-deep .el-input__inner,
  497. ::v-deep .el-color-picker__color-inner,
  498. ::v-deep .el-input-number--mini,
  499. ::v-deep .el-textarea__inner,
  500. ::v-deep .el-input-group__append,
  501. ::v-deep .el-radio__label {
  502. background: var(--bs-el-background-1);
  503. color: var(--bs-el-text);
  504. border: 0 !important;
  505. }
  506. ::v-deep .el-form-item__label {
  507. color: var(--bs-el-title);
  508. font-size: 12px;
  509. }
  510. ::v-deep .el-radio {
  511. margin-right: 10px
  512. }
  513. ::v-deep .el-table {
  514. background: var(--bs-el-background-1);
  515. border-bottom: 1px solid var(--bs-el-title);
  516. }
  517. ::v-deep .el-table__cell {
  518. background: var(--bs-el-background-1) !important;
  519. color: var(--bs-el-title) !important;
  520. border-color: var(--bs-el-text) !important;
  521. }
  522. ::v-deep .el-input__inner {
  523. &:placeholder {
  524. color: var(--bs-el-text);
  525. }
  526. }
  527. }
  528. .bg-img {
  529. width: 180px;
  530. height: 150px;
  531. cursor: pointer;
  532. position: relative;
  533. }
  534. .close-icon {
  535. left: 150px;
  536. top: 10px;
  537. font-size: 24px;
  538. cursor: pointer;
  539. color: #ffffff;
  540. position: absolute;
  541. }
  542. .select {
  543. display: table-footer-group;
  544. }
  545. .description {
  546. display: block;
  547. margin-top: 8px;
  548. font-size: 12px;
  549. }
  550. .toolbar {
  551. width: 320px;
  552. height: 50px;
  553. bottom: 0;
  554. z-index: 10;
  555. position: fixed;
  556. text-align: center;
  557. display: flex;
  558. align-items: center;
  559. justify-content: center;
  560. background: var(--bs-background-1);
  561. .el-button {
  562. margin-right: 10px;
  563. }
  564. }
  565. ::v-deep .el-drawer__wrapper {
  566. z-index: 2000 !important;
  567. .setting-body {
  568. padding: 16px;
  569. }
  570. }
  571. ::v-deep .el-drawer__body {
  572. padding: 0;
  573. margin-bottom: 0;
  574. overflow: hidden;
  575. }
  576. ::v-deep .el-drawer__container {
  577. height: calc(100% - 40px) !important;
  578. top: 40px !important;
  579. position: relative;
  580. left: 0;
  581. right: 0;
  582. bottom: 0;
  583. width: 100%;
  584. }
  585. .select-item {
  586. display: flex;
  587. margin-bottom: 8px;
  588. cursor: pointer;
  589. align-items: center;
  590. border: 1px solid #fff;
  591. padding: 4px;
  592. .input-wrap {
  593. flex: 1;
  594. display: flex;
  595. justify-content: center;
  596. margin-right: 2px;
  597. color: #36474f;
  598. ::v-deep.el-form-item {
  599. margin-bottom: 0 !important;
  600. }
  601. .el-input-number--mini {
  602. width: 90px !important;
  603. }
  604. }
  605. .input-wrap-right {
  606. width: 30px;
  607. flex: unset;
  608. }
  609. .input-wrap_left {
  610. flex: 1;
  611. display: flex;
  612. align-items: center;
  613. justify-content: left;
  614. }
  615. .select-line-icon {
  616. width: 30px;
  617. font-size: 18px;
  618. cursor: pointer;
  619. text-align: center;
  620. }
  621. .option-delete {
  622. color: #f56c6c;
  623. }
  624. }
  625. ::v-deep .el-color-picker--mini .el-color-picker__trigger {
  626. height: 32px;
  627. width: 32px;
  628. border: 1px solid var(--bs-el-background-1);
  629. background: var(--bs-el-background-1);
  630. .el-color-picker__color {
  631. background: var(--bs-el-background-1);
  632. border: 0 !important;
  633. }
  634. }
  635. .side-catalog-box {
  636. height: calc(100% - 50px);
  637. overflow-y: auto;
  638. }
  639. </style>
  640. <style lang="scss">
  641. //修改notify的样式
  642. .ds-el-notify {
  643. background-color: var(--bs-el-background-1)!important;
  644. .el-notification__title{
  645. color: #fff!important;
  646. }
  647. .el-notification__content{
  648. color: #fff!important;
  649. }
  650. .el-notification__closeBtn{
  651. color: #fff!important;
  652. }
  653. }
  654. </style>