login.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. import { useConfigStore } from '@/store/config.js'
  32. import { onLoad } from '@dcloudio/uni-app'
  33. const userStore = useUserStore()
  34. const configStore = useConfigStore();
  35. const loginForm = ref({
  36. username: getLoginInfo().username || '',
  37. password: getLoginInfo().password || ''
  38. })
  39. function handleLogin() {
  40. const username = loginForm.value.username
  41. const password = loginForm.value.password
  42. if (username == '') {
  43. $modal.msgError("请输入您的账号")
  44. } else if (password == '') {
  45. $modal.msgError("请输入您的密码")
  46. } else {
  47. $modal.loading("登录中,请耐心等待...")
  48. // TEST: 测试登录接口
  49. userStore.Login(loginForm.value).then(() => {
  50. $modal.closeLoading()
  51. loginSuccess()
  52. })
  53. }
  54. }
  55. onLoad((options) => {
  56. //判断是否要自动登录
  57. if (options.type) {
  58. // console.log('autoLogin');
  59. handleLogin()
  60. }
  61. })
  62. function loginSuccess() {
  63. userStore.GetInfo().then(() => {
  64. // 是否在上班打卡时间段
  65. configStore.GetAttRule(userStore.user).then(() => {
  66. console.log('GetAttRule');
  67. if (isInTimeRange(...configStore.signInTimeRange)) {
  68. const now = new Date()
  69. const params = {
  70. universalid: userStore.useId,
  71. rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
  72. }
  73. // 获取当天考勤信息
  74. checkAttendance(params).then(({ returnParams }) => {
  75. if (returnParams.list.length) {
  76. // 已签到 跳转消息页
  77. $tab.reLaunch('/pages/message/index')
  78. } else {
  79. // 未签到 跳转考勤页面
  80. $tab.reLaunch('/pages/message/index?to=clockIn')
  81. }
  82. })
  83. } else {
  84. $tab.reLaunch('/pages/message/index')
  85. }
  86. }).catch((error) => {
  87. // console.log('GetAttRule error:', error);
  88. if (['getAttendanceSegmentErr', 'getAttendanceRuleErr'].includes(error)) {
  89. $tab.reLaunch('/pages/message/index')
  90. }
  91. });
  92. })
  93. }
  94. //判断时间是否在区间内
  95. function isInTimeRange(start, end) {
  96. // 获取当前时间戳
  97. const now = Date.now();
  98. // 获取当前日期
  99. const currentDate = new Date(now);
  100. const year = currentDate.getFullYear();
  101. const month = currentDate.getMonth();
  102. const day = currentDate.getDate();
  103. // 构建当天的起始时间和结束时间的时间戳
  104. const startTime = new Date(year, month, day, ...start.split(':').map(Number)).getTime();
  105. const endTime = new Date(year, month, day, ...end.split(':').map(Number)).getTime();
  106. // 判断当前时间是否在范围内
  107. return now >= startTime && now <= endTime;
  108. }
  109. </script>
  110. <style lang="scss">
  111. @import '@/static/font/iconfont.css';
  112. page {
  113. background-color: #ffffff;
  114. }
  115. .justify-center {
  116. justify-content: center;
  117. }
  118. .align-center {
  119. align-items: center;
  120. }
  121. .flex {
  122. display: flex;
  123. }
  124. view,
  125. scroll-view,
  126. swiper,
  127. button,
  128. input,
  129. textarea,
  130. label,
  131. navigator,
  132. image {
  133. box-sizing: border-box;
  134. }
  135. .normal-login-container {
  136. width: 100%;
  137. .logo-content {
  138. width: 100%;
  139. font-size: 21px;
  140. text-align: center;
  141. padding-top: 45%;
  142. image {
  143. border-radius: 4px;
  144. }
  145. .title {
  146. margin-left: 10px;
  147. }
  148. }
  149. .login-form-content {
  150. text-align: center;
  151. margin: 20px auto;
  152. margin-top: 15%;
  153. width: 80%;
  154. .input-item {
  155. margin: 20px auto;
  156. background-color: #f5f6f7;
  157. height: 45px;
  158. border-radius: 20px;
  159. .icon {
  160. font-size: 38rpx;
  161. margin-left: 10px;
  162. color: #999;
  163. }
  164. .input {
  165. width: 100%;
  166. line-height: 20px;
  167. text-align: left;
  168. padding-left: 15px;
  169. }
  170. }
  171. .action-btn {
  172. .login-btn {
  173. margin-top: 40px;
  174. height: 45px;
  175. border-radius: 20px;
  176. }
  177. .login-btn::after {
  178. border: 0px;
  179. border-radius: 20px;
  180. }
  181. .cu-btn.block {
  182. display: flex;
  183. }
  184. .cu-btn.lg {
  185. padding: 0 40rpx;
  186. font-size: 32rpx;
  187. }
  188. .bg-blue {
  189. background-color: #0081ff;
  190. color: #ffffff;
  191. }
  192. .cu-btn {
  193. position: relative;
  194. border: 0rpx;
  195. display: inline-flex;
  196. align-items: center;
  197. justify-content: center;
  198. box-sizing: border-box;
  199. line-height: 1;
  200. text-align: center;
  201. text-decoration: none;
  202. overflow: visible;
  203. margin-left: initial;
  204. transform: translate(0rpx, 0rpx);
  205. margin-right: initial;
  206. }
  207. }
  208. }
  209. }
  210. </style>