index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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: '#151a26',
  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. // 根据主题色来决定背景色和背景图绑定什么变量
  316. currentBgColor () {
  317. return this.form.customTheme === 'dark' ? 'bgColor' : 'lightBgColor'
  318. },
  319. currentBg () {
  320. return this.form.customTheme === 'dark' ? 'bg' : 'lightBgColor'
  321. },
  322. dsValue () {
  323. return this.form.cacheDataSets?.map(dSet => ({
  324. id: dSet.dataSetId,
  325. name: dSet.name
  326. })) || []
  327. }
  328. },
  329. watch: {
  330. form: {
  331. handler (val) {
  332. this.changePageConfig(val)
  333. // 改变大屏的整体配置后,需要判断元素是否在大屏内,如果不在大屏内,需要将元素尽量往内部靠拢
  334. this.pageInfo.chartList.forEach(item => {
  335. if (item.x + item.w > this.form.w) {
  336. item.x = this.form.w - item.w
  337. }
  338. if (item.y + item.h > this.form.h) {
  339. item.y = this.form.h - item.h
  340. }
  341. })
  342. },
  343. deep: true
  344. },
  345. 'pageInfo.pageConfig.refreshConfig': {
  346. handler (val) {
  347. if (Array.isArray(val) && val.length) {
  348. this.chartOptions.forEach(chart => {
  349. chart.disabled = val?.findIndex(item => item.code === chart.code) !== -1
  350. })
  351. }
  352. },
  353. deep: true
  354. }
  355. },
  356. created () { },
  357. mounted () {
  358. this.initResolution()
  359. this.init()
  360. },
  361. methods: {
  362. ...mapMutations('bigScreen', [
  363. 'changePageLoading',
  364. 'changePageConfig',
  365. 'changeLayout',
  366. 'changeChartKey',
  367. 'changeRefreshConfig',
  368. 'changePageInfo'
  369. ]),
  370. // 切换主题时更新主题配置
  371. changeTheme (theme) {
  372. const pageInfo = this.pageInfo
  373. pageInfo.chartList = themeToSetting(pageInfo.chartList, theme)
  374. this.changePageInfo(pageInfo)
  375. pageInfo.chartList.forEach(chart => {
  376. // if (chart.type === 'remoteComponent')
  377. })
  378. },
  379. init () {
  380. if (!this.pageInfo.pageConfig.refreshConfig) {
  381. this.pageInfo.pageConfig.refreshConfig = []
  382. }
  383. this.form = { ...this.pageInfo.pageConfig }
  384. this.drawerVisible = true
  385. if (this.pageInfo.chartList.length === 0) {
  386. this.pageInfo.pageConfig.refreshConfig = []
  387. this.changeRefreshConfig([])
  388. this.form.refreshConfig = []
  389. } else {
  390. this.pageInfo.chartList.forEach(chart => {
  391. if (chart.dataSource?.businessKey || chart.type === 'marquee') {
  392. this.chartOptions.push({
  393. code: chart.code,
  394. title: chart.title,
  395. disabled: false
  396. })
  397. } else {
  398. this.pageInfo.pageConfig.refreshConfig = this.pageInfo?.pageConfig?.refreshConfig?.filter(item => item.code !== chart.code) || []
  399. }
  400. })
  401. }
  402. },
  403. // 添加定时器
  404. createTimer () {
  405. const timer = {
  406. code: '',
  407. time: 0
  408. }
  409. if (!this.pageInfo.pageConfig.refreshConfig) {
  410. this.pageInfo.pageConfig.refreshConfig = []
  411. }
  412. this.pageInfo.pageConfig.refreshConfig.push(timer)
  413. },
  414. chartChange (val) {
  415. this.chartOptions.find(item => item.code === val).disabled = true
  416. },
  417. deleteTimer (timerIndex) {
  418. this.pageInfo.pageConfig.refreshConfig.splice(timerIndex, 1)
  419. },
  420. resolutionRatioValueHandel (val) {
  421. if (val) {
  422. this.form.w = Number(val.split('*')[0])
  423. this.form.h = Number(val.split('*')[1])
  424. } else {
  425. this.form.w = this.pageInfo.type === 'component' ? 1024 : 1920
  426. this.form.h = this.pageInfo.type === 'component' ? 768 : 1080
  427. }
  428. },
  429. initResolution () {
  430. this.resolutionRatioValue = this.pageInfo.pageConfig.w + '*' + this.pageInfo.pageConfig.h
  431. },
  432. // 新增数据集
  433. addCacheDataSet () {
  434. this.form.cacheDataSets.push({
  435. // 数据集名称
  436. name: '',
  437. // 数据集id
  438. dataSetId: ''
  439. })
  440. },
  441. // 删除数据集
  442. deleteCacheDataSet (index) {
  443. this.form.cacheDataSets.splice(index, 1)
  444. },
  445. // 选择数据集
  446. getSelectDs (selectDs) {
  447. this.form.cacheDataSets = selectDs?.map(ds => ({
  448. name: ds.name,
  449. dataSetId: ds.id
  450. }))
  451. },
  452. close () {
  453. this.drawerVisible = false
  454. this.$emit('close')
  455. },
  456. timerEmptyState () {
  457. return this.pageInfo.chartList.every(chart => chart.dataSource?.businessKey === '')
  458. }
  459. }
  460. }
  461. </script>
  462. <style lang="scss" scoped>
  463. @import '../../assets/style/bsTheme.scss';
  464. .bs-overall-wrap {
  465. position: relative;
  466. height: 100%;
  467. background: var(--bs-background-2);
  468. .bs-overall-setting-wrap {
  469. padding: 16px;
  470. .title {
  471. display: flex;
  472. justify-content: space-around;
  473. margin-bottom: 18px;
  474. }
  475. .bs-timer-item {
  476. display: flex;
  477. margin-bottom: 18px;
  478. }
  479. }
  480. ::v-deep .el-input__inner,
  481. ::v-deep .el-color-picker__color-inner,
  482. ::v-deep .el-input-number--mini,
  483. ::v-deep .el-textarea__inner,
  484. ::v-deep .el-input-group__append,
  485. ::v-deep .el-radio__label {
  486. background: var(--bs-el-background-1);
  487. color: var(--bs-el-text);
  488. border: 0 !important;
  489. }
  490. ::v-deep .el-form-item__label {
  491. color: var(--bs-el-title);
  492. font-size: 12px;
  493. }
  494. ::v-deep .el-radio {
  495. margin-right: 10px
  496. }
  497. ::v-deep .el-table {
  498. background: var(--bs-el-background-1);
  499. border-bottom: 1px solid var(--bs-el-title);
  500. }
  501. ::v-deep .el-table__cell {
  502. background: var(--bs-el-background-1) !important;
  503. color: var(--bs-el-title) !important;
  504. border-color: var(--bs-el-text) !important;
  505. }
  506. ::v-deep .el-input__inner {
  507. &:placeholder {
  508. color: var(--bs-el-text);
  509. }
  510. }
  511. }
  512. .bg-img {
  513. width: 180px;
  514. height: 150px;
  515. cursor: pointer;
  516. position: relative;
  517. }
  518. .close-icon {
  519. left: 150px;
  520. top: 10px;
  521. font-size: 24px;
  522. cursor: pointer;
  523. color: #ffffff;
  524. position: absolute;
  525. }
  526. .select {
  527. display: table-footer-group;
  528. }
  529. .description {
  530. display: block;
  531. margin-top: 8px;
  532. font-size: 12px;
  533. }
  534. .toolbar {
  535. width: 320px;
  536. height: 50px;
  537. bottom: 0;
  538. z-index: 10;
  539. position: fixed;
  540. text-align: center;
  541. display: flex;
  542. align-items: center;
  543. justify-content: center;
  544. background: var(--bs-background-1);
  545. .el-button {
  546. margin-right: 10px;
  547. }
  548. }
  549. ::v-deep .el-drawer__wrapper {
  550. z-index: 2000 !important;
  551. .setting-body {
  552. padding: 16px;
  553. }
  554. }
  555. ::v-deep .el-drawer__body {
  556. padding: 0;
  557. margin-bottom: 0;
  558. overflow: hidden;
  559. }
  560. ::v-deep .el-drawer__container {
  561. height: calc(100% - 40px) !important;
  562. top: 40px !important;
  563. position: relative;
  564. left: 0;
  565. right: 0;
  566. bottom: 0;
  567. width: 100%;
  568. }
  569. .select-item {
  570. display: flex;
  571. margin-bottom: 8px;
  572. cursor: pointer;
  573. align-items: center;
  574. border: 1px solid #fff;
  575. padding: 4px;
  576. .input-wrap {
  577. flex: 1;
  578. display: flex;
  579. justify-content: center;
  580. margin-right: 2px;
  581. color: #36474f;
  582. ::v-deep.el-form-item {
  583. margin-bottom: 0 !important;
  584. }
  585. .el-input-number--mini {
  586. width: 90px !important;
  587. }
  588. }
  589. .input-wrap-right {
  590. width: 30px;
  591. flex: unset;
  592. }
  593. .input-wrap_left {
  594. flex: 1;
  595. display: flex;
  596. align-items: center;
  597. justify-content: left;
  598. }
  599. .select-line-icon {
  600. width: 30px;
  601. font-size: 18px;
  602. cursor: pointer;
  603. text-align: center;
  604. }
  605. .option-delete {
  606. color: #f56c6c;
  607. }
  608. }
  609. ::v-deep .el-color-picker--mini .el-color-picker__trigger {
  610. height: 32px;
  611. width: 32px;
  612. border: 1px solid var(--bs-el-background-1);
  613. background: var(--bs-el-background-1);
  614. .el-color-picker__color {
  615. background: var(--bs-el-background-1);
  616. border: 0 !important;
  617. }
  618. }
  619. .side-catalog-box {
  620. height: calc(100% - 50px);
  621. overflow-y: auto;
  622. }
  623. </style>