topBox.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view>
  3. <view class="top">
  4. <view class="img_logo" :style="{ width: width, height: height }">
  5. <image class="img" :src="img"></image>
  6. </view>
  7. <view class="time">
  8. <view class="">
  9. {{ today }}
  10. </view>
  11. <view style="margin-left: 2%">
  12. {{ currentTime }}
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'topBox',
  21. props: {
  22. img: {
  23. type: String,
  24. default: '/static/img/img_logo.png'
  25. },
  26. width: {
  27. type: [String, Number] // 可以是字符串或数字类型
  28. },
  29. height: {
  30. type: [String, Number] // 可以是字符串或数字类型
  31. }
  32. },
  33. data() {
  34. return { currentTime: '', today: '' };
  35. },
  36. watch: {
  37. currentTime(newVal, oldVal) {
  38. if (newVal === oldVal) return;
  39. this.currentTime = newVal;
  40. },
  41. today(newVal, oldVal) {
  42. if (newVal === oldVal) return;
  43. this.today = newVal;
  44. }
  45. },
  46. mounted() {
  47. this.updateTime();
  48. setInterval(() => {
  49. this.updateTime();
  50. }, 1000);
  51. },
  52. methods: {
  53. // 获取时间
  54. updateTime() {
  55. const now = new Date();
  56. let hours = now.getHours();
  57. let minutes = now.getMinutes();
  58. minutes = ('0' + minutes).slice(-2);
  59. this.currentTime = hours + ':' + minutes;
  60. let month = now.getMonth() + 1;
  61. let day = now.getDate();
  62. month = ('0' + month).slice(-2);
  63. this.today = month + '月' + day + '日';
  64. }
  65. }
  66. };
  67. </script>
  68. <style>
  69. .top {
  70. width: 100%;
  71. height: 20vh;
  72. background: linear-gradient(0deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.3) 50%, rgba(0, 0, 0, 0.5) 100%);
  73. }
  74. .img {
  75. width: 100%;
  76. height: 100%;
  77. }
  78. .img_logo {
  79. position: absolute;
  80. width: 10%;
  81. height: 38%;
  82. margin: 3% 0 0 5%;
  83. /* background: url('/static/img/img_logo.png') no-repeat; */
  84. /* background-size: 100% 100%; */
  85. }
  86. .time {
  87. width: 25%;
  88. display: flex;
  89. align-items: center;
  90. position: absolute;
  91. right: -1%;
  92. top: 30%;
  93. color: #ffffff;
  94. z-index: 100;
  95. font-size: 14px;
  96. }
  97. </style>