home.vue 15 KB

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