home.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. <template>
  2. <view class="container">
  3. <view class="placeholder"></view>
  4. <!-- 头部学生信息区域 -->
  5. <view class="header">
  6. <view class="img"><img :src="userInfo.headImage || headImage" /></view>
  7. <view class="msg">
  8. <view class="name">{{ userInfo.name || '用户' }}</view>
  9. <view class="major">{{ userInfo.college || '南昌交通学院' }}</view>
  10. </view>
  11. </view>
  12. <!-- 主体打卡区域 -->
  13. <view class="body">
  14. <!-- 卡片区域 -->
  15. <view class="card" v-if="list.length">
  16. <!-- 每一个卡片区域 -->
  17. <view :class="activeid == item.id ? 'active_box' : 'item'" v-for="item in list" :key="item.id" @click="handleClick(item)">
  18. <view class="item_box">
  19. <view class="title">{{ item.ruleName }}</view>
  20. <view class="time">{{ item.timeRange }}</view>
  21. <view class="type">
  22. <img v-if="item.status == 4" src="./imgs/success.png" />
  23. <span v-if="item.status == 4">{{ format_time(item.updateTime) }}</span>
  24. <span v-if="item.status == 4">已打卡</span>
  25. <span v-if="item.status == 3">已超时</span>
  26. <span v-if="item.status == 1 || item.status == 2">未打卡</span>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- list数组为空时的占位盒子 -->
  32. <view class="card" v-else></view>
  33. <!-- 打卡区域 -->
  34. <view :class="{ clock: flags, active: !flags }" @click="handlePunch(contrastObj)">
  35. <view class="info" v-if="flags">打卡</view>
  36. <view class="info" v-else>无法打卡</view>
  37. <view class="time">{{ nowTime }}</view>
  38. </view>
  39. <!-- 提示信息位置 -->
  40. <view class="address" v-if="flags">{{ address }}</view>
  41. <view class="address" v-else>{{ notes }}</view>
  42. </view>
  43. <!-- 底部导航栏区域 -->
  44. <view class="tab_bar">
  45. <navigator open-type="redirect" url="/pages/home/home" class="tab_box">
  46. <img v-if="pageUrl == 'pages/home/home'" src="../../static/imgs/home_active.png" />
  47. <img v-else src="../../static/imgs/home.png" />
  48. <view v-if="pageUrl == 'pages/home/home'" class="tab_title_active">首页</view>
  49. <view v-else class="tab_title">首页</view>
  50. </navigator>
  51. <navigator open-type="redirect" url="/pages/stat/stat" class="tab_box">
  52. <img v-if="pageUrl == 'pages/stat/stat'" src="../../static/imgs/stat_active.png" />
  53. <img v-else src="../../static/imgs/stat.png" />
  54. <view v-if="pageUrl == 'pages/stat/stat'" class="tab_title_active">统计</view>
  55. <view v-else class="tab_title">统计</view>
  56. </navigator>
  57. <navigator open-type="redirect" v-if="showTab" url="/pages/my/my" class="tab_box">
  58. <img v-if="pageUrl == 'pages/my/my'" src="../../static/imgs/my_active.png" />
  59. <img v-else src="../../static/imgs/my.png" />
  60. <view v-if="pageUrl == 'pages/my/my'" class="tab_title_active">我的</view>
  61. <view v-else class="tab_title">我的</view>
  62. </navigator>
  63. </view>
  64. <!-- 认证结果弹窗 -->
  65. <uni-popup ref="popup" :is-mask-click="false">
  66. <view class="popup-content">
  67. <view class="title">
  68. <view class="icon"><img src="./imgs/success2.png" /></view>
  69. <view class="title_info">打卡成功</view>
  70. </view>
  71. <view class="time">{{ nowTime_pop }}</view>
  72. <view class="popup_button" @click="handleGoHome">我知道了</view>
  73. </view>
  74. </uni-popup>
  75. </view>
  76. </template>
  77. <script>
  78. import headImage from '../../static/imgs/headImage.png'
  79. export default {
  80. data() {
  81. return {
  82. // 用户信息
  83. userInfo: {},
  84. // 打卡规则列表
  85. list: [],
  86. // 当前时间
  87. nowTime: '',
  88. // 弹窗当前时间
  89. nowTime_pop: '',
  90. // 当前定位位置信息
  91. address: '',
  92. // 定时器标识
  93. timer: null,
  94. // 提示信息
  95. notes: '',
  96. // 当前显示的是哪个规则id
  97. activeid: null,
  98. // 当前时间的时间戳
  99. timestamp: null,
  100. // 当前显示的规则具体信息
  101. contrastObj: {},
  102. // 当前用户定位经度
  103. myLng: 0,
  104. // 当前用户定位纬度
  105. myLat: 0,
  106. // 签到点中心经度
  107. centerLng: 0,
  108. // 签到点中心纬度
  109. centerLat: 0,
  110. // 签到半径
  111. radius: 0,
  112. // 距离签到点的距离
  113. distance: 0,
  114. // 是否可以打卡的标识
  115. flags: false,
  116. // 当前页面的路由地址
  117. pageUrl: '',
  118. // 是否显示底部 我的 导航栏
  119. showTab: false,
  120. // 是否需要人脸识别
  121. faceRecognition: true,
  122. // 是否需要拍摄场景照片
  123. takePicture: true,
  124. headImage: headImage
  125. }
  126. },
  127. onLoad() {
  128. // 获取用户的个人信息数据
  129. this.getUserInfo()
  130. // 获取当前系统时间
  131. this.getNowTime()
  132. },
  133. onShow() {
  134. // 获取当前页面路径
  135. this.getPageUrl()
  136. // 获取当前位置的详细信息
  137. this.getLocationData()
  138. // 获取当前时间的时间戳
  139. this.getTimestamp()
  140. },
  141. onUnload() {
  142. if (this.timer) {
  143. clearInterval(this.timer)
  144. }
  145. },
  146. // 下拉刷新
  147. onPullDownRefresh() {
  148. uni.removeStorageSync('manager')
  149. uni.removeStorageSync('sub-administrator')
  150. this.getNowTime()
  151. this.getTimestamp()
  152. this.getUserInfo()
  153. this.getLocationData()
  154. setTimeout(() => {
  155. uni.stopPullDownRefresh()
  156. }, 1500)
  157. },
  158. methods: {
  159. getPageUrl() {
  160. // 获取当前打开过的页面路由数组
  161. let routes = getCurrentPages()
  162. // 获取当前页面路由,也就是最后一个打开的页面路由
  163. let curRoute = routes[routes.length - 1].route
  164. this.pageUrl = curRoute
  165. },
  166. // 获取当前时间
  167. getNowTime() {
  168. if (this.timer) {
  169. clearInterval(this.timer)
  170. }
  171. this.timer = setInterval(() => {
  172. let date = new Date()
  173. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  174. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  175. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  176. this.nowTime = hours + ':' + minutes + ':' + seconds
  177. }, 1000)
  178. },
  179. // 获取当前时间的时间戳
  180. getTimestamp() {
  181. let dates = new Date()
  182. let times = dates.getTime()
  183. this.timestamp = times
  184. },
  185. // 获取用户详细信息
  186. async getUserInfo() {
  187. let res = await this.$myRequest_clockIn({
  188. url: `/attendance/api/system/user/detail`
  189. })
  190. // console.log(res)
  191. if (res.code == 200) {
  192. this.userInfo = res.data
  193. uni.setStorageSync('clockIn_userInfo', this.userInfo)
  194. if (this.userInfo.roles) {
  195. let temList = []
  196. this.userInfo.roles.forEach(ele => {
  197. temList.push(ele.id)
  198. })
  199. let flag = temList.includes('2' || 2)
  200. let flag2 = temList.includes('3' || 3)
  201. if (flag) {
  202. uni.setStorageSync('manager', flag)
  203. } else {
  204. uni.removeStorageSync('manager')
  205. }
  206. if (flag2) {
  207. uni.setStorageSync('sub-administrator', flag2)
  208. } else {
  209. uni.removeStorageSync('sub-administrator')
  210. }
  211. let flag_show = uni.getStorageSync('manager')
  212. let flag_show2 = uni.getStorageSync('sub-administrator')
  213. if (flag_show || flag_show2) {
  214. this.showTab = true
  215. } else {
  216. this.showTab = false
  217. }
  218. }
  219. }
  220. },
  221. // 获取当前定位位置信息
  222. getLocationData() {
  223. // 获取经纬度
  224. uni.getLocation({
  225. type: 'gcj02',
  226. success: res => {
  227. const KEY = 'X57BZ-ZISE3-KTN3O-3P45H-C3J7Q-D5B67'
  228. let url = 'https://apis.map.qq.com/ws/geocoder/v1'
  229. let locationdata = res.latitude + ',' + res.longitude
  230. this.$jsonp(url, {
  231. key: KEY,
  232. output: 'jsonp',
  233. location: locationdata
  234. })
  235. .then(json => {
  236. // console.log(json)
  237. if (json.status == 0) {
  238. // 获取详细地址信息 经纬度
  239. this.address = json.result.address
  240. this.myLat = json.result.location.lat
  241. this.myLng = json.result.location.lng
  242. // 获取当天的打卡列表数组
  243. this.getRulesList()
  244. } else {
  245. uni.showToast({
  246. title: `${json.message},请求定位失败`,
  247. icon: 'none'
  248. })
  249. }
  250. })
  251. .catch(err => {
  252. console.log(err)
  253. })
  254. }
  255. })
  256. },
  257. // 获取打卡规则列表
  258. async getRulesList() {
  259. let res = await this.$myRequest_clockIn({
  260. url: '/attendance/api/sign/check/in/list/today'
  261. })
  262. // console.log(res)
  263. if (res.code == 200) {
  264. if (res.data.length == 0) {
  265. this.flags = false
  266. this.notes = '无打卡任务无需打卡'
  267. } else {
  268. this.flags = true
  269. this.list = res.data
  270. this.activeid = this.list[0].id
  271. this.faceRecognition = this.list[0].faceRecognition
  272. this.takePicture = this.list[0].takePicture
  273. this.contrastObj = this.list[0]
  274. this.changeType()
  275. }
  276. }
  277. },
  278. // 对比信息改变打卡的状态显示
  279. changeType() {
  280. if (this.contrastObj.status == 4) {
  281. this.flags = false
  282. this.notes = '已打卡,无需再次打卡'
  283. } else {
  284. // 没有到打卡时间 或者 超过打卡时间 的状态
  285. if (this.timestamp < this.contrastObj.beginTime || this.timestamp > this.contrastObj.endTime) {
  286. this.flags = false
  287. this.notes = '不在打卡时间段内,无法打卡'
  288. }
  289. // 到了打卡时间,判断是否在打卡范围内
  290. else {
  291. if (this.contrastObj.locations.length) {
  292. let temList = []
  293. temList = this.contrastObj.locations.map(ele => {
  294. this.centerLat = ele.lat
  295. this.centerLng = ele.lng
  296. this.radius = ele.radius
  297. let red1 = (this.myLat * Math.PI) / 180.0
  298. let red2 = (this.centerLat * Math.PI) / 180.0
  299. let a = red1 - red2
  300. let b = (this.myLng * Math.PI) / 180.0 - (this.centerLng * Math.PI) / 180.0
  301. let R = 6378137
  302. let distance = R * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(red1) * Math.cos(red2) * Math.pow(Math.sin(b / 2), 2)))
  303. this.distance = distance.toFixed(2) * 1
  304. // console.log(this.distance);
  305. // console.log(this.radius);
  306. if (this.distance <= this.radius) {
  307. return 1
  308. } else {
  309. return 2
  310. }
  311. })
  312. let temFlag = temList.indexOf(1)
  313. if (temFlag == -1) {
  314. this.flags = false
  315. this.notes = '不在管理员设定范围内,无法打卡'
  316. } else {
  317. this.flags = true
  318. }
  319. }
  320. }
  321. }
  322. },
  323. // 点击每一个打卡规则回调
  324. handleClick(item) {
  325. // console.log(item);
  326. this.getTimestamp()
  327. this.contrastObj = item
  328. this.activeid = item.id
  329. this.faceRecognition = item.faceRecognition
  330. this.takePicture = item.takePicture
  331. this.changeType()
  332. },
  333. // 点击打卡按钮回调
  334. handlePunch(info) {
  335. if (this.flags) {
  336. let obj = JSON.stringify(info)
  337. // 如果场景照片和人脸识别都需要
  338. if (this.faceRecognition && this.takePicture) {
  339. uni.navigateTo({
  340. url: `/pages/location/location?obj=${obj}`
  341. })
  342. }
  343. // 如果都不需要
  344. else if (!this.faceRecognition && !this.takePicture) {
  345. this.handleUploading()
  346. }
  347. // 如果只需要场景照片
  348. else if (this.takePicture) {
  349. uni.navigateTo({
  350. url: `/pages/location/location?obj=${obj}&flag=1`
  351. })
  352. }
  353. // 如果只需要人脸识别
  354. else if (this.faceRecognition) {
  355. uni.navigateTo({
  356. url: `/pages/authentication/authentication?id=${this.contrastObj.id}&address=${this.address}&latitude=${this.myLat}&longitude=${this.myLng}&flag=1`
  357. })
  358. // uni.navigateTo({
  359. // url: `/pages/location/location?obj=${obj}&flag=1`
  360. // })
  361. }
  362. }
  363. },
  364. // handlePunch(info) {
  365. // if (this.flags) {
  366. // let obj = JSON.stringify(info)
  367. // // 如果需要场景照片
  368. // if (this.takePicture) {
  369. // uni.navigateTo({
  370. // url: `/pages/location/location?obj=${obj}&flag=1`
  371. // })
  372. // } else {
  373. // this.handleUploading()
  374. // }
  375. // }
  376. // },
  377. // 打卡请求
  378. async handleUploading() {
  379. let res = await this.$myRequest_clockIn({
  380. url: '/attendance/api/sign/check/in/update',
  381. method: 'put',
  382. header: {
  383. 'content-type': 'application/json'
  384. },
  385. data: {
  386. id: this.contrastObj.id,
  387. lat: this.myLat,
  388. lng: this.myLng,
  389. location: this.address
  390. }
  391. })
  392. // console.log(res);
  393. if (res.code == 200) {
  394. this.getNowTimePop()
  395. this.$refs.popup.open()
  396. }
  397. },
  398. // 点击 我知道了按钮 跳回首页
  399. handleGoHome() {
  400. this.$refs.popup.close()
  401. uni.reLaunch({
  402. url: '/pages/home/home'
  403. })
  404. },
  405. getNowTimePop() {
  406. let date = new Date()
  407. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  408. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  409. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  410. this.nowTime_pop = hours + ':' + minutes + ':' + seconds
  411. },
  412. // 格式化时间
  413. format_time(timestamp) {
  414. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  415. var date = new Date(timestamp)
  416. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
  417. var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  418. let strDate = h + m
  419. return strDate
  420. }
  421. }
  422. }
  423. </script>
  424. <style lang="scss" scoped>
  425. .container {
  426. width: 100vw;
  427. height: 100vh;
  428. background-color: #f2f2f2;
  429. .placeholder {
  430. height: 20rpx;
  431. }
  432. .header {
  433. display: flex;
  434. margin: 0 30rpx 30rpx 30rpx;
  435. width: 690rpx;
  436. height: 130rpx;
  437. background-color: #fff;
  438. .img {
  439. margin: 30rpx;
  440. width: 70rpx;
  441. height: 70rpx;
  442. img {
  443. width: 100%;
  444. height: 100%;
  445. }
  446. }
  447. .msg {
  448. margin: 30rpx 0;
  449. height: 70rpx;
  450. line-height: 36rpx;
  451. .name {
  452. font-size: 32rpx;
  453. font-weight: 400;
  454. }
  455. .major {
  456. font-size: 24rpx;
  457. font-weight: 400;
  458. color: #a6a6a6;
  459. }
  460. }
  461. }
  462. .body {
  463. margin: 0 30rpx;
  464. width: 690rpx;
  465. height: 75vh;
  466. background-color: #fff;
  467. .card {
  468. padding-top: 30rpx;
  469. white-space: nowrap;
  470. height: 160rpx;
  471. overflow-x: auto;
  472. .active_box {
  473. display: inline-block;
  474. margin: 0 15rpx;
  475. width: 300rpx;
  476. height: 130rpx;
  477. line-height: 12rpx;
  478. border-radius: 8rpx;
  479. font-weight: 400;
  480. background-color: #e6e6e6;
  481. border: 1rpx solid #0094fc;
  482. .item_box {
  483. display: flex;
  484. flex-direction: column;
  485. justify-content: space-evenly;
  486. height: 130rpx;
  487. padding-left: 30rpx;
  488. .title {
  489. font-size: 28rpx;
  490. }
  491. .time {
  492. font-size: 24rpx;
  493. }
  494. .type {
  495. font-size: 24rpx;
  496. color: #808080;
  497. img {
  498. margin-right: 10rpx;
  499. width: 20rpx;
  500. height: 20rpx;
  501. }
  502. }
  503. }
  504. }
  505. .item {
  506. display: inline-block;
  507. margin: 0 15rpx;
  508. width: 300rpx;
  509. height: 130rpx;
  510. line-height: 12rpx;
  511. border-radius: 8rpx;
  512. font-weight: 400;
  513. background-color: #e6e6e6;
  514. .item_box {
  515. display: flex;
  516. flex-direction: column;
  517. justify-content: space-evenly;
  518. height: 130rpx;
  519. padding-left: 30rpx;
  520. .title {
  521. font-size: 28rpx;
  522. }
  523. .time {
  524. font-size: 24rpx;
  525. }
  526. .type {
  527. font-size: 24rpx;
  528. color: #808080;
  529. img {
  530. margin-right: 10rpx;
  531. width: 20rpx;
  532. height: 20rpx;
  533. }
  534. }
  535. }
  536. }
  537. }
  538. .clock {
  539. display: flex;
  540. flex-direction: column;
  541. justify-content: center;
  542. align-items: center;
  543. margin: auto;
  544. margin-top: 145rpx;
  545. width: 300rpx;
  546. height: 300rpx;
  547. border-radius: 150rpx;
  548. text-align: center;
  549. color: #fff;
  550. background: linear-gradient(180deg, #00acfc 0%, #0082fc 100%);
  551. .info {
  552. height: 58rpx;
  553. font-size: 40rpx;
  554. font-weight: 700;
  555. }
  556. .time {
  557. height: 41rpx;
  558. font-size: 28rpx;
  559. font-weight: 400;
  560. }
  561. }
  562. .active {
  563. display: flex;
  564. flex-direction: column;
  565. justify-content: center;
  566. align-items: center;
  567. margin: auto;
  568. margin-top: 145rpx;
  569. width: 300rpx;
  570. height: 300rpx;
  571. border-radius: 150rpx;
  572. text-align: center;
  573. color: #fff;
  574. background: linear-gradient(180deg, #cccccc 0%, #b3b3b3 100%);
  575. .info {
  576. height: 58rpx;
  577. font-size: 40rpx;
  578. font-weight: 700;
  579. }
  580. .time {
  581. height: 41rpx;
  582. font-size: 28rpx;
  583. font-weight: 400;
  584. }
  585. }
  586. .address {
  587. margin-top: 34rpx;
  588. height: 35rpx;
  589. line-height: 35rpx;
  590. text-align: center;
  591. font-size: 24rpx;
  592. font-weight: 400;
  593. color: #808080;
  594. }
  595. }
  596. .tab_bar {
  597. position: fixed;
  598. left: 0;
  599. bottom: 0;
  600. display: flex;
  601. width: 750rpx;
  602. height: 128rpx;
  603. border-top: 1rpx solid #ccc;
  604. background-color: #fff;
  605. .tab_box {
  606. flex: 1;
  607. display: flex;
  608. flex-direction: column;
  609. justify-content: center;
  610. align-items: center;
  611. img {
  612. margin-bottom: 10rpx;
  613. width: 54rpx;
  614. height: 48rpx;
  615. }
  616. .tab_title {
  617. font-size: 20rpx;
  618. }
  619. .tab_title_active {
  620. font-size: 20rpx;
  621. color: #0082fc;
  622. }
  623. }
  624. }
  625. .popup-content {
  626. display: flex;
  627. flex-direction: column;
  628. justify-content: space-around;
  629. align-items: center;
  630. width: 630rpx;
  631. height: 376rpx;
  632. border-radius: 33rpx;
  633. background-color: #fff;
  634. .title {
  635. display: flex;
  636. justify-content: center;
  637. align-items: center;
  638. .icon {
  639. width: 40rpx;
  640. height: 40rpx;
  641. img {
  642. width: 100%;
  643. height: 100%;
  644. }
  645. }
  646. .title_info {
  647. margin-left: 8rpx;
  648. font-size: 36rpx;
  649. font-weight: 800;
  650. color: #0082fc;
  651. }
  652. }
  653. .time {
  654. font-size: 32rpx;
  655. }
  656. .popup_button {
  657. width: 50%;
  658. text-align: center;
  659. font-size: 32rpx;
  660. color: #0082fc;
  661. }
  662. }
  663. }
  664. </style>