home.vue 7.6 KB

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