index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // 实时显示当前系统时间
  59. getCurrentTime (dateFormat) {
  60. if (this.timer) {
  61. clearInterval(this.timer)
  62. }
  63. this.dateFormat(dateFormat)
  64. this.timer = setInterval(() => {
  65. this.dateFormat(dateFormat)
  66. }, 1000)
  67. },
  68. // 格式化时间
  69. dateFormat () {
  70. this.nowTime = moment(new Date().getTime()).format(
  71. this.config.dateFormat
  72. )
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. @import "~packages/BasicComponents/fonts/index.css";
  79. .bs-design-wrap{
  80. width: 100%;
  81. }
  82. .time {
  83. width: 100%;
  84. height: 100%;
  85. display: flex;
  86. align-items: center;
  87. justify-content: center;
  88. }
  89. .light-theme {
  90. background-color: #ffffff;
  91. color: #000000;
  92. }
  93. .dark-theme {
  94. background-color: #000000;
  95. color: #ffffff;
  96. }
  97. .auto-theme {
  98. background-color: transparent;
  99. color: #000000;
  100. }
  101. .time-text-box{
  102. padding: 20px;
  103. display: flex;
  104. align-items: center;
  105. justify-content: center;
  106. white-space:nowrap;
  107. box-sizing: border-box;
  108. }
  109. </style>