adminloginBox.vue 3.5 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. import {useIsCanBack} from "@/store/isCanBack.js"
  34. const userName = ref('') // 用户名
  35. const password = ref('') // 密码
  36. const lliPassword = ref('') // 加密后的密码
  37. const passLLiRef = ref(null)
  38. const showPassword= ref(true)
  39. const clearTelIcon= ref(false)
  40. const clearPwIcon= ref(false)
  41. const store = useIsCanBack();
  42. // 加密
  43. function handleUpdateLLiPassword() {
  44. console.log('handleUpdateLLiPassword')
  45. passLLiRef.value.lliPassword();
  46. }
  47. function onLliPassword(password) {
  48. console.log('onLliPassword',password)
  49. lliPassword.value = password;
  50. }
  51. // 手机号校验
  52. function userInputChange(event){
  53. if (event.detail.value.length > 0) {
  54. clearTelIcon.value = true;
  55. } else {
  56. clearTelIcon.value = false;
  57. }
  58. }
  59. // 密码校验
  60. function passwordInputChange(event){
  61. if (event.detail.value.length > 0) {
  62. clearPwIcon.value = true;
  63. } else {
  64. clearPwIcon.value = false;
  65. }
  66. }
  67. // 清除手机号
  68. function clearTel(){
  69. userName.value = '';
  70. clearTelIcon.value = false;
  71. }
  72. // 清除密码
  73. function clearPw(){
  74. password.value = '';
  75. clearPwIcon.value = false;
  76. }
  77. // 密码显隐
  78. function changePassword() {
  79. showPassword.value = !showPassword.value;
  80. }
  81. // 登录
  82. function handleLogin() {
  83. if(userName.value.length ===0){
  84. toast('请输入手机号!')
  85. return
  86. }
  87. if(password.value.length ===0){
  88. toast('请输入密码!')
  89. return
  90. }
  91. // 去除 userName 两端的空格
  92. const trimmedUserName = userName.value;
  93. const trimmedPassword = lliPassword.value;
  94. httpApi.login({
  95. userName: trimmedUserName,
  96. password: lliPassword.value,
  97. }).then(res => {
  98. // 2为家政管理员
  99. if(res.data.type ===2){
  100. cacheManager.set('auth', res.data)
  101. store.setIsCanBack(false)
  102. // 页面跳转
  103. gotoPage();
  104. }else{
  105. toast('登录失败,您的身份有误,请联系管理员。')
  106. }
  107. }).catch(err => {
  108. store.setIsCanBack(true)
  109. })
  110. }
  111. // 跳转
  112. function gotoPage(){
  113. uni.navigateTo({
  114. url: `/pages/admin/ShouYe/shouye`
  115. })
  116. }
  117. </script>
  118. <style>
  119. </style>