home.vue 15 KB

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