clientloginBox.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="phone-login-page">
  3. <view class="login-wrap-box">
  4. <view class="bjcx-head-box">
  5. <icon class="bjcx-logo-box"></icon>
  6. <view class="bjcx-logo-title">家政学</view>
  7. </view>
  8. <view class="login-input-box">
  9. <icon class="user-icon"></icon>
  10. <input class="login-input" type="text" v-model="userName" placeholder="请输入手机号" @input="userInputChange">
  11. <view class="close-btn" v-if="clearTelIcon" @click="clearTel"></view>
  12. </view>
  13. <view class="login-input-box">
  14. <icon class="tel-icon"></icon>
  15. <input class="login-input" placeholder="请输入证件号后六位" v-model="password" :password="showPassword"
  16. @input="passwordInputChange" />
  17. <text class="login-eye" :class="[!showPassword ? 'uni-eye-active' : '']" @click="changePassword"></text>
  18. <view class="close-btn" v-if="clearPwIcon" @click="clearPw"></view>
  19. </view>
  20. <button type="default" @click="handleLogin" class="phone-green-btn login-btn">登录</button>
  21. <!-- 已加密的:{{lliPassword}} -->
  22. </view>
  23. <passwordLli ref="passLLiRef" :password="password" @lli-password="onLliPassword" />
  24. </view>
  25. </template>
  26. <script setup>
  27. import cacheManager from '@/utils/cacheManager.js'
  28. import * as httpApi from "@/api/login.js"
  29. import passwordLli from "@/components/password-lli/password-lli.vue";
  30. import {
  31. ref
  32. } from "vue"
  33. import {
  34. toast
  35. } from "@/utils/common";
  36. import {
  37. useIsCanBack
  38. } from "@/store/isCanBack.js"
  39. const userName = ref('') // 用户名
  40. const password = ref('') // 密码
  41. const lliPassword = ref('') // 加密后的密码
  42. const passLLiRef = ref(null)
  43. const showPassword = ref(true)
  44. const clearTelIcon = ref(false)
  45. const clearPwIcon = ref(false)
  46. const store = useIsCanBack();
  47. // 加密
  48. function handleUpdateLLiPassword() {
  49. console.log('handleUpdateLLiPassword')
  50. passLLiRef.value.lliPassword();
  51. }
  52. function onLliPassword(password) {
  53. console.log('onLliPassword', password)
  54. lliPassword.value = password;
  55. }
  56. // 手机号校验
  57. function userInputChange(event) {
  58. if (event.detail.value.length > 0) {
  59. clearTelIcon.value = true;
  60. } else {
  61. clearTelIcon.value = false;
  62. }
  63. }
  64. // 密码校验
  65. function passwordInputChange(event) {
  66. if (event.detail.value.length > 0) {
  67. clearPwIcon.value = true;
  68. } else {
  69. clearPwIcon.value = false;
  70. }
  71. }
  72. // 清除手机号
  73. function clearTel() {
  74. userName.value = '';
  75. clearTelIcon.value = false;
  76. }
  77. // 清除密码
  78. function clearPw() {
  79. password.value = '';
  80. clearPwIcon.value = false;
  81. }
  82. // 密码显隐
  83. function changePassword() {
  84. showPassword.value = !showPassword.value;
  85. }
  86. // 登录
  87. function handleLogin() {
  88. if (userName.value.length === 0) {
  89. toast('请输入手机号!')
  90. return
  91. }
  92. if (password.value.length === 0) {
  93. toast('请输入密码!')
  94. return
  95. }
  96. // 去除 userName 两端的空格
  97. const trimmedUserName = userName.value;
  98. const trimmedPassword = lliPassword.value;
  99. uni.showLoading({
  100. title: '登录中'
  101. })
  102. httpApi.login({
  103. // type 1app 2为H5
  104. type: 2,
  105. userName: trimmedUserName,
  106. password: lliPassword.value,
  107. }).then(res => {
  108. // 4为家政人员
  109. if (res.data.type === 4) {
  110. if (cacheManager.get('auth')) {
  111. cacheManager.clearAll()
  112. }
  113. cacheManager.set('auth', res.data)
  114. store.setIsCanBack(false)
  115. // 页面跳转
  116. gotoPage();
  117. } else {
  118. toast('登录失败,您的身份有误,请联系管理员。')
  119. }
  120. }).catch(err => {
  121. store.setIsCanBack(true)
  122. }).finally(err => {
  123. uni.hideLoading()
  124. })
  125. }
  126. // 跳转
  127. function gotoPage() {
  128. uni.navigateTo({
  129. url: `/pages/client/ShouYe/shouye`
  130. })
  131. }
  132. </script>
  133. <style>
  134. </style>