index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <view class="tabPage" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='打卡' bgColor="transparent" :showback="false"></cus-header>
  4. <image class="topbg" :src="imgBase+'clockingin/topbg.png'" mode="widthFix"></image>
  5. <div class="info">
  6. <div class="i_avatar">
  7. <image :src="imgBase+'clockingin/default_avatar.png'"></image>
  8. </div>
  9. <div class="i_name_date">
  10. <p>{{username}}</p>
  11. <p class="date">{{dateweek}}</p>
  12. </div>
  13. </div>
  14. <div class="card">
  15. <div class="c_title">今日打卡</div>
  16. <div class="c_worktime">
  17. <div class="cw_pre">
  18. <p>上班08:30</p>
  19. <div class="cwp_time">
  20. <image :src="imgBase+'clockingin/checked_active.png'"></image>
  21. <span>打卡{{sbClockTime||'- -'}}</span>
  22. </div>
  23. <div class="cwp_status active">已打卡</div>
  24. </div>
  25. <div class="cw_pre">
  26. <p>下班20:00</p>
  27. <div class="cwp_time">
  28. <image :src="imgBase+'clockingin/checked_inactive.png'"></image>
  29. <span>{{xbClockTime||'- -'}}</span>
  30. </div>
  31. <div class="cwp_status inactive">未打卡</div>
  32. </div>
  33. </div>
  34. <div class="c_clock">
  35. <div class="cc_box" :style="{'background-image':'url('+imgBase+'clockingin/clock_active_bg.png)'}" @tap="clock">
  36. <p>{{isSW?'上班':'下班'}}打卡</p>
  37. <p class="time">{{currentSFM}}</p>
  38. </div>
  39. <div class="cc_location">
  40. <image :src="imgBase+'clockingin/location_active.png'"></image>
  41. <span>已进入考勤范围:谷锐特设备自动化有限公司</span>
  42. <!-- <span>当前定位不在考勤范围内</span> -->
  43. </div>
  44. </div>
  45. </div>
  46. <u-popup :show="show" @close="close" mode="center" :round="32" :customStyle="{'width':'calc(100% - 120rpx)'}">
  47. <div class="up_box">
  48. <div class="upb_close">
  49. <image :src="imgBase+'clockingin/close.png'" @tap="close"></image>
  50. </div>
  51. <image class="upb_text" :src="imgBase+'clockingin/clock_success.png'"></image>
  52. <p class="upb_time">打卡时间 {{clockTime}}</p>
  53. <image class="upb_img" :src="imgBase+'clockingin/clock_success2.png'"></image>
  54. <div class="upb_btn" @tap="close">我知道了</div>
  55. </div>
  56. </u-popup>
  57. <Tabbar :tabbarIndex="0"></Tabbar>
  58. </view>
  59. </template>
  60. <script>
  61. var timer = null;
  62. const QQMapWX = require('../static/lib/qqmap-wx-jssdk.min.js');
  63. const qqmapsdk = new QQMapWX({
  64. key: 'V3NBZ-6NRKT-QOQXY-LU6RY-PNHJ5-QDBTQKEY'
  65. });
  66. import Tabbar from '@/components/CusTabbar/clock.vue'
  67. export default {
  68. components:{ Tabbar },
  69. data(){
  70. return {
  71. username:'王勇毅',
  72. dateweek:'',
  73. sbClockTime:'08::24',
  74. xbClockTime:'',
  75. isSW:true,//是否是上午,12点前是上午,12点后是下午
  76. currentSFM:new Date().Format('hh:mm:ss'),
  77. show:false,
  78. clockTime:'',
  79. distance: null,
  80. targetLocation: { //谷锐特 31.962084,117.020446 /跨境电商大厦 31.865786,117.15297
  81. latitude: 31.865786,
  82. longitude: 117.15297
  83. }
  84. }
  85. },
  86. created() {
  87. this.getDateWeek();
  88. this.getCurrentSFM();
  89. this.getCurrentHour();
  90. },
  91. onUnload() {
  92. clearInterval(timer)
  93. },
  94. mounted() {
  95. this.getCurrentLocation();
  96. },
  97. methods:{
  98. getDateWeek(){
  99. let date = new Date().Format('yyyy年MM月dd日');
  100. let cfg = {0:'天',1:'一',2:'二',3:'三',4:'四',5:'五',6:'六'};
  101. let week = cfg[new Date().getDay()];
  102. this.dateweek = date+' 星期'+week;
  103. },
  104. getCurrentSFM(){
  105. timer = setInterval(()=>{
  106. this.currentSFM = new Date().Format('hh:mm:ss');
  107. },1000)
  108. },
  109. getCurrentHour(){
  110. this.isSW = new Date().getHours()>12?false:true;
  111. },
  112. clock(){
  113. this.clockTime = new Date().Format('hh:mm');
  114. this.show = true;
  115. },
  116. close(){
  117. this.show = false;
  118. },
  119. // 获取当前位置
  120. async getCurrentLocation() {
  121. try {
  122. const res = await uni.getLocation({
  123. type: 'gcj02 ', // 腾讯地图使用GCJ-02坐标系/
  124. isHighAccuracy: true
  125. });
  126. console.log(res);
  127. this.calculateDistance(
  128. res[1].latitude,
  129. res[1].longitude,
  130. this.targetLocation.latitude,
  131. this.targetLocation.longitude
  132. );
  133. console.log(this.distance,'distance');
  134. } catch (err) {
  135. uni.showToast({
  136. title: '获取位置失败,请检查权限设置',
  137. icon: 'none'
  138. });
  139. }
  140. },
  141. // 计算两点间距离
  142. calculateDistance(lat1, lng1, lat2, lng2) {
  143. qqmapsdk.calculateDistance({
  144. mode: 'straight', // 直线距离
  145. from: `${lat1},${lng1}`,
  146. to: `${lat2},${lng2}`,
  147. success: (res) => {
  148. if(res.result && res.result.elements.length > 0) {
  149. this.distance = res.result.elements[0].distance;
  150. }
  151. },
  152. fail: (err) => {
  153. uni.showToast({
  154. title: '距离计算失败',
  155. icon: 'none'
  156. });
  157. }
  158. });
  159. }
  160. }
  161. }
  162. </script>
  163. <style scoped lang="less">
  164. .tabPage{
  165. padding: 0 24rpx 188rpx;
  166. background: #F4F8FB;
  167. .topbg{
  168. width: 100%;
  169. position: fixed;
  170. top: 0;
  171. left: 0;
  172. z-index: 0;
  173. }
  174. .info{
  175. position: relative;
  176. background: #FFFFFF;
  177. border-radius: 16rpx;
  178. margin-top: 20rpx;
  179. padding: 48rpx 24rpx;
  180. display: flex;
  181. align-items: center;
  182. .i_avatar{
  183. width: 98rpx;
  184. height: 98rpx;
  185. image{
  186. width: 100%;
  187. height: 100%;
  188. }
  189. }
  190. .i_name_date{
  191. padding-left: 24rpx;
  192. p{
  193. font-family: PingFang-SC, PingFang-SC;
  194. font-weight: bold;
  195. font-size: 36rpx;
  196. color: #1D2129;
  197. line-height: 36rpx;
  198. &.date{
  199. font-size: 28rpx;
  200. color: #657588;
  201. line-height: 28rpx;
  202. margin-top: 22rpx;
  203. }
  204. }
  205. }
  206. }
  207. .card{
  208. position: relative;
  209. background: #FFFFFF;
  210. border-radius: 16rpx;
  211. padding: 44rpx 24rpx 211rpx;
  212. margin-top: 20rpx;
  213. .c_title{
  214. font-family: PingFang-SC, PingFang-SC;
  215. font-weight: bold;
  216. font-size: 36rpx;
  217. color: #1D2129;
  218. line-height: 36rpx;
  219. }
  220. .c_worktime{
  221. margin-top: 40rpx;
  222. display: flex;
  223. justify-content: space-between;
  224. .cw_pre{
  225. width: calc(50% - 15rpx);
  226. background: #F5F8FA;
  227. border-radius: 16rpx;
  228. position: relative;
  229. padding: 36rpx 20rpx;
  230. box-sizing: border-box;
  231. &>p{
  232. font-family: PingFangSC, PingFang SC;
  233. font-weight: 400;
  234. font-size: 32rpx;
  235. color: #1D2129;
  236. line-height: 32rpx;
  237. }
  238. .cwp_time{
  239. display: flex;
  240. align-items: center;
  241. margin-top: 32rpx;
  242. image{
  243. width: 28rpx;
  244. height: 28rpx;
  245. }
  246. span{
  247. font-family: PingFangSC, PingFang SC;
  248. font-weight: 400;
  249. font-size: 28rpx;
  250. color: #86909C;
  251. line-height: 36rpx;
  252. margin-left: 12rpx;
  253. }
  254. }
  255. .cwp_status{
  256. width: 108rpx;
  257. height: 54rpx;
  258. border-radius: 0rpx 16rpx 0rpx 12rpx;
  259. font-family: PingFang-SC, PingFang-SC;
  260. font-weight: bold;
  261. font-size: 24rpx;
  262. line-height: 54rpx;
  263. text-align: center;
  264. position: absolute;
  265. top: 0;
  266. right: 0;
  267. &.active{
  268. color: #14D08E;
  269. background: rgba(20, 204, 140, 0.08);
  270. }
  271. &.inactive{
  272. color: #86909C;
  273. background: #EFEFEF;
  274. }
  275. }
  276. }
  277. }
  278. .c_clock{
  279. display: flex;
  280. flex-direction: column;
  281. align-items: center;
  282. margin-top: 117rpx;
  283. .cc_box{
  284. width: 306rpx;
  285. height: 306rpx;
  286. background-repeat: no-repeat;
  287. background-size: 100% 100%;
  288. display: flex;
  289. flex-direction: column;
  290. align-items: center;
  291. justify-content: center;
  292. p{
  293. font-family: PingFang-SC, PingFang-SC;
  294. font-weight: bold;
  295. font-size: 40rpx;
  296. color: #FFFFFF;
  297. line-height: 56rpx;
  298. &.time{
  299. font-size: 32rpx;
  300. line-height: 45rpx;
  301. margin-top: 8px;
  302. }
  303. }
  304. }
  305. .cc_location{
  306. margin-top: 64rpx;
  307. display: flex;
  308. align-items: center;
  309. image{
  310. width: 36rpx;
  311. height: 36rpx;
  312. }
  313. span{
  314. font-family: PingFangSC, PingFang SC;
  315. font-weight: 400;
  316. font-size: 26rpx;
  317. color: #86909C;
  318. line-height: 26rpx;
  319. margin-left: 10rpx;
  320. }
  321. }
  322. }
  323. }
  324. .up_box{
  325. background: linear-gradient( 134deg, #E7F4FD 0%, #FFFFFF 100%);
  326. border-radius: 32rpx;
  327. padding: 40rpx;
  328. display: flex;
  329. flex-direction: column;
  330. align-items: center;
  331. .upb_close{
  332. width: 100%;
  333. display: flex;
  334. justify-content: flex-end;
  335. image{
  336. width: 32rpx;
  337. height: 32rpx;
  338. }
  339. }
  340. .upb_text{
  341. width: 210rpx;
  342. height: 50rpx;
  343. margin-top: 16rpx;
  344. }
  345. .upb_time{
  346. font-family: PingFangSC, PingFang SC;
  347. font-weight: 400;
  348. font-size: 28rpx;
  349. color: #86909C;
  350. line-height: 32rpx;
  351. margin-top: 36rpx;
  352. }
  353. .upb_img{
  354. width: 344rpx;
  355. height: 194rpx;
  356. margin-top: 216rpx;
  357. }
  358. .upb_btn{
  359. width: 446rpx;
  360. height: 88rpx;
  361. background: #0171F6;
  362. border-radius: 32rpx;
  363. font-family: PingFang-SC, PingFang-SC;
  364. font-weight: bold;
  365. font-size: 32rpx;
  366. color: #FFFFFF;
  367. line-height: 88rpx;
  368. text-align: center;
  369. margin-top: 112rpx;
  370. letter-spacing: 2rpx;
  371. }
  372. }
  373. }
  374. </style>