login.vue 3.9 KB

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