home.vue 8.1 KB

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