home.vue 11 KB

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