home.vue 17 KB

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