home.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. getUserInfo() {
  131. try {
  132. const value = uni.getStorageSync('userInfo')
  133. if (value) {
  134. this.userInfo = value
  135. }
  136. } catch (e) {
  137. console.log(e);
  138. }
  139. },
  140. getLocationData() {
  141. qqmapsdk.reverseGeocoder({
  142. success: (res) => {
  143. // console.log(res);
  144. if (res.status == 0) {
  145. // 获取详细地址信息
  146. this.address = res.result.address
  147. } else {
  148. uni.showToast({
  149. title: "请求定位失败",
  150. icon: 'none'
  151. })
  152. }
  153. }
  154. })
  155. },
  156. // 获取打卡规则列表
  157. async getRulesList() {
  158. let res = await this.$myRequest({
  159. url: "/attendance/api/sign/check/in/list",
  160. name: this.userInfo.username
  161. })
  162. console.log(res);
  163. },
  164. // 点击打卡按钮回调
  165. handlePunch() {
  166. // 获取用户位置权限
  167. uni.authorize({
  168. scope: 'scope.userLocation',
  169. success() {
  170. uni.navigateTo({
  171. url: "/pages/location/location"
  172. })
  173. },
  174. fail() {
  175. uni.showModal({
  176. title: '提示',
  177. content: '请先开启定位权限,否则将无法使用定位功能',
  178. cancelText: '不授权',
  179. confirmText: '授权',
  180. success: function(res) {
  181. if (res.confirm) {
  182. uni.openSetting({
  183. success(res) {}
  184. })
  185. } else if (res.cancel) {}
  186. }
  187. });
  188. }
  189. })
  190. },
  191. // 获取当前时间
  192. getNowTime() {
  193. if (this.timer) {
  194. clearInterval(this.timer)
  195. } else {
  196. this.timer = setInterval(() => {
  197. let date = new Date()
  198. let hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  199. let minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  200. let seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  201. this.nowTime = hours + ':' + minutes + ':' + seconds
  202. // console.log(this.nowTime);
  203. }, 1000)
  204. }
  205. },
  206. }
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. .container {
  211. padding-top: 20rpx;
  212. .header {
  213. display: flex;
  214. margin: 0 30rpx 30rpx 30rpx;
  215. width: 690rpx;
  216. height: 130rpx;
  217. background-color: #fff;
  218. .img {
  219. margin: 30rpx;
  220. width: 70rpx;
  221. height: 70rpx;
  222. img {
  223. width: 100%;
  224. height: 100%;
  225. }
  226. }
  227. .msg {
  228. margin: 30rpx 0;
  229. height: 70rpx;
  230. line-height: 36rpx;
  231. .name {
  232. font-size: 32rpx;
  233. font-weight: 400;
  234. }
  235. .major {
  236. font-size: 24rpx;
  237. font-weight: 400;
  238. color: #A6A6A6;
  239. }
  240. }
  241. }
  242. .body {
  243. margin: 0 30rpx;
  244. width: 690rpx;
  245. height: 919rpx;
  246. background-color: #fff;
  247. .card {
  248. padding-top: 30rpx;
  249. white-space: nowrap;
  250. height: 160rpx;
  251. overflow-x: auto;
  252. .item {
  253. display: inline-block;
  254. margin: 0 15rpx;
  255. width: 300rpx;
  256. height: 130rpx;
  257. line-height: 12rpx;
  258. border-radius: 8rpx;
  259. font-weight: 400;
  260. background-color: #E6E6E6;
  261. .item_box {
  262. display: flex;
  263. flex-direction: column;
  264. justify-content: space-evenly;
  265. height: 130rpx;
  266. padding-left: 30rpx;
  267. .title {
  268. font-size: 28rpx;
  269. }
  270. .time {
  271. font-size: 24rpx;
  272. }
  273. .type {
  274. font-size: 24rpx;
  275. color: #808080;
  276. img {
  277. margin-right: 10rpx;
  278. width: 20rpx;
  279. height: 20rpx;
  280. }
  281. }
  282. }
  283. }
  284. }
  285. .clock {
  286. display: flex;
  287. flex-direction: column;
  288. justify-content: center;
  289. align-items: center;
  290. margin: auto;
  291. margin-top: 145rpx;
  292. width: 300rpx;
  293. height: 300rpx;
  294. border-radius: 150rpx;
  295. text-align: center;
  296. color: #fff;
  297. background: linear-gradient(180deg, #00ACFC 0%, #0082FC 100%);
  298. .info {
  299. height: 58rpx;
  300. font-size: 40rpx;
  301. font-weight: 700;
  302. }
  303. .time {
  304. height: 41rpx;
  305. font-size: 28rpx;
  306. font-weight: 400;
  307. }
  308. }
  309. .active {
  310. display: flex;
  311. flex-direction: column;
  312. justify-content: center;
  313. align-items: center;
  314. margin: auto;
  315. margin-top: 145rpx;
  316. width: 300rpx;
  317. height: 300rpx;
  318. border-radius: 150rpx;
  319. text-align: center;
  320. color: #fff;
  321. background: linear-gradient(180deg, #CCCCCC 0%, #B3B3B3 100%);
  322. .info {
  323. height: 58rpx;
  324. font-size: 40rpx;
  325. font-weight: 700;
  326. }
  327. .time {
  328. height: 41rpx;
  329. font-size: 28rpx;
  330. font-weight: 400;
  331. }
  332. }
  333. .address {
  334. margin-top: 34rpx;
  335. height: 35rpx;
  336. line-height: 35rpx;
  337. text-align: center;
  338. font-size: 24rpx;
  339. font-weight: 400;
  340. color: #808080;
  341. }
  342. }
  343. }
  344. </style>