index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="page flex-center" :class="cross?'column':'row'">
  3. <view :style="'width:'+long+'px;'+'height:'+long+'px;'" class="clock" @click="showApm()">
  4. <clock :num='hours' :long="long" :apm="apm" style="height: 100% !important;"></clock>
  5. </view>
  6. <view :style="'width:'+long+'px;'+'height:'+long+'px;'" class="clock" @click="hidden()">
  7. <clock :num='minutes' :long="long" style="height: 100% !important;"></clock>
  8. </view>
  9. <block v-if="isshow">
  10. <view :style="'width:'+long+'px;'+'height:'+long+'px;'" class="clock">
  11. <clock :num='seconds' :long="long" style="height: 100% !important;"></clock>
  12. </view>
  13. </block>
  14. </view>
  15. </template>
  16. <script>
  17. import clock from './clock.vue'
  18. export default {
  19. components: {
  20. clock
  21. },
  22. data() {
  23. return {
  24. hours: '',
  25. minutes: '',
  26. seconds: '',
  27. width: 0,
  28. long: 80,
  29. cross: false,
  30. isshow: true,
  31. isapm: false,
  32. apm: ''
  33. }
  34. },
  35. created() {
  36. this.timer();
  37. // #ifdef APP-PLUS
  38. // 屏幕常亮
  39. uni.setKeepScreenOn({
  40. keepScreenOn: true
  41. });
  42. // 隐藏状态栏
  43. plus.navigator.setFullscreen(true);
  44. // #endif
  45. },
  46. watch: {
  47. hours() {
  48. // console.log('时');
  49. },
  50. minutes() {
  51. // console.log('分');
  52. },
  53. seconds() {
  54. // console.log(this.seconds + '秒');
  55. }
  56. },
  57. methods: {
  58. timer() {
  59. let date = new Date()
  60. let hours = date.getHours().toString()
  61. this.apm = '';
  62. if (this.isapm && hours <= 12) {
  63. this.apm = 'AM'
  64. }
  65. if (this.isapm && hours > 12) {
  66. hours = hours - 12;
  67. this.apm = 'PM'
  68. }
  69. let minutes = date.getMinutes().toString();
  70. minutes = minutes >= 10 ? minutes : ('0' + minutes);
  71. let seconds = date.getSeconds().toString();
  72. seconds = seconds >= 10 ? seconds : ('0' + seconds);
  73. if (this.hours != hours) {
  74. this.hours = hours;
  75. }
  76. if (this.minutes != minutes) {
  77. this.minutes = minutes;
  78. }
  79. if (this.seconds != seconds) {
  80. this.seconds = seconds;
  81. }
  82. setTimeout(() => {
  83. this.timer()
  84. }, 100);
  85. },
  86. hidden() {
  87. this.isshow = !this.isshow;
  88. this.init();
  89. },
  90. showApm() {
  91. this.isapm = !this.isapm;
  92. }
  93. }
  94. }
  95. </script>
  96. <style>
  97. .flex-center {
  98. display: flex;
  99. justify-content: center;
  100. align-items: center;
  101. }
  102. .row {
  103. flex-direction: row;
  104. }
  105. .column {
  106. flex-direction: column;
  107. }
  108. .clock {
  109. padding: 2%;
  110. }
  111. </style>