login.vue 5.5 KB

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