login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="logo-content align-center justify-center flex">
  4. <image style="width: 100%;" :src="config.logoSrc" mode="widthFix">
  5. </image>
  6. <!-- <text class="title">OA移动端登录</text> -->
  7. </view>
  8. <view class="login-form-content">
  9. <view class="input-item flex align-center">
  10. <view class="iconfont icon-user icon"></view>
  11. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  12. </view>
  13. <view class="input-item flex align-center">
  14. <view class="iconfont icon-password icon"></view>
  15. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  16. </view>
  17. <view class="action-btn">
  18. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { ref } from 'vue'
  25. import { checkAttendance } from '@/api/mine.js'
  26. import config from '@/config.js'
  27. import $modal from '@/plugins/modal.js'
  28. import $tab from '@/plugins/tab.js'
  29. import { useUserStore } from '@/store/user.js'
  30. import { getLoginInfo } from '@/utils/auth'
  31. const userStore = useUserStore()
  32. const loginForm = ref({
  33. username: getLoginInfo().username || '',
  34. password: getLoginInfo().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/font/iconfont.css';
  93. page {
  94. background-color: #ffffff;
  95. }
  96. .justify-center {
  97. justify-content: center;
  98. }
  99. .align-center {
  100. align-items: center;
  101. }
  102. .flex {
  103. display: flex;
  104. }
  105. view,
  106. scroll-view,
  107. swiper,
  108. button,
  109. input,
  110. textarea,
  111. label,
  112. navigator,
  113. image {
  114. box-sizing: border-box;
  115. }
  116. .normal-login-container {
  117. width: 100%;
  118. .logo-content {
  119. width: 100%;
  120. font-size: 21px;
  121. text-align: center;
  122. padding-top: 45%;
  123. image {
  124. border-radius: 4px;
  125. }
  126. .title {
  127. margin-left: 10px;
  128. }
  129. }
  130. .login-form-content {
  131. text-align: center;
  132. margin: 20px auto;
  133. margin-top: 15%;
  134. width: 80%;
  135. .input-item {
  136. margin: 20px auto;
  137. background-color: #f5f6f7;
  138. height: 45px;
  139. border-radius: 20px;
  140. .icon {
  141. font-size: 38rpx;
  142. margin-left: 10px;
  143. color: #999;
  144. }
  145. .input {
  146. width: 100%;
  147. line-height: 20px;
  148. text-align: left;
  149. padding-left: 15px;
  150. }
  151. }
  152. .action-btn {
  153. .login-btn {
  154. margin-top: 40px;
  155. height: 45px;
  156. border-radius: 20px;
  157. }
  158. .login-btn::after {
  159. border: 0px;
  160. border-radius: 20px;
  161. }
  162. .cu-btn.block {
  163. display: flex;
  164. }
  165. .cu-btn.lg {
  166. padding: 0 40rpx;
  167. font-size: 32rpx;
  168. }
  169. .bg-blue {
  170. background-color: #0081ff;
  171. color: #ffffff;
  172. }
  173. .cu-btn {
  174. position: relative;
  175. border: 0rpx;
  176. display: inline-flex;
  177. align-items: center;
  178. justify-content: center;
  179. box-sizing: border-box;
  180. line-height: 1;
  181. text-align: center;
  182. text-decoration: none;
  183. overflow: visible;
  184. margin-left: initial; transform: translate(0rpx, 0rpx);
  185. margin-right: initial;
  186. }
  187. }
  188. }
  189. }
  190. </style>