App.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <script>
  2. import { getUserInfo } from '@/utils/auth'
  3. import { checkAttendance } from '@/api/mine.js'
  4. import $tab from '@/plugins/tab.js'
  5. export default {
  6. onLaunch: function () {
  7. console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
  8. this.initApp()
  9. console.log('App Launch')
  10. },
  11. onShow: function () {
  12. console.log('App Show')
  13. },
  14. onHide: function () {
  15. console.log('App Hide')
  16. },
  17. methods: {
  18. // 初始化应用
  19. initApp() {
  20. // 初始化应用配置
  21. // this.initConfig()
  22. // 检查用户登录状态
  23. this.checkLogin()
  24. },
  25. checkLogin() {
  26. const user = getUserInfo()
  27. if (!getUserInfo()) {
  28. $tab.reLaunch('/pages/login')
  29. } else {
  30. // 是否在上班打卡时间段
  31. if (this.isInTimeRange('08:30:00', '10:00:00')) {
  32. const now = new Date()
  33. const params = {
  34. universalid: user.useId,
  35. rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
  36. }
  37. // 获取当天考勤信息
  38. checkAttendance(params).then(({ returnParams }) => {
  39. if (returnParams.list.length) {
  40. // 已签到 跳转消息页
  41. $tab.reLaunch('/pages/message/index')
  42. } else {
  43. // 未签到 跳转考勤页面
  44. $tab.reLaunch('/pages/message/index?to=clockIn')
  45. }
  46. })
  47. } else {
  48. $tab.reLaunch('/pages/message/index')
  49. }
  50. }
  51. },
  52. //判断时间是否在区间内
  53. isInTimeRange(start, end) {
  54. // 获取当前时间戳
  55. const now = Date.now();
  56. // 获取当前日期
  57. const currentDate = new Date(now);
  58. const year = currentDate.getFullYear();
  59. const month = currentDate.getMonth();
  60. const day = currentDate.getDate();
  61. // 构建当天的起始时间和结束时间的时间戳
  62. const startTime = new Date(year, month, day, ...start.split(':').map(Number)).getTime();
  63. const endTime = new Date(year, month, day, ...end.split(':').map(Number)).getTime();
  64. // 判断当前时间是否在范围内
  65. return now >= startTime && now <= endTime;
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss">
  71. /*每个页面公共css */
  72. @import '@/uni_modules/uni-scss/index.scss';
  73. /* uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */
  74. @import '@/common/uni.css';
  75. /* #ifndef APP-NVUE */
  76. @import '@/static/font/customicons.css';
  77. /* uParse富文本框渲染 样式 */
  78. @import url("/components/gaoyia-parse/parse.css");
  79. // 设置整个项目的背景色
  80. page {
  81. background-color: #f5f5f5;
  82. }
  83. /* #endif */
  84. .example-info {
  85. font-size: 14px;
  86. color: #333;
  87. padding: 10px;
  88. }
  89. </style>