login.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="logo-content align-center justify-center flex">
  4. <image style="width: 100%;"
  5. :src="config.logoSrc" mode="widthFix">
  6. </image>
  7. <!-- <text class="title">OA移动端登录</text> -->
  8. </view>
  9. <view class="login-form-content">
  10. <view class="input-item flex align-center">
  11. <view class="iconfont icon-user icon"></view>
  12. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  13. </view>
  14. <view class="input-item flex align-center">
  15. <view class="iconfont icon-password icon"></view>
  16. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  17. </view>
  18. <view class="action-btn">
  19. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script setup lang="ts">
  25. import { ref } from 'vue'
  26. import { checkAttendance } from '@/api/mine.js'
  27. import config from '@/config.js'
  28. import $modal from '@/plugins/modal.js'
  29. import $tab from '@/plugins/tab.js'
  30. import { useUserStore } from '@/store/user.js'
  31. import { reLogin } from '@/api/login'
  32. const userStore = useUserStore()
  33. const loginForm = ref({
  34. username: '',
  35. password: ''
  36. })
  37. function handleLogin() {
  38. const username = loginForm.value.username
  39. const password = loginForm.value.password
  40. if (username === "") {
  41. $modal.msgError("请输入您的账号")
  42. } else if (password === "") {
  43. $modal.msgError("请输入您的密码")
  44. } else {
  45. $modal.loading("登录中,请耐心等待...")
  46. // TEST: 测试登录接口
  47. userStore.Login(loginForm.value).then(() => {
  48. $modal.closeLoading()
  49. loginSuccess()
  50. })
  51. }
  52. }
  53. function loginSuccess() {
  54. userStore.GetInfo()
  55. // 是否在上班打卡时间段
  56. if (isInTimeRange(...config.signInTimeRange)) {
  57. const now = new Date()
  58. const params = {
  59. universalid: userStore.useId,
  60. rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
  61. }
  62. // 获取当天考勤信息
  63. checkAttendance(params).then(({ returnParams }) => {
  64. if (returnParams.list.length) {
  65. // 已签到 跳转消息页
  66. $tab.reLaunch('/pages/message/index')
  67. } else {
  68. // 未签到 跳转考勤页面
  69. $tab.reLaunch('/pages/message/index?to=clockIn')
  70. }
  71. })
  72. } else {
  73. $tab.reLaunch('/pages/message/index')
  74. }
  75. }
  76. //判断时间是否在区间内
  77. function isInTimeRange(start, end) {
  78. // 获取当前时间戳
  79. const now = Date.now();
  80. // 获取当前日期
  81. const currentDate = new Date(now);
  82. const year = currentDate.getFullYear();
  83. const month = currentDate.getMonth();
  84. const day = currentDate.getDate();
  85. // 构建当天的起始时间和结束时间的时间戳
  86. const startTime = new Date(year, month, day, ...start.split(':').map(Number)).getTime();
  87. const endTime = new Date(year, month, day, ...end.split(':').map(Number)).getTime();
  88. // 判断当前时间是否在范围内
  89. return now >= startTime && now <= endTime;
  90. }
  91. </script>
  92. <style lang="scss">
  93. @import "@/static/scss/colorui.css";
  94. @import '@/static/font/iconfont.css';
  95. page {
  96. background-color: #ffffff;
  97. }
  98. .normal-login-container {
  99. width: 100%;
  100. .logo-content {
  101. width: 100%;
  102. font-size: 21px;
  103. text-align: center;
  104. padding-top: 45%;
  105. image {
  106. border-radius: 4px;
  107. }
  108. .title {
  109. margin-left: 10px;
  110. }
  111. }
  112. .login-form-content {
  113. text-align: center;
  114. margin: 20px auto;
  115. margin-top: 15%;
  116. width: 80%;
  117. .input-item {
  118. margin: 20px auto;
  119. background-color: #f5f6f7;
  120. height: 45px;
  121. border-radius: 20px;
  122. .icon {
  123. font-size: 38rpx;
  124. margin-left: 10px;
  125. color: #999;
  126. }
  127. .input {
  128. width: 100%;
  129. line-height: 20px;
  130. text-align: left;
  131. padding-left: 15px;
  132. }
  133. }
  134. .login-btn {
  135. margin-top: 40px;
  136. height: 45px;
  137. border-radius: 20px;
  138. }
  139. }
  140. }
  141. </style>