home.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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="item" v-for="item in list" :key="item.id">
  23. <view class="item_box">
  24. <view class="title">
  25. {{item.ruleName}}
  26. </view>
  27. <view class="time">
  28. {{item.timeRange}}
  29. </view>
  30. <view class="type">
  31. <img v-if="item.updateTime" src="./imgs/success.png">
  32. <span v-if="item.updateTime">{{item.updateTime}}</span>
  33. {{item.updateTime?"已打卡":"未打卡"}}
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- list数组为空时的占位盒子 -->
  39. <view class="card" v-else></view>
  40. <!-- 打卡区域 -->
  41. <view :class="{clock:flags,active:!flags}" @click="handlePunch">
  42. <view class="info" v-if="flags">
  43. 打卡
  44. </view>
  45. <view class="info" v-else>
  46. 无法打卡
  47. </view>
  48. <view class="time">
  49. {{nowTime}}
  50. </view>
  51. </view>
  52. <!-- 提示信息位置 -->
  53. <view class="address" v-if="flags">
  54. {{notes}}
  55. </view>
  56. <view class="address" v-if="!flags">
  57. 无打卡任务无需打卡
  58. </view>
  59. <!-- <view class="address" v-if="addressFlags&&!flags">
  60. 不在管理员设定范围打卡
  61. </view>
  62. <view class="address" v-if="timeFlags&&!flags">
  63. 未到打卡时间无法打卡
  64. </view>
  65. <view class="address" v-if="!list.length">
  66. 今日休息无需打卡
  67. </view>
  68. <view class="address" v-if="!list.length">
  69. 下一次打卡时间段为18:00-19:00
  70. </view> -->
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. var QQMapWX = require('../../util/qqmap-wx-jssdk1.1/qqmap-wx-jssdk');
  76. var qqmapsdk;
  77. export default {
  78. data() {
  79. return {
  80. // 用户信息
  81. userInfo: {},
  82. // 打卡规则列表
  83. list: [],
  84. // 是否在打卡范围内标识
  85. addressFlags: false,
  86. // 是否在打卡时间内标识
  87. timeFlags: false,
  88. // 当前时间
  89. nowTime: "",
  90. // 当前定位位置信息
  91. address: "",
  92. // 定时器标识
  93. timer: null,
  94. notes:""
  95. };
  96. },
  97. computed: {
  98. // 是否有打卡任务的标识
  99. flags() {
  100. return this.list.length ? true : false
  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. this.getNowTime()
  112. this.getUserInfo()
  113. this.getLocationData()
  114. this.getRulesList()
  115. },
  116. onUnload() {
  117. if (this.timer) {
  118. clearInterval(this.timer)
  119. }
  120. },
  121. methods: {
  122. // 获取当前时间
  123. getNowTime() {
  124. if (this.timer) {
  125. clearInterval(this.timer)
  126. } else {
  127. this.timer = setInterval(() => {
  128. let date = new Date()
  129. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  130. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  131. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  132. this.nowTime = hours + ':' + minutes + ':' + seconds
  133. // console.log(this.nowTime);
  134. }, 1000)
  135. }
  136. },
  137. // 获取用户详细信息
  138. async getUserInfo() {
  139. let userId = uni.getStorageSync("userInfo").id || 5046
  140. let res = await this.$myRequest({
  141. url: `/attendance/api/system/user/detail/${userId}`,
  142. })
  143. // console.log(res);
  144. if (res.code == 200) {
  145. this.userInfo = res.data
  146. if (this.userInfo.roles) {
  147. let temList = []
  148. this.userInfo.roles.forEach((ele) => {
  149. temList.push(ele.id)
  150. })
  151. let flag = temList.includes(2)
  152. let flag2 = temList.includes(3)
  153. if (flag) {
  154. uni.setStorageSync("manager", flag)
  155. }
  156. if (flag2) {
  157. uni.setStorageSync("sub-administrator", flag2)
  158. }
  159. }
  160. }
  161. },
  162. // 获取当前定位位置信息
  163. getLocationData() {
  164. qqmapsdk.reverseGeocoder({
  165. success: (res) => {
  166. // console.log(res);
  167. if (res.status == 0) {
  168. // 获取详细地址信息
  169. this.notes = res.result.address
  170. } else {
  171. uni.showToast({
  172. title: "请求定位失败",
  173. icon: 'none'
  174. })
  175. }
  176. }
  177. })
  178. },
  179. // 获取打卡规则列表
  180. async getRulesList() {
  181. // let name = uni.getStorageSync("userInfo").username
  182. let res = await this.$myRequest({
  183. url: "/attendance/api/sign/check/in/list/today",
  184. // data: {
  185. // name: name ? name : "",
  186. // size: 999
  187. // }
  188. })
  189. // console.log(res);
  190. if (res.code == 200) {
  191. this.list = res.data.reverse()
  192. }
  193. },
  194. // 点击打卡按钮回调
  195. handlePunch() {
  196. if (this.flags) {
  197. // 获取用户位置权限
  198. uni.authorize({
  199. scope: 'scope.userLocation',
  200. success() {
  201. uni.navigateTo({
  202. url: "/pages/location/location"
  203. })
  204. },
  205. fail() {
  206. uni.showModal({
  207. title: '提示',
  208. content: '请先开启定位权限,否则将无法使用定位功能',
  209. cancelText: '不授权',
  210. confirmText: '授权',
  211. success: function(res) {
  212. if (res.confirm) {
  213. uni.openSetting({
  214. success(res) {}
  215. })
  216. } else if (res.cancel) {}
  217. }
  218. });
  219. }
  220. })
  221. }
  222. },
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .container {
  228. padding-top: 20rpx;
  229. .header {
  230. display: flex;
  231. margin: 0 30rpx 30rpx 30rpx;
  232. width: 690rpx;
  233. height: 130rpx;
  234. background-color: #fff;
  235. .img {
  236. margin: 30rpx;
  237. width: 70rpx;
  238. height: 70rpx;
  239. img {
  240. width: 100%;
  241. height: 100%;
  242. }
  243. }
  244. .msg {
  245. margin: 30rpx 0;
  246. height: 70rpx;
  247. line-height: 36rpx;
  248. .name {
  249. font-size: 32rpx;
  250. font-weight: 400;
  251. }
  252. .major {
  253. font-size: 24rpx;
  254. font-weight: 400;
  255. color: #A6A6A6;
  256. }
  257. }
  258. }
  259. .body {
  260. margin: 0 30rpx;
  261. width: 690rpx;
  262. height: 919rpx;
  263. background-color: #fff;
  264. .card {
  265. padding-top: 30rpx;
  266. white-space: nowrap;
  267. height: 160rpx;
  268. overflow-x: auto;
  269. .item {
  270. display: inline-block;
  271. margin: 0 15rpx;
  272. width: 300rpx;
  273. height: 130rpx;
  274. line-height: 12rpx;
  275. border-radius: 8rpx;
  276. font-weight: 400;
  277. background-color: #E6E6E6;
  278. .item_box {
  279. display: flex;
  280. flex-direction: column;
  281. justify-content: space-evenly;
  282. height: 130rpx;
  283. padding-left: 30rpx;
  284. .title {
  285. font-size: 28rpx;
  286. }
  287. .time {
  288. font-size: 24rpx;
  289. }
  290. .type {
  291. font-size: 24rpx;
  292. color: #808080;
  293. img {
  294. margin-right: 10rpx;
  295. width: 20rpx;
  296. height: 20rpx;
  297. }
  298. }
  299. }
  300. }
  301. }
  302. .clock {
  303. display: flex;
  304. flex-direction: column;
  305. justify-content: center;
  306. align-items: center;
  307. margin: auto;
  308. margin-top: 145rpx;
  309. width: 300rpx;
  310. height: 300rpx;
  311. border-radius: 150rpx;
  312. text-align: center;
  313. color: #fff;
  314. background: linear-gradient(180deg, #00ACFC 0%, #0082FC 100%);
  315. .info {
  316. height: 58rpx;
  317. font-size: 40rpx;
  318. font-weight: 700;
  319. }
  320. .time {
  321. height: 41rpx;
  322. font-size: 28rpx;
  323. font-weight: 400;
  324. }
  325. }
  326. .active {
  327. display: flex;
  328. flex-direction: column;
  329. justify-content: center;
  330. align-items: center;
  331. margin: auto;
  332. margin-top: 145rpx;
  333. width: 300rpx;
  334. height: 300rpx;
  335. border-radius: 150rpx;
  336. text-align: center;
  337. color: #fff;
  338. background: linear-gradient(180deg, #CCCCCC 0%, #B3B3B3 100%);
  339. .info {
  340. height: 58rpx;
  341. font-size: 40rpx;
  342. font-weight: 700;
  343. }
  344. .time {
  345. height: 41rpx;
  346. font-size: 28rpx;
  347. font-weight: 400;
  348. }
  349. }
  350. .address {
  351. margin-top: 34rpx;
  352. height: 35rpx;
  353. line-height: 35rpx;
  354. text-align: center;
  355. font-size: 24rpx;
  356. font-weight: 400;
  357. color: #808080;
  358. }
  359. }
  360. }
  361. </style>