index.vue 3.1 KB

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