adminloginBox.vue 3.6 KB

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