index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. // 根据主题色来决定背景色和背景图绑定什么变量
  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. this.$emit('styleHandler', chart)
  378. }
  379. })
  380. },
  381. init () {
  382. if (!this.pageInfo.pageConfig.refreshConfig) {
  383. this.pageInfo.pageConfig.refreshConfig = []
  384. }
  385. this.form = { ...this.pageInfo.pageConfig }
  386. this.drawerVisible = true
  387. if (this.pageInfo.chartList.length === 0) {
  388. this.pageInfo.pageConfig.refreshConfig = []
  389. this.changeRefreshConfig([])
  390. this.form.refreshConfig = []
  391. } else {
  392. this.pageInfo.chartList.forEach(chart => {
  393. if (chart.dataSource?.businessKey || chart.type === 'marquee') {
  394. this.chartOptions.push({
  395. code: chart.code,
  396. title: chart.title,
  397. disabled: false
  398. })
  399. } else {
  400. this.pageInfo.pageConfig.refreshConfig = this.pageInfo?.pageConfig?.refreshConfig?.filter(item => item.code !== chart.code) || []
  401. }
  402. })
  403. }
  404. },
  405. // 添加定时器
  406. createTimer () {
  407. const timer = {
  408. code: '',
  409. time: 0
  410. }
  411. if (!this.pageInfo.pageConfig.refreshConfig) {
  412. this.pageInfo.pageConfig.refreshConfig = []
  413. }
  414. this.pageInfo.pageConfig.refreshConfig.push(timer)
  415. },
  416. chartChange (val) {
  417. this.chartOptions.find(item => item.code === val).disabled = true
  418. },
  419. deleteTimer (timerIndex) {
  420. this.pageInfo.pageConfig.refreshConfig.splice(timerIndex, 1)
  421. },
  422. resolutionRatioValueHandel (val) {
  423. if (val) {
  424. this.form.w = Number(val.split('*')[0])
  425. this.form.h = Number(val.split('*')[1])
  426. } else {
  427. this.form.w = this.pageInfo.type === 'component' ? 1024 : 1920
  428. this.form.h = this.pageInfo.type === 'component' ? 768 : 1080
  429. }
  430. },
  431. initResolution () {
  432. this.resolutionRatioValue = this.pageInfo.pageConfig.w + '*' + this.pageInfo.pageConfig.h
  433. },
  434. // 新增数据集
  435. addCacheDataSet () {
  436. this.form.cacheDataSets.push({
  437. // 数据集名称
  438. name: '',
  439. // 数据集id
  440. dataSetId: ''
  441. })
  442. },
  443. // 删除数据集
  444. deleteCacheDataSet (index) {
  445. this.form.cacheDataSets.splice(index, 1)
  446. },
  447. // 选择数据集
  448. getSelectDs (selectDs) {
  449. this.form.cacheDataSets = selectDs?.map(ds => ({
  450. name: ds.name,
  451. dataSetId: ds.id
  452. }))
  453. },
  454. close () {
  455. this.drawerVisible = false
  456. this.$emit('close')
  457. },
  458. timerEmptyState () {
  459. return this.pageInfo.chartList.every(chart => chart.dataSource?.businessKey === '')
  460. }
  461. }
  462. }
  463. </script>
  464. <style lang="scss" scoped>
  465. @import '../../assets/style/bsTheme.scss';
  466. .bs-overall-wrap {
  467. position: relative;
  468. height: 100%;
  469. background: var(--bs-background-2);
  470. .bs-overall-setting-wrap {
  471. padding: 16px;
  472. .title {
  473. display: flex;
  474. justify-content: space-around;
  475. margin-bottom: 18px;
  476. }
  477. .bs-timer-item {
  478. display: flex;
  479. margin-bottom: 18px;
  480. }
  481. }
  482. ::v-deep .el-input__inner,
  483. ::v-deep .el-color-picker__color-inner,
  484. ::v-deep .el-input-number--mini,
  485. ::v-deep .el-textarea__inner,
  486. ::v-deep .el-input-group__append,
  487. ::v-deep .el-radio__label {
  488. background: var(--bs-el-background-1);
  489. color: var(--bs-el-text);
  490. border: 0 !important;
  491. }
  492. ::v-deep .el-form-item__label {
  493. color: var(--bs-el-title);
  494. font-size: 12px;
  495. }
  496. ::v-deep .el-radio {
  497. margin-right: 10px
  498. }
  499. ::v-deep .el-table {
  500. background: var(--bs-el-background-1);
  501. border-bottom: 1px solid var(--bs-el-title);
  502. }
  503. ::v-deep .el-table__cell {
  504. background: var(--bs-el-background-1) !important;
  505. color: var(--bs-el-title) !important;
  506. border-color: var(--bs-el-text) !important;
  507. }
  508. ::v-deep .el-input__inner {
  509. &:placeholder {
  510. color: var(--bs-el-text);
  511. }
  512. }
  513. }
  514. .bg-img {
  515. width: 180px;
  516. height: 150px;
  517. cursor: pointer;
  518. position: relative;
  519. }
  520. .close-icon {
  521. left: 150px;
  522. top: 10px;
  523. font-size: 24px;
  524. cursor: pointer;
  525. color: #ffffff;
  526. position: absolute;
  527. }
  528. .select {
  529. display: table-footer-group;
  530. }
  531. .description {
  532. display: block;
  533. margin-top: 8px;
  534. font-size: 12px;
  535. }
  536. .toolbar {
  537. width: 320px;
  538. height: 50px;
  539. bottom: 0;
  540. z-index: 10;
  541. position: fixed;
  542. text-align: center;
  543. display: flex;
  544. align-items: center;
  545. justify-content: center;
  546. background: var(--bs-background-1);
  547. .el-button {
  548. margin-right: 10px;
  549. }
  550. }
  551. ::v-deep .el-drawer__wrapper {
  552. z-index: 2000 !important;
  553. .setting-body {
  554. padding: 16px;
  555. }
  556. }
  557. ::v-deep .el-drawer__body {
  558. padding: 0;
  559. margin-bottom: 0;
  560. overflow: hidden;
  561. }
  562. ::v-deep .el-drawer__container {
  563. height: calc(100% - 40px) !important;
  564. top: 40px !important;
  565. position: relative;
  566. left: 0;
  567. right: 0;
  568. bottom: 0;
  569. width: 100%;
  570. }
  571. .select-item {
  572. display: flex;
  573. margin-bottom: 8px;
  574. cursor: pointer;
  575. align-items: center;
  576. border: 1px solid #fff;
  577. padding: 4px;
  578. .input-wrap {
  579. flex: 1;
  580. display: flex;
  581. justify-content: center;
  582. margin-right: 2px;
  583. color: #36474f;
  584. ::v-deep.el-form-item {
  585. margin-bottom: 0 !important;
  586. }
  587. .el-input-number--mini {
  588. width: 90px !important;
  589. }
  590. }
  591. .input-wrap-right {
  592. width: 30px;
  593. flex: unset;
  594. }
  595. .input-wrap_left {
  596. flex: 1;
  597. display: flex;
  598. align-items: center;
  599. justify-content: left;
  600. }
  601. .select-line-icon {
  602. width: 30px;
  603. font-size: 18px;
  604. cursor: pointer;
  605. text-align: center;
  606. }
  607. .option-delete {
  608. color: #f56c6c;
  609. }
  610. }
  611. ::v-deep .el-color-picker--mini .el-color-picker__trigger {
  612. height: 32px;
  613. width: 32px;
  614. border: 1px solid var(--bs-el-background-1);
  615. background: var(--bs-el-background-1);
  616. .el-color-picker__color {
  617. background: var(--bs-el-background-1);
  618. border: 0 !important;
  619. }
  620. }
  621. .side-catalog-box {
  622. height: calc(100% - 50px);
  623. overflow-y: auto;
  624. }
  625. </style>