App.vue 2.6 KB

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