index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div :class="'logo-container-' + layout">
  3. <router-link to="/">
  4. <vab-remix-icon v-if="logo" class="logo" :icon-class="logo" />
  5. <span
  6. class="title"
  7. :class="{ 'hidden-xs-only': layout === 'horizontal' }"
  8. :title="title"
  9. >
  10. {{ title }}
  11. </span>
  12. </router-link>
  13. <!--时间展示区(包含毫秒)-->
  14. <span class="compact-time-display">
  15. <span class="time-line utc-time">
  16. {{ "天文时间:" + formattedUTCTime }}
  17. </span>
  18. &nbsp;&nbsp;
  19. <span class="time-line local-time">
  20. {{ "绝对时间:" + formattedLocalTime }}
  21. </span>
  22. </span>
  23. </div>
  24. </template>
  25. <script>
  26. import { mapGetters } from "vuex";
  27. export default {
  28. name: "VabLogo",
  29. data() {
  30. return {
  31. title: this.$baseTitle,
  32. timer: null,
  33. currentTime: new Date(),
  34. };
  35. },
  36. computed: {
  37. ...mapGetters({
  38. logo: "settings/logo",
  39. layout: "settings/layout",
  40. }),
  41. formattedUTCTime() {
  42. return this.formatUTCTime(this.currentTime);
  43. },
  44. formattedLocalTime() {
  45. return this.formatLocalTime(this.currentTime);
  46. },
  47. },
  48. mounted() {
  49. // 改为每10毫秒更新一次(确保毫秒级精度)
  50. this.timer = setInterval(() => {
  51. this.currentTime = new Date();
  52. }, 10);
  53. },
  54. beforeDestroy() {
  55. clearInterval(this.timer);
  56. },
  57. methods: {
  58. // 格式化UTC时间(包含毫秒)
  59. formatUTCTime(date) {
  60. const pad = (num, length = 2) => String(num).padStart(length, "0");
  61. return `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(
  62. date.getUTCDate()
  63. )} ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${pad(
  64. date.getUTCSeconds()
  65. )} UTC`;
  66. },
  67. // 格式化本地时间(包含毫秒)
  68. formatLocalTime(date) {
  69. const pad = (num, length = 2) => String(num).padStart(length, "0");
  70. const hours = date.getHours();
  71. const ampm = hours >= 12 ? "PM" : "AM";
  72. const displayHours = hours % 12 || 12;
  73. return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(
  74. date.getDate()
  75. )} ${pad(displayHours)}:${pad(date.getMinutes())}:${pad(
  76. date.getSeconds()
  77. )} ${ampm}`;
  78. },
  79. },
  80. };
  81. </script>
  82. <style lang="scss" scoped>
  83. @mixin container {
  84. position: relative;
  85. height: $base-top-bar-height;
  86. overflow: hidden;
  87. line-height: $base-top-bar-height;
  88. background: $base-menu-background;
  89. }
  90. @mixin logo {
  91. display: inline-block;
  92. width: 34px;
  93. height: 34px;
  94. margin-right: 3px;
  95. color: $base-title-color;
  96. vertical-align: middle;
  97. }
  98. @mixin title {
  99. display: inline-block;
  100. overflow: hidden;
  101. font-size: 20px;
  102. line-height: 55px;
  103. color: $base-title-color;
  104. text-overflow: ellipsis;
  105. white-space: nowrap;
  106. vertical-align: middle;
  107. }
  108. .logo-container-horizontal {
  109. @include container;
  110. .logo {
  111. @include logo;
  112. }
  113. .title {
  114. @include title;
  115. }
  116. }
  117. .logo-container-vertical {
  118. @include container;
  119. height: $base-logo-height;
  120. line-height: $base-logo-height;
  121. text-align: center;
  122. .logo {
  123. @include logo;
  124. }
  125. .title {
  126. @include title;
  127. max-width: calc(#{$base-left-menu-width} - 60px);
  128. }
  129. }
  130. .compact-time-display {
  131. font-size: 20px;
  132. font-family: "Courier New", monospace;
  133. padding: 12px;
  134. border-radius: 6px;
  135. background-color: transparent;
  136. line-height: 1.5;
  137. display: inline-block;
  138. vertical-align: middle;
  139. .time-line {
  140. font-weight: 800;
  141. white-space: nowrap;
  142. font-size: 12px;
  143. &.utc-time {
  144. color: #8d978f;
  145. font-size: 18px;
  146. font-weight: 800;
  147. }
  148. &.local-time {
  149. color: #8d978f;
  150. font-size: 18px;
  151. }
  152. }
  153. }
  154. </style>