home.vue 12 KB

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