login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. if (isInTimeRange(...configStore.signInTimeRange)) {
  67. const now = new Date()
  68. const params = {
  69. universalid: userStore.useId,
  70. rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
  71. }
  72. // 获取当天考勤信息
  73. checkAttendance(params).then(({ returnParams }) => {
  74. if (returnParams.list.length) {
  75. // 已签到 跳转消息页
  76. $tab.reLaunch('/pages/message/index')
  77. } else {
  78. // 未签到 跳转考勤页面
  79. $tab.reLaunch('/pages/message/index?to=clockIn')
  80. }
  81. })
  82. } else {
  83. $tab.reLaunch('/pages/message/index')
  84. }
  85. })
  86. })
  87. }
  88. //判断时间是否在区间内
  89. function isInTimeRange(start, end) {
  90. // 获取当前时间戳
  91. const now = Date.now();
  92. // 获取当前日期
  93. const currentDate = new Date(now);
  94. const year = currentDate.getFullYear();
  95. const month = currentDate.getMonth();
  96. const day = currentDate.getDate();
  97. // 构建当天的起始时间和结束时间的时间戳
  98. const startTime = new Date(year, month, day, ...start.split(':').map(Number)).getTime();
  99. const endTime = new Date(year, month, day, ...end.split(':').map(Number)).getTime();
  100. // 判断当前时间是否在范围内
  101. return now >= startTime && now <= endTime;
  102. }
  103. </script>
  104. <style lang="scss">
  105. @import '@/static/font/iconfont.css';
  106. page {
  107. background-color: #ffffff;
  108. }
  109. .justify-center {
  110. justify-content: center;
  111. }
  112. .align-center {
  113. align-items: center;
  114. }
  115. .flex {
  116. display: flex;
  117. }
  118. view,
  119. scroll-view,
  120. swiper,
  121. button,
  122. input,
  123. textarea,
  124. label,
  125. navigator,
  126. image {
  127. box-sizing: border-box;
  128. }
  129. .normal-login-container {
  130. width: 100%;
  131. .logo-content {
  132. width: 100%;
  133. font-size: 21px;
  134. text-align: center;
  135. padding-top: 45%;
  136. image {
  137. border-radius: 4px;
  138. }
  139. .title {
  140. margin-left: 10px;
  141. }
  142. }
  143. .login-form-content {
  144. text-align: center;
  145. margin: 20px auto;
  146. margin-top: 15%;
  147. width: 80%;
  148. .input-item {
  149. margin: 20px auto;
  150. background-color: #f5f6f7;
  151. height: 45px;
  152. border-radius: 20px;
  153. .icon {
  154. font-size: 38rpx;
  155. margin-left: 10px;
  156. color: #999;
  157. }
  158. .input {
  159. width: 100%;
  160. line-height: 20px;
  161. text-align: left;
  162. padding-left: 15px;
  163. }
  164. }
  165. .action-btn {
  166. .login-btn {
  167. margin-top: 40px;
  168. height: 45px;
  169. border-radius: 20px;
  170. }
  171. .login-btn::after {
  172. border: 0px;
  173. border-radius: 20px;
  174. }
  175. .cu-btn.block {
  176. display: flex;
  177. }
  178. .cu-btn.lg {
  179. padding: 0 40rpx;
  180. font-size: 32rpx;
  181. }
  182. .bg-blue {
  183. background-color: #0081ff;
  184. color: #ffffff;
  185. }
  186. .cu-btn {
  187. position: relative;
  188. border: 0rpx;
  189. display: inline-flex;
  190. align-items: center;
  191. justify-content: center;
  192. box-sizing: border-box;
  193. line-height: 1;
  194. text-align: center;
  195. text-decoration: none;
  196. overflow: visible;
  197. margin-left: initial; transform: translate(0rpx, 0rpx);
  198. margin-right: initial;
  199. }
  200. }
  201. }
  202. }
  203. </style>