clockIn.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="clock">
  3. <view class="clock-button">
  4. <view class="clock-button-outer">
  5. <view class="clock-button-inner">
  6. <view class="tips">
  7. <view>上班打卡</view>
  8. <view>{{ currentTime }}</view>
  9. </view>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="clock-tips">
  14. <view class="clock-tips-content">
  15. <u-icon name="checkmark-circle-fill" color="#0E9CFF" size="15"></u-icon>
  16. <view>已经进入考勤范围,<view class="address">{{ address }}</view><text @click="positionLocation()">重新定位?</text></view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import QQMapWX from '@/static/js/qqmap-wx-jssdk.min.js'
  23. export default {
  24. data() {
  25. return {
  26. currentTime: '',
  27. qqMap: new QQMapWX({ key: 'CWWBZ-F2T36-ZQ6SU-EDL5X-Y3EUT-3HBIF', vm: this }),
  28. address: ''
  29. }
  30. },
  31. onShow() {
  32. this.currentDate();
  33. this.positionLocation()
  34. },
  35. onUnload() {
  36. if (this.formatDate) {
  37. clearInterval(this.formatDate); // 在Vue实例销毁前,清除时间定时器
  38. }
  39. },
  40. methods: {
  41. positionLocation() {
  42. uni.showLoading({
  43. title: '定位中...'
  44. })
  45. wx.getLocation({
  46. type: 'gcj02',
  47. success: (res) => {
  48. this.qqMap.reverseGeocoder({
  49. location: {
  50. longitude: res.longitude,
  51. latitude: res.latitude
  52. },
  53. success: (res) => {
  54. if (res?.result?.formatted_addresses) {
  55. this.address = res.result.formatted_addresses.recommend;
  56. } else {
  57. uni.showToast({
  58. title: '获取位置失败!',
  59. duration: 3000
  60. })
  61. }
  62. uni.hideLoading()
  63. },
  64. fail: () => {
  65. uni.showToast({
  66. title: '获取位置失败!',
  67. duration: 3000
  68. })
  69. uni.hideLoading()
  70. }
  71. })
  72. },
  73. fail: () => {
  74. uni.showToast({
  75. title: '获取位置失败!',
  76. duration: 3000
  77. })
  78. uni.hideLoading()
  79. }
  80. });
  81. },
  82. currentDate() {
  83. setInterval(this.formatDate, 500);
  84. },
  85. formatDate() {
  86. let date = new Date();
  87. let year = date.getFullYear(); // 年
  88. let month = date.getMonth() + 1; // 月
  89. let day = date.getDate(); // 日
  90. let week = date.getDay(); // 星期
  91. let hour = date.getHours(); // 时
  92. hour = hour < 10 ? "0" + hour : hour; // 如果只有一位,则前面补零
  93. let minute = date.getMinutes(); // 分
  94. minute = minute < 10 ? "0" + minute : minute; // 如果只有一位,则前面补零
  95. let second = date.getSeconds(); // 秒
  96. second = second < 10 ? "0" + second : second; // 如果只有一位,则前面补零
  97. this.currentTime = `${hour}:${minute}:${second}`;
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .clock {
  104. &-button {
  105. position: relative;
  106. animation-name: example;
  107. animation-duration: 2s;
  108. animation-fill-mode: forwards;
  109. &-outer {
  110. margin: 0 auto;
  111. width: 270rpx;
  112. height: 270rpx;
  113. background-color: #98D4FE;
  114. border-radius: 50%;
  115. display: flex;
  116. justify-content: center;
  117. align-items: center;
  118. }
  119. @keyframes example {
  120. from {
  121. top: 0;
  122. }
  123. to {
  124. top: 286rpx;
  125. }
  126. }
  127. &-inner {
  128. width: 220rpx;
  129. height: 220rpx;
  130. background-color: #0E9CFF;
  131. border-radius: 50%;
  132. display: flex;
  133. align-items: center;
  134. justify-content: center;
  135. color: #fff;
  136. .tips {
  137. view {
  138. color: #f2f2f2;
  139. font-size: 34rpx;
  140. text-align: center;
  141. &:last-child {
  142. color: #ddd;
  143. font-size: 30rpx;
  144. margin-top: 10rpx;
  145. }
  146. }
  147. }
  148. }
  149. }
  150. &-tips {
  151. text-align: center;
  152. margin-top: 320rpx;
  153. &-content {
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. color: #000;
  158. font-size: 24rpx;
  159. view {
  160. margin-left: 5rpx;
  161. text {
  162. color: #F4993A;
  163. }
  164. }
  165. }
  166. }
  167. }
  168. .address {
  169. display: inline-block;
  170. width: 200rpx;
  171. line-height: 24rpx;
  172. overflow: hidden;
  173. white-space: nowrap;
  174. text-overflow: ellipsis;
  175. }
  176. </style>