index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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-switch
  64. v-model="currentSnap"
  65. class="bs-el-switch"
  66. active-color="#007aff"
  67. :active-value="30"
  68. :inactive-value="3"
  69. @change="snapHandler"
  70. />
  71. </el-form-item>
  72. <el-form-item label="主题">
  73. <el-select
  74. v-model="form.customTheme"
  75. class="bs-el-select select"
  76. popper-class="bs-el-select"
  77. placeholder="请选择主题"
  78. clearable
  79. @change="changeTheme"
  80. >
  81. <el-option
  82. v-for="themeItem in themeOptions"
  83. :key="themeItem.value"
  84. :label="themeItem.label"
  85. :value="themeItem.value"
  86. />
  87. </el-select>
  88. </el-form-item>
  89. <el-form-item label="背景图">
  90. <el-button
  91. v-if="!form[currentBg]"
  92. type="primary"
  93. @click="$refs.bgImg.init()"
  94. >
  95. 选择背景图
  96. </el-button>
  97. <el-image
  98. v-if="form[currentBg]"
  99. class="bg-img bs-el-img"
  100. :src="getCoverPicture(form[currentBg])"
  101. fit="cover"
  102. @click="$refs.bgImg.init()"
  103. />
  104. <div
  105. v-show="form[currentBg]"
  106. @click="form[currentBg] = ''"
  107. >
  108. <i class="el-icon-circle-close close-icon" />
  109. </div>
  110. <span
  111. v-if="form[currentBg]"
  112. class="description"
  113. >(背景图优先级高于背景色,设置后将覆盖背景色)</span>
  114. <BgImg
  115. ref="bgImg"
  116. :form="form"
  117. @imgUrl="form[currentBg] = $event"
  118. />
  119. </el-form-item>
  120. <el-form-item label="背景色">
  121. <ColorPicker
  122. v-model="form[currentBgColor]"
  123. :placeholder="form[currentBg] ? '' : '请选择背景色'"
  124. :predefine-colors="predefineColors"
  125. />
  126. </el-form-item>
  127. </el-form>
  128. </div>
  129. <div>
  130. <SettingTitle>定时器</SettingTitle>
  131. <!-- 定时器空数据 -->
  132. <el-empty
  133. v-if="timerEmptyState()"
  134. description="请添加图表,并绑定数据集"
  135. />
  136. <div
  137. v-else
  138. class="bs-overall-setting-wrap"
  139. >
  140. <div class="title">
  141. <span>时间(秒)</span>
  142. <span>图表</span>
  143. <span />
  144. </div>
  145. <div
  146. v-for="(timer, index) in pageInfo.pageConfig.refreshConfig"
  147. :key="index"
  148. class="bs-timer-item"
  149. >
  150. <el-input-number
  151. v-model="timer.time"
  152. class="bs-el-input-number"
  153. :min="0"
  154. :max="999999"
  155. :step="1"
  156. placeholder="请输入定时器时间"
  157. style="margin-right: 8px;"
  158. />
  159. <el-select
  160. v-model="timer.code"
  161. class="bs-el-select"
  162. popper-class="bs-el-select"
  163. placeholder="请选择需要刷新的图表"
  164. @change="chartChange"
  165. >
  166. <el-option
  167. v-for="chart in chartOptions"
  168. :key="chart.code"
  169. :label="chart.title"
  170. :value="chart.code"
  171. :disabled="chart.disabled"
  172. />
  173. </el-select>
  174. <el-button
  175. style="margin-left: 8px;"
  176. class="bs-el-button-default"
  177. @click="deleteTimer(index)"
  178. >
  179. 删除
  180. </el-button>
  181. </div>
  182. <el-button
  183. v-if="pageInfo.chartList.length !== pageInfo.pageConfig.refreshConfig.length"
  184. type="primary"
  185. style="width: 100%;"
  186. @click="createTimer"
  187. >
  188. 新建
  189. </el-button>
  190. </div>
  191. </div>
  192. </el-scrollbar>
  193. </div>
  194. </template>
  195. <script>
  196. import SettingTitle from 'data-room-ui/SettingTitle/index.vue'
  197. import ColorPicker from 'data-room-ui/ColorPicker/index.vue'
  198. import BgImg from 'data-room-ui/BigScreenDesign/OverallSetting/BgImgDialog.vue'
  199. import { mapState, mapMutations } from 'vuex'
  200. import { themeToSetting } from 'data-room-ui/js/utils/themeFormatting'
  201. import { predefineColors } from 'data-room-ui/js/utils/colorList'
  202. import { getFileUrl } from 'data-room-ui/js/utils/file'
  203. export default {
  204. name: 'OverallSetting',
  205. components: {
  206. ColorPicker,
  207. SettingTitle,
  208. BgImg
  209. },
  210. directives: {
  211. block: {
  212. bind (el, binding) {
  213. el.style.width = binding.value || '100%'
  214. }
  215. }
  216. },
  217. data () {
  218. return {
  219. resolutionRatioValue: '',
  220. // 自适应模式 无(none) 、自动(auto)、宽度铺满(fitWidth)、高度铺满(fitHeight)和 双向铺满(cover) 5 种自适应模式
  221. autoModeOptions: [
  222. {
  223. value: 'none',
  224. label: '无'
  225. },
  226. {
  227. value: 'auto',
  228. label: '自动'
  229. },
  230. {
  231. value: 'fitWidth',
  232. label: '宽度铺满'
  233. },
  234. {
  235. value: 'fitHeight',
  236. label: '高度铺满'
  237. },
  238. {
  239. value: 'cover',
  240. label: '双向铺满'
  241. }
  242. ],
  243. drawerVisible: false,
  244. resolutionRatioOptions: [
  245. {
  246. value: '1024*768',
  247. label: '1024*768'
  248. },
  249. {
  250. value: '1280*720',
  251. label: '1280*720'
  252. },
  253. {
  254. value: '1920*1080',
  255. label: '1920*1080'
  256. },
  257. {
  258. value: '2560*1440',
  259. label: '2560*1440'
  260. },
  261. {
  262. value: '3840*2160',
  263. label: '3840*2160'
  264. },
  265. {
  266. value: '5120*2880',
  267. label: '5120*2880'
  268. },
  269. {
  270. value: '7680*4320',
  271. label: '7680*4320'
  272. }
  273. ],
  274. themeOptions: [
  275. {
  276. value: 'dark',
  277. label: '暗黑'
  278. },
  279. {
  280. value: 'light',
  281. label: '明亮'
  282. }
  283. // {
  284. // value: 'auto',
  285. // label: '透明'
  286. // },
  287. // {
  288. // value: 'custom',
  289. // label: '自定义'
  290. // }
  291. ],
  292. form: {
  293. w: 1920,
  294. h: 1080,
  295. bg: '',
  296. bgColor: '#151a26', // 背景色
  297. lightBg: '',
  298. lightBgColor: '#f5f7fa',
  299. opacity: 100,
  300. customTheme: 'dark',
  301. themeJson: {},
  302. cacheDataSets: [],
  303. refreshConfig: [],
  304. fitMode: 'none'
  305. },
  306. // 预设主题色
  307. predefineColors,
  308. // 图表列表
  309. chartOptions: []
  310. }
  311. },
  312. computed: {
  313. ...mapState({
  314. pageInfo: state => state.bigScreen.pageInfo,
  315. config: state => state.bigScreen.activeItemConfig
  316. }),
  317. currentSnap: {
  318. get () {
  319. // return this.snap
  320. return this.$store.state.bigScreen.snapTolerance
  321. },
  322. set (val) {
  323. }
  324. },
  325. isPreview () {
  326. return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
  327. },
  328. // 根据主题色来决定背景色和背景图绑定什么变量
  329. currentBgColor () {
  330. return this.form.customTheme === 'light' ? 'lightBgColor' : 'bgColor'
  331. },
  332. currentBg () {
  333. return this.form.customTheme === 'light' ? 'lightBg' : 'bg'
  334. },
  335. dsValue () {
  336. return this.form.cacheDataSets?.map(dSet => ({
  337. id: dSet.dataSetId,
  338. name: dSet.name
  339. })) || []
  340. }
  341. },
  342. watch: {
  343. form: {
  344. handler (val) {
  345. this.changePageConfig(val)
  346. // 改变大屏的整体配置后,需要判断元素是否在大屏内,如果不在大屏内,需要将元素尽量往内部靠拢
  347. this.pageInfo.chartList.forEach(item => {
  348. if (item.x + item.w > this.form.w) {
  349. item.x = this.form.w - item.w
  350. }
  351. if (item.y + item.h > this.form.h) {
  352. item.y = this.form.h - item.h
  353. }
  354. })
  355. },
  356. deep: true
  357. },
  358. 'pageInfo.pageConfig.refreshConfig': {
  359. handler (val) {
  360. if (Array.isArray(val) && val.length) {
  361. this.chartOptions.forEach(chart => {
  362. chart.disabled = val?.findIndex(item => item.code === chart.code) !== -1
  363. })
  364. }
  365. },
  366. deep: true
  367. }
  368. },
  369. created () { },
  370. mounted () {
  371. this.initResolution()
  372. this.init()
  373. },
  374. methods: {
  375. ...mapMutations('bigScreen', [
  376. 'changePageLoading',
  377. 'changePageConfig',
  378. 'changeLayout',
  379. 'changeChartKey',
  380. 'changeRefreshConfig',
  381. 'changePageInfo',
  382. 'snapChange'
  383. ]),
  384. // 切换主题时更新主题配置
  385. changeTheme (theme) {
  386. const pageInfo = this.pageInfo
  387. pageInfo.chartList = themeToSetting(pageInfo.chartList, theme)
  388. this.changePageInfo(pageInfo)
  389. pageInfo.chartList.forEach(chart => {
  390. if (chart.type === 'remoteComponent') {
  391. this.$emit('styleHandler', chart)
  392. }
  393. })
  394. if (!this.isPreview) {
  395. const themeLabel = theme === 'light' ? '明亮' : '暗黑'
  396. const htmlStr = `<span>当前已切换到<strong>${themeLabel}</strong>主题,颜色设置针对当前主题生效</span>`
  397. this.$notify({
  398. title: '注意',
  399. dangerouslyUseHTMLString: true,
  400. message: htmlStr,
  401. customClass: 'ds-el-notify',
  402. type: 'warning'
  403. })
  404. }
  405. },
  406. init () {
  407. if (!this.pageInfo.pageConfig.refreshConfig) {
  408. this.pageInfo.pageConfig.refreshConfig = []
  409. }
  410. this.form = { ...this.pageInfo.pageConfig }
  411. this.drawerVisible = true
  412. if (this.pageInfo.chartList.length === 0) {
  413. this.pageInfo.pageConfig.refreshConfig = []
  414. this.changeRefreshConfig([])
  415. this.form.refreshConfig = []
  416. } else {
  417. this.pageInfo.chartList.forEach(chart => {
  418. if (chart.dataSource?.businessKey || chart.type === 'marquee') {
  419. this.chartOptions.push({
  420. code: chart.code,
  421. title: chart.title,
  422. disabled: false
  423. })
  424. } else {
  425. this.pageInfo.pageConfig.refreshConfig = this.pageInfo?.pageConfig?.refreshConfig?.filter(item => item.code !== chart.code) || []
  426. }
  427. })
  428. }
  429. },
  430. // 添加定时器
  431. createTimer () {
  432. const timer = {
  433. code: '',
  434. time: 0
  435. }
  436. if (!this.pageInfo.pageConfig.refreshConfig) {
  437. this.pageInfo.pageConfig.refreshConfig = []
  438. }
  439. this.pageInfo.pageConfig.refreshConfig.push(timer)
  440. },
  441. chartChange (val) {
  442. this.chartOptions.find(item => item.code === val).disabled = true
  443. },
  444. deleteTimer (timerIndex) {
  445. this.pageInfo.pageConfig.refreshConfig.splice(timerIndex, 1)
  446. },
  447. resolutionRatioValueHandel (val) {
  448. if (val) {
  449. this.form.w = Number(val.split('*')[0])
  450. this.form.h = Number(val.split('*')[1])
  451. } else {
  452. this.form.w = this.pageInfo.type === 'component' ? 1024 : 1920
  453. this.form.h = this.pageInfo.type === 'component' ? 768 : 1080
  454. }
  455. },
  456. initResolution () {
  457. this.resolutionRatioValue = this.pageInfo.pageConfig.w + '*' + this.pageInfo.pageConfig.h
  458. },
  459. // 新增数据集
  460. addCacheDataSet () {
  461. this.form.cacheDataSets.push({
  462. // 数据集名称
  463. name: '',
  464. // 数据集id
  465. dataSetId: ''
  466. })
  467. },
  468. // 删除数据集
  469. deleteCacheDataSet (index) {
  470. this.form.cacheDataSets.splice(index, 1)
  471. },
  472. // 选择数据集
  473. getSelectDs (selectDs) {
  474. this.form.cacheDataSets = selectDs?.map(ds => ({
  475. name: ds.name,
  476. dataSetId: ds.id
  477. }))
  478. },
  479. close () {
  480. this.drawerVisible = false
  481. this.$emit('close')
  482. },
  483. timerEmptyState () {
  484. return this.pageInfo.chartList.every(chart => chart.dataSource?.businessKey === '' && chart.type !== 'marquee')
  485. },
  486. snapHandler (val) {
  487. // this.$emit('changeSnap', val)
  488. this.snapChange(val)
  489. },
  490. /**
  491. * 获取图片访问地址,如果是相对路径则拼接上文件访问前缀地址
  492. * @param url
  493. * @returns {*}
  494. */
  495. getCoverPicture (url) {
  496. return getFileUrl(url)
  497. }
  498. }
  499. }
  500. </script>
  501. <style lang="scss" scoped>
  502. @import '../../assets/style/bsTheme.scss';
  503. .bs-overall-wrap {
  504. position: relative;
  505. height: 100%;
  506. background: var(--bs-background-2);
  507. .bs-overall-setting-wrap {
  508. padding: 16px;
  509. .title {
  510. display: flex;
  511. justify-content: space-around;
  512. margin-bottom: 18px;
  513. }
  514. .bs-timer-item {
  515. display: flex;
  516. margin-bottom: 18px;
  517. }
  518. }
  519. ::v-deep .el-input__inner,
  520. ::v-deep .el-color-picker__color-inner,
  521. ::v-deep .el-input-number--mini,
  522. ::v-deep .el-textarea__inner,
  523. ::v-deep .el-input-group__append,
  524. ::v-deep .el-radio__label {
  525. background: var(--bs-el-background-1);
  526. color: var(--bs-el-text);
  527. border: 0 !important;
  528. }
  529. ::v-deep .el-form-item__label {
  530. color: var(--bs-el-title);
  531. font-size: 12px;
  532. }
  533. ::v-deep .el-radio {
  534. margin-right: 10px
  535. }
  536. ::v-deep .el-table {
  537. background: var(--bs-el-background-1);
  538. border-bottom: 1px solid var(--bs-el-title);
  539. }
  540. ::v-deep .el-table__cell {
  541. background: var(--bs-el-background-1) !important;
  542. color: var(--bs-el-title) !important;
  543. border-color: var(--bs-el-text) !important;
  544. }
  545. ::v-deep .el-input__inner {
  546. &:placeholder {
  547. color: var(--bs-el-text);
  548. }
  549. }
  550. }
  551. .bg-img {
  552. width: 180px;
  553. height: 150px;
  554. cursor: pointer;
  555. position: relative;
  556. }
  557. .close-icon {
  558. left: 150px;
  559. top: 10px;
  560. font-size: 24px;
  561. cursor: pointer;
  562. color: #ffffff;
  563. position: absolute;
  564. }
  565. .select {
  566. display: table-footer-group;
  567. }
  568. .description {
  569. display: block;
  570. margin-top: 8px;
  571. font-size: 12px;
  572. }
  573. .toolbar {
  574. width: 320px;
  575. height: 50px;
  576. bottom: 0;
  577. z-index: 10;
  578. position: fixed;
  579. text-align: center;
  580. display: flex;
  581. align-items: center;
  582. justify-content: center;
  583. background: var(--bs-background-1);
  584. .el-button {
  585. margin-right: 10px;
  586. }
  587. }
  588. ::v-deep .el-drawer__wrapper {
  589. z-index: 2000 !important;
  590. .setting-body {
  591. padding: 16px;
  592. }
  593. }
  594. ::v-deep .el-drawer__body {
  595. padding: 0;
  596. margin-bottom: 0;
  597. overflow: hidden;
  598. }
  599. ::v-deep .el-drawer__container {
  600. height: calc(100% - 40px) !important;
  601. top: 40px !important;
  602. position: relative;
  603. left: 0;
  604. right: 0;
  605. bottom: 0;
  606. width: 100%;
  607. }
  608. .select-item {
  609. display: flex;
  610. margin-bottom: 8px;
  611. cursor: pointer;
  612. align-items: center;
  613. border: 1px solid #fff;
  614. padding: 4px;
  615. .input-wrap {
  616. flex: 1;
  617. display: flex;
  618. justify-content: center;
  619. margin-right: 2px;
  620. color: #36474f;
  621. ::v-deep.el-form-item {
  622. margin-bottom: 0 !important;
  623. }
  624. .el-input-number--mini {
  625. width: 90px !important;
  626. }
  627. }
  628. .input-wrap-right {
  629. width: 30px;
  630. flex: unset;
  631. }
  632. .input-wrap_left {
  633. flex: 1;
  634. display: flex;
  635. align-items: center;
  636. justify-content: left;
  637. }
  638. .select-line-icon {
  639. width: 30px;
  640. font-size: 18px;
  641. cursor: pointer;
  642. text-align: center;
  643. }
  644. .option-delete {
  645. color: #f56c6c;
  646. }
  647. }
  648. ::v-deep .el-color-picker--mini .el-color-picker__trigger {
  649. height: 32px;
  650. width: 32px;
  651. border: 1px solid var(--bs-el-background-1);
  652. background: var(--bs-el-background-1);
  653. .el-color-picker__color {
  654. background: var(--bs-el-background-1);
  655. border: 0 !important;
  656. }
  657. }
  658. .side-catalog-box {
  659. height: calc(100% - 50px);
  660. overflow-y: auto;
  661. }
  662. </style>
  663. <style lang="scss">
  664. //修改notify的样式
  665. .ds-el-notify {
  666. background-color: var(--bs-el-background-1)!important;
  667. border: var(--bs-el-border)!important;
  668. .el-notification__title{
  669. color: #fff!important;
  670. }
  671. .el-notification__content{
  672. color: #fff!important;
  673. }
  674. .el-notification__closeBtn{
  675. color: #fff!important;
  676. }
  677. }
  678. </style>