index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div
  3. class="bs-design-wrap"
  4. :class="`bs-current-time-${customTheme}`"
  5. >
  6. <div
  7. :class="[
  8. 'time',
  9. {
  10. 'light-theme': customTheme === 'light',
  11. 'auto-theme': customTheme == 'auto',
  12. 'dark-theme': customTheme == 'dark'
  13. }
  14. ]"
  15. class="time-text-box"
  16. :style="
  17. 'font-size:' +
  18. config.customize.fontSize +
  19. 'px;color:' +
  20. config.customize.color +
  21. ';font-weight:' +
  22. config.customize.fontWeight
  23. "
  24. >
  25. {{ nowTime }}
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import moment from 'moment'
  31. import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
  32. import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
  33. import cloneDeep from "lodash/cloneDeep";
  34. import {mapMutations, mapState} from 'vuex'
  35. export default {
  36. name: 'CurrentTime',
  37. mixins: [paramsMixins],
  38. props: {
  39. config: {
  40. type: Object,
  41. default: () => ({})
  42. }
  43. },
  44. computed: {
  45. ...mapState({
  46. customTheme: state => state.bigScreen.pageInfo.pageConfig.customTheme,
  47. activeCode: state => state.bigScreen.activeCode
  48. })
  49. },
  50. data () {
  51. return {
  52. nowTime: '',
  53. time: new Date(),
  54. currentTime: new Date()
  55. }
  56. },
  57. mounted () {
  58. this.getCurrentTime(this.config.dateFormat)
  59. },
  60. // 销毁定时器
  61. destroyed () {
  62. if (this.timer) {
  63. clearInterval(this.timer) // 关闭
  64. }
  65. },
  66. methods: {
  67. ...mapMutations({
  68. changeChartConfig: 'bigScreen/changeChartConfig',
  69. changeActiveItemConfig: 'bigScreen/changeActiveItemConfig'
  70. }),
  71. changeStyle (config) {
  72. this.getCurrentTime(config.dateFormat)
  73. config = { ...this.config, ...config }
  74. // 样式改变时更新主题配置
  75. config.theme = settingToTheme(cloneDeep(config), this.customTheme)
  76. this.changeChartConfig(config)
  77. if (config.code === this.activeCode) {
  78. this.changeActiveItemConfig(config)
  79. }
  80. },
  81. // 实时显示当前系统时间
  82. getCurrentTime (dateFormat) {
  83. if (this.timer) {
  84. clearInterval(this.timer)
  85. }
  86. this.dateFormat(dateFormat)
  87. this.timer = setInterval(() => {
  88. this.dateFormat(dateFormat)
  89. }, 1000)
  90. },
  91. // 格式化时间
  92. dateFormat () {
  93. this.nowTime = moment(new Date().getTime()).format(
  94. this.config.dateFormat
  95. )
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. @import "../../BasicComponents/fonts/index.css";
  102. .bs-design-wrap{
  103. width: 100%;
  104. }
  105. .time {
  106. width: 100%;
  107. height: 100%;
  108. display: flex;
  109. align-items: center;
  110. justify-content: center;
  111. }
  112. .light-theme {
  113. background-color: #ffffff;
  114. color: #000000;
  115. }
  116. .dark-theme {
  117. background-color: #000000;
  118. color: #ffffff;
  119. }
  120. .auto-theme {
  121. background-color: transparent;
  122. color: #000000;
  123. }
  124. .time-text-box{
  125. padding: 20px;
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. white-space:nowrap;
  130. box-sizing: border-box;
  131. }
  132. </style>