login.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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, changePWD } 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((res) => {
  50. if (loginForm.value.password == '123456') {
  51. changeOrgPWD(res.returnParams.useId)
  52. } else {
  53. $modal.closeLoading()
  54. loginSuccess()
  55. }
  56. })
  57. }
  58. }
  59. function changeOrgPWD(staffId) {
  60. $modal.editable('修改初始密码', '请输入大于6位的新密码', false).then((newpassword) => {
  61. if (newpassword < 99999) {
  62. $modal.syncAlert('密码需大于6位').then(() => {
  63. changeOrgPWD(staffId)
  64. })
  65. return
  66. }
  67. if (newpassword == '123456') {
  68. $modal.syncAlert('请勿使用123456作为密码').then(() => {
  69. changeOrgPWD(staffId)
  70. })
  71. return
  72. }
  73. const params = {
  74. staffId,
  75. oldpassword: loginForm.value.password,
  76. newpassword,
  77. }
  78. changePWD(params).then(res => {
  79. loginForm.value.password = newpassword
  80. $modal.showToast(res.returnMsg);
  81. if ("1" == res.returnCode) { //修改成功
  82. handleLogin()
  83. } else {
  84. changeOrgPWD(staffId)
  85. }
  86. })
  87. })
  88. }
  89. onLoad((options) => {
  90. //判断是否要自动登录
  91. if (options.type) {
  92. // console.log('autoLogin');
  93. handleLogin()
  94. }
  95. })
  96. function loginSuccess() {
  97. userStore.GetInfo().then(() => {
  98. // 是否在上班打卡时间段
  99. configStore.GetAttRule(userStore.user).then(() => {
  100. console.log('GetAttRule');
  101. let inTime = false;
  102. if(config.clock && config.clock == 'multiple'){
  103. inTime = isInTimeRange(...configStore.signInTimeRange[0]) || isInTimeRange(...configStore.signInTimeRange[1])
  104. }else{
  105. inTime = isInTimeRange(...configStore.signInTimeRange[0])
  106. }
  107. //if (isInTimeRange(...configStore.signInTimeRange)) {
  108. if (inTime) {
  109. const now = new Date()
  110. const params = {
  111. universalid: userStore.useId,
  112. rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
  113. }
  114. // 获取当天考勤信息
  115. checkAttendance(params).then(({ returnParams }) => {
  116. if (returnParams.list.length) {
  117. // 已签到 跳转消息页
  118. $tab.reLaunch('/pages/message/index')
  119. } else {
  120. // 未签到 跳转考勤页面
  121. $tab.reLaunch('/pages/message/index?to=clockIn')
  122. }
  123. })
  124. } else {
  125. $tab.reLaunch('/pages/message/index')
  126. }
  127. }).catch((error) => {
  128. // console.log('GetAttRule error:', error);
  129. if (['getAttendanceSegmentErr', 'getAttendanceRuleErr'].includes(error)) {
  130. $tab.reLaunch('/pages/message/index')
  131. }
  132. });
  133. })
  134. }
  135. //判断时间是否在区间内
  136. function isInTimeRange(start, end) {
  137. // 获取当前时间戳
  138. const now = Date.now();
  139. // 获取当前日期
  140. const currentDate = new Date(now);
  141. const year = currentDate.getFullYear();
  142. const month = currentDate.getMonth();
  143. const day = currentDate.getDate();
  144. // 构建当天的起始时间和结束时间的时间戳
  145. const startTime = new Date(year, month, day, ...start.split(':').map(Number)).getTime();
  146. const endTime = new Date(year, month, day, ...end.split(':').map(Number)).getTime();
  147. // 判断当前时间是否在范围内
  148. return now >= startTime && now <= endTime;
  149. }
  150. </script>
  151. <style lang="scss">
  152. @import '@/static/font/iconfont.css';
  153. page {
  154. background-color: #ffffff;
  155. }
  156. .justify-center {
  157. justify-content: center;
  158. }
  159. .align-center {
  160. align-items: center;
  161. }
  162. .flex {
  163. display: flex;
  164. }
  165. view,
  166. scroll-view,
  167. swiper,
  168. button,
  169. input,
  170. textarea,
  171. label,
  172. navigator,
  173. image {
  174. box-sizing: border-box;
  175. }
  176. .normal-login-container {
  177. width: 100%;
  178. .logo-content {
  179. width: 100%;
  180. font-size: 21px;
  181. text-align: center;
  182. padding-top: 45%;
  183. image {
  184. border-radius: 4px;
  185. }
  186. .title {
  187. margin-left: 10px;
  188. }
  189. }
  190. .login-form-content {
  191. text-align: center;
  192. margin: 20px auto;
  193. margin-top: 15%;
  194. width: 80%;
  195. .input-item {
  196. margin: 20px auto;
  197. background-color: #f5f6f7;
  198. height: 45px;
  199. border-radius: 20px;
  200. .icon {
  201. font-size: 38rpx;
  202. margin-left: 10px;
  203. color: #999;
  204. }
  205. .input {
  206. width: 100%;
  207. line-height: 20px;
  208. text-align: left;
  209. padding-left: 15px;
  210. }
  211. }
  212. .action-btn {
  213. .login-btn {
  214. margin-top: 40px;
  215. height: 45px;
  216. border-radius: 20px;
  217. }
  218. .login-btn::after {
  219. border: 0px;
  220. border-radius: 20px;
  221. }
  222. .cu-btn.block {
  223. display: flex;
  224. }
  225. .cu-btn.lg {
  226. padding: 0 40rpx;
  227. font-size: 32rpx;
  228. }
  229. .bg-blue {
  230. background-color: #0081ff;
  231. color: #ffffff;
  232. }
  233. .cu-btn {
  234. position: relative;
  235. border: 0rpx;
  236. display: inline-flex;
  237. align-items: center;
  238. justify-content: center;
  239. box-sizing: border-box;
  240. line-height: 1;
  241. text-align: center;
  242. text-decoration: none;
  243. overflow: visible;
  244. margin-left: initial;
  245. transform: translate(0rpx, 0rpx);
  246. margin-right: initial;
  247. }
  248. }
  249. }
  250. }
  251. </style>