home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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: false,
  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.getTimestamp()
  161. },
  162. onUnload() {
  163. if (this.timer) {
  164. clearInterval(this.timer)
  165. }
  166. },
  167. // 下拉刷新
  168. onPullDownRefresh() {
  169. uni.removeStorageSync("manager")
  170. uni.removeStorageSync("sub-administrator")
  171. qqmapsdk = new QQMapWX({
  172. // 申请的key
  173. key: 'R43BZ-2XROX-L7T45-T5OQI-IBDFT-GNBOI'
  174. });
  175. this.getNowTime()
  176. this.getTimestamp()
  177. this.getUserInfo()
  178. this.getLocationData()
  179. setTimeout(() => {
  180. uni.stopPullDownRefresh()
  181. }, 1500)
  182. },
  183. methods: {
  184. getPageUrl() {
  185. // 获取当前打开过的页面路由数组
  186. let routes = getCurrentPages();
  187. // 获取当前页面路由,也就是最后一个打开的页面路由
  188. let curRoute = routes[routes.length - 1].route
  189. this.pageUrl = curRoute
  190. },
  191. // 获取当前时间
  192. getNowTime() {
  193. if (this.timer) {
  194. clearInterval(this.timer)
  195. }
  196. this.timer = setInterval(() => {
  197. let date = new Date()
  198. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  199. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  200. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  201. this.nowTime = hours + ':' + minutes + ':' + seconds
  202. }, 1000)
  203. },
  204. // 获取当前时间的时间戳
  205. getTimestamp() {
  206. let dates = new Date()
  207. let times = dates.getTime()
  208. this.timestamp = times
  209. },
  210. // 获取用户详细信息
  211. async getUserInfo() {
  212. let res = await this.$myRequest_clockIn({
  213. url: `/attendance/api/system/user/detail`,
  214. })
  215. // console.log(res);
  216. if (res.code == 200) {
  217. this.userInfo = res.data
  218. uni.setStorageSync("userInfo", this.userInfo)
  219. if (this.userInfo.roles) {
  220. let temList = []
  221. this.userInfo.roles.forEach((ele) => {
  222. temList.push(ele.id)
  223. })
  224. let flag = temList.includes(2)
  225. let flag2 = temList.includes(3)
  226. if (flag) {
  227. uni.setStorageSync("manager", flag)
  228. } else {
  229. uni.removeStorageSync("manager")
  230. }
  231. if (flag2) {
  232. uni.setStorageSync("sub-administrator", flag2)
  233. } else {
  234. uni.removeStorageSync("sub-administrator")
  235. }
  236. let flag_show = uni.getStorageSync("manager")
  237. let flag_show2 = uni.getStorageSync("sub-administrator")
  238. if (flag_show || flag_show2) {
  239. this.showTab = true
  240. } else {
  241. this.showTab = false
  242. }
  243. }
  244. }
  245. },
  246. // 获取当前定位位置信息
  247. getLocationData() {
  248. qqmapsdk.reverseGeocoder({
  249. success: (res) => {
  250. // console.log(res);
  251. if (res.status == 0) {
  252. // 获取详细地址信息 经纬度
  253. this.address = res.result.address
  254. this.myLat = res.result.location.lat
  255. this.myLng = res.result.location.lng
  256. // 获取当天的打卡列表数组
  257. this.getRulesList()
  258. } else {
  259. uni.showToast({
  260. title: "请求定位失败",
  261. icon: 'none'
  262. })
  263. }
  264. }
  265. })
  266. },
  267. // 获取打卡规则列表
  268. async getRulesList() {
  269. let res = await this.$myRequest_clockIn({
  270. url: "/attendance/api/sign/check/in/list/today",
  271. })
  272. // console.log(res);
  273. if (res.code == 200) {
  274. if (res.data.length == 0) {
  275. this.flags = false
  276. this.notes = "无打卡任务无需打卡"
  277. } else {
  278. this.flags = true
  279. this.list = res.data.reverse()
  280. this.activeid = this.list[0].id
  281. this.contrastObj = this.list[0]
  282. this.changeType()
  283. }
  284. }
  285. },
  286. // 对比信息改变打卡的状态显示
  287. changeType() {
  288. if (this.contrastObj.status == 4) {
  289. this.flags = false
  290. this.notes = "已打卡,无需再次打卡"
  291. } else {
  292. // 没有到打卡时间 或者 超过打卡时间 的状态
  293. if (this.timestamp < this.contrastObj.beginTime || this.timestamp > this.contrastObj.endTime) {
  294. this.flags = false
  295. this.notes = "未到打卡时间无法打卡"
  296. }
  297. // 到了打卡时间,判断是否在打卡范围内
  298. else {
  299. if (this.contrastObj.locations.length) {
  300. let temList = []
  301. temList = this.contrastObj.locations.map((ele) => {
  302. this.centerLat = ele.lat
  303. this.centerLng = ele.lng
  304. this.radius = ele.radius
  305. let red1 = this.myLat * Math.PI / 180.0;
  306. let red2 = this.centerLat * Math.PI / 180.0;
  307. let a = red1 - red2;
  308. let b = this.myLng * Math.PI / 180.0 - this.centerLng * Math.PI / 180.0;
  309. let R = 6378137;
  310. let distance = R * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(
  311. red1) *
  312. Math.cos(red2) *
  313. Math.pow(Math.sin(b / 2), 2)));
  314. this.distance = distance.toFixed(2) * 1;
  315. // console.log(this.distance);
  316. // console.log(this.radius);
  317. if (this.distance <= this.radius) {
  318. return 1
  319. } else {
  320. return 2
  321. }
  322. })
  323. let temFlag = temList.indexOf(1)
  324. if (temFlag == -1) {
  325. this.flags = false
  326. this.notes = "不在管理员设定范围内,无法打卡"
  327. } else {
  328. this.flags = true
  329. }
  330. }
  331. }
  332. }
  333. },
  334. // 点击每一个打卡规则回调
  335. handleClick(item) {
  336. // console.log(item);
  337. this.getTimestamp()
  338. this.contrastObj = item
  339. this.activeid = item.id
  340. this.changeType()
  341. },
  342. // 点击打卡按钮回调
  343. handlePunch(info) {
  344. if (this.flags) {
  345. let obj = JSON.stringify(info)
  346. // 获取用户位置权限
  347. uni.authorize({
  348. scope: 'scope.userLocation',
  349. success() {
  350. uni.navigateTo({
  351. url: `/pagesClockIn/location/location?obj=${obj}`
  352. })
  353. },
  354. fail() {
  355. uni.showModal({
  356. title: '提示',
  357. content: '请先开启定位权限,否则将无法使用定位功能',
  358. cancelText: '不授权',
  359. confirmText: '授权',
  360. success: function(res) {
  361. if (res.confirm) {
  362. uni.openSetting({
  363. success(res) {}
  364. })
  365. }
  366. }
  367. });
  368. }
  369. })
  370. }
  371. },
  372. // 格式化时间
  373. format_time(timestamp) {
  374. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  375. var date = new Date(timestamp);
  376. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  377. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  378. let strDate = h + m;
  379. return strDate;
  380. }
  381. }
  382. }
  383. </script>
  384. <style lang="scss" scoped>
  385. .container {
  386. padding-top: 20rpx;
  387. background-color: #F2F2F2;
  388. .header {
  389. display: flex;
  390. margin: 0 30rpx 30rpx 30rpx;
  391. width: 690rpx;
  392. height: 130rpx;
  393. background-color: #fff;
  394. .img {
  395. margin: 30rpx;
  396. width: 70rpx;
  397. height: 70rpx;
  398. img {
  399. width: 100%;
  400. height: 100%;
  401. }
  402. }
  403. .msg {
  404. margin: 30rpx 0;
  405. height: 70rpx;
  406. line-height: 36rpx;
  407. .name {
  408. font-size: 32rpx;
  409. font-weight: 400;
  410. }
  411. .major {
  412. font-size: 24rpx;
  413. font-weight: 400;
  414. color: #A6A6A6;
  415. }
  416. }
  417. }
  418. .body {
  419. margin: 0 30rpx;
  420. width: 690rpx;
  421. height: 919rpx;
  422. background-color: #fff;
  423. .card {
  424. padding-top: 30rpx;
  425. white-space: nowrap;
  426. height: 160rpx;
  427. overflow-x: auto;
  428. .active_box {
  429. display: inline-block;
  430. margin: 0 15rpx;
  431. width: 300rpx;
  432. height: 130rpx;
  433. line-height: 12rpx;
  434. border-radius: 8rpx;
  435. font-weight: 400;
  436. background-color: #E6E6E6;
  437. border: 1rpx solid #0094FC;
  438. .item_box {
  439. display: flex;
  440. flex-direction: column;
  441. justify-content: space-evenly;
  442. height: 130rpx;
  443. padding-left: 30rpx;
  444. .title {
  445. font-size: 28rpx;
  446. }
  447. .time {
  448. font-size: 24rpx;
  449. }
  450. .type {
  451. font-size: 24rpx;
  452. color: #808080;
  453. img {
  454. margin-right: 10rpx;
  455. width: 20rpx;
  456. height: 20rpx;
  457. }
  458. }
  459. }
  460. }
  461. .item {
  462. display: inline-block;
  463. margin: 0 15rpx;
  464. width: 300rpx;
  465. height: 130rpx;
  466. line-height: 12rpx;
  467. border-radius: 8rpx;
  468. font-weight: 400;
  469. background-color: #E6E6E6;
  470. .item_box {
  471. display: flex;
  472. flex-direction: column;
  473. justify-content: space-evenly;
  474. height: 130rpx;
  475. padding-left: 30rpx;
  476. .title {
  477. font-size: 28rpx;
  478. }
  479. .time {
  480. font-size: 24rpx;
  481. }
  482. .type {
  483. font-size: 24rpx;
  484. color: #808080;
  485. img {
  486. margin-right: 10rpx;
  487. width: 20rpx;
  488. height: 20rpx;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. .clock {
  495. display: flex;
  496. flex-direction: column;
  497. justify-content: center;
  498. align-items: center;
  499. margin: auto;
  500. margin-top: 145rpx;
  501. width: 300rpx;
  502. height: 300rpx;
  503. border-radius: 150rpx;
  504. text-align: center;
  505. color: #fff;
  506. background: linear-gradient(180deg, #00ACFC 0%, #0082FC 100%);
  507. .info {
  508. height: 58rpx;
  509. font-size: 40rpx;
  510. font-weight: 700;
  511. }
  512. .time {
  513. height: 41rpx;
  514. font-size: 28rpx;
  515. font-weight: 400;
  516. }
  517. }
  518. .active {
  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, #CCCCCC 0%, #B3B3B3 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. .address {
  543. margin-top: 34rpx;
  544. height: 35rpx;
  545. line-height: 35rpx;
  546. text-align: center;
  547. font-size: 24rpx;
  548. font-weight: 400;
  549. color: #808080;
  550. }
  551. }
  552. .tab_bar {
  553. position: fixed;
  554. left: 0;
  555. bottom: 0;
  556. display: flex;
  557. width: 750rpx;
  558. height: 128rpx;
  559. border-top: 1rpx solid #CCC;
  560. background-color: #fff;
  561. .tab_box {
  562. flex: 1;
  563. display: flex;
  564. flex-direction: column;
  565. justify-content: center;
  566. align-items: center;
  567. img {
  568. margin-bottom: 10rpx;
  569. width: 54rpx;
  570. height: 48rpx;
  571. }
  572. .tab_title {
  573. font-size: 20rpx;
  574. }
  575. .tab_title_active {
  576. font-size: 20rpx;
  577. color: #0082FC;
  578. }
  579. }
  580. }
  581. }
  582. </style>