index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 'packages/js/mixins/paramsMixins'
  32. export default {
  33. name: 'CurrentTime',
  34. mixins: [paramsMixins],
  35. props: {
  36. config: {
  37. type: Object,
  38. default: () => ({})
  39. }
  40. },
  41. data () {
  42. return {
  43. nowTime: '',
  44. time: new Date(),
  45. currentTime: new Date()
  46. }
  47. },
  48. mounted () {
  49. this.getCurrentTime(this.config.dateFormat)
  50. },
  51. // 销毁定时器
  52. destroyed () {
  53. if (this.timer) {
  54. clearInterval(this.timer) // 关闭
  55. }
  56. },
  57. methods: {
  58. changeStyle (config) {
  59. this.getCurrentTime(config.dateFormat)
  60. },
  61. // 实时显示当前系统时间
  62. getCurrentTime (dateFormat) {
  63. if (this.timer) {
  64. clearInterval(this.timer)
  65. }
  66. this.dateFormat(dateFormat)
  67. this.timer = setInterval(() => {
  68. this.dateFormat(dateFormat)
  69. }, 1000)
  70. },
  71. // 格式化时间
  72. dateFormat () {
  73. this.nowTime = moment(new Date().getTime()).format(
  74. this.config.dateFormat
  75. )
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. @import "../../BasicComponents/fonts/index.css";
  82. .bs-design-wrap{
  83. width: 100%;
  84. }
  85. .time {
  86. width: 100%;
  87. height: 100%;
  88. display: flex;
  89. align-items: center;
  90. justify-content: center;
  91. }
  92. .light-theme {
  93. background-color: #ffffff;
  94. color: #000000;
  95. }
  96. .dark-theme {
  97. background-color: #000000;
  98. color: #ffffff;
  99. }
  100. .auto-theme {
  101. background-color: transparent;
  102. color: #000000;
  103. }
  104. .time-text-box{
  105. padding: 20px;
  106. display: flex;
  107. align-items: center;
  108. justify-content: center;
  109. white-space:nowrap;
  110. box-sizing: border-box;
  111. }
  112. </style>