loginBox.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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' : '']"
  18. @click="changePassword"></text>
  19. <view class="close-btn" v-if="clearPwIcon" @click="clearPw"></view>
  20. </view>
  21. <button type="default" @click="handleLogin" class="phone-green-btn login-btn">登录</button>
  22. <!-- 已加密的:{{lliPassword}} -->
  23. </view>
  24. <passwordLli ref="passLLiRef" :password="password" @lli-password="onLliPassword" />
  25. </view>
  26. </template>
  27. <script setup>
  28. import cacheManager from '@/utils/cacheManager.js'
  29. import * as httpApi from "@/api/login.js"
  30. import passwordLli from "@/components/password-lli/password-lli.vue";
  31. import {ref} from "vue"
  32. import {toast} from "@/utils/common";
  33. const userName = ref('') // 用户名
  34. const password = ref('') // 密码
  35. const lliPassword = ref('') // 加密后的密码
  36. const passLLiRef = ref(null)
  37. const showPassword= ref(true)
  38. const clearTelIcon= ref(false)
  39. const clearPwIcon= ref(false)
  40. // 加密
  41. function handleUpdateLLiPassword() {
  42. console.log('handleUpdateLLiPassword')
  43. passLLiRef.value.lliPassword();
  44. }
  45. function onLliPassword(password) {
  46. console.log('onLliPassword',password)
  47. lliPassword.value = password;
  48. }
  49. // 手机号校验
  50. function userInputChange(event){
  51. if (event.detail.value.length > 0) {
  52. clearTelIcon.value = true;
  53. } else {
  54. clearTelIcon.value = false;
  55. }
  56. }
  57. // 密码校验
  58. function passwordInputChange(event){
  59. if (event.detail.value.length > 0) {
  60. clearPwIcon.value = true;
  61. } else {
  62. clearPwIcon.value = false;
  63. }
  64. }
  65. // 清除手机号
  66. function clearTel(){
  67. userName.value = '';
  68. clearTelIcon.value = false;
  69. }
  70. // 清除密码
  71. function clearPw(){
  72. password.value = '';
  73. clearPwIcon.value = false;
  74. }
  75. // 密码显隐
  76. function changePassword() {
  77. showPassword.value = !showPassword.value;
  78. }
  79. // 登录
  80. function handleLogin() {
  81. if(userName.value.length ===0){
  82. toast('请输入手机号!')
  83. return
  84. }
  85. if(password.value.length ===0){
  86. toast('请输入密码!')
  87. return
  88. }
  89. // 去除 userName 两端的空格
  90. const trimmedUserName = userName.value;
  91. const trimmedPassword = lliPassword.value;
  92. httpApi.login({
  93. userName: trimmedUserName,
  94. password: lliPassword.value,
  95. }).then(res => {
  96. cacheManager.set('auth', res.data)
  97. console.log('登录成功')
  98. // 页面跳转
  99. gotoPage();
  100. })
  101. }
  102. // 跳转
  103. function gotoPage(){
  104. // 客户端
  105. // #ifdef H5
  106. uni.navigateTo({
  107. url: `/pages/client/ShouYe/shouye`
  108. })
  109. // #endif
  110. // 管理端
  111. // #ifdef APP-PLUS
  112. uni.navigateTo({
  113. url: `/pages/admin/ShouYe/shouye`
  114. })
  115. // #endif
  116. }
  117. </script>
  118. <style>
  119. </style>