adminloginBox.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. <tip-dialog ref="tipDialogRef" :title="tipTitle" :content="tipContent"></tip-dialog>
  26. </view>
  27. </template>
  28. <script setup>
  29. import {onShow} from '@dcloudio/uni-app';
  30. import cacheManager from '@/utils/cacheManager.js'
  31. import * as httpApi from "@/api/login.js"
  32. import passwordLli from "@/components/password-lli/password-lli.vue";
  33. import {ref} from "vue"
  34. import {toast} from "@/utils/common";
  35. import {useIsCanBack} from "@/store/isCanBack.js"
  36. import config from '../../../config.js'
  37. import tipDialog from '@/components/dialog/tipDialog.vue';
  38. const userName = ref('') // 用户名
  39. const password = ref('') // 密码
  40. const lliPassword = ref('') // 加密后的密码
  41. const passLLiRef = ref(null)
  42. const showPassword= ref(true)
  43. const clearTelIcon= ref(false)
  44. const clearPwIcon= ref(false)
  45. const store = useIsCanBack();
  46. const version = config.appInfo.version;
  47. const tipDialogRef = ref(null);
  48. const tipTitle = '升级提醒';
  49. const tipContent = '您的APP不是最新版本,请升级至最新版本。';
  50. // 加密
  51. function handleUpdateLLiPassword() {
  52. passLLiRef.value.lliPassword();
  53. }
  54. function onLliPassword(password) {
  55. console.log('onLliPassword',password)
  56. lliPassword.value = password;
  57. }
  58. // 手机号校验
  59. function userInputChange(event){
  60. if (event.detail.value.length > 0) {
  61. clearTelIcon.value = true;
  62. } else {
  63. clearTelIcon.value = false;
  64. }
  65. }
  66. // 密码校验
  67. function passwordInputChange(event){
  68. if (event.detail.value.length > 0) {
  69. clearPwIcon.value = true;
  70. } else {
  71. clearPwIcon.value = false;
  72. }
  73. }
  74. // 清除手机号
  75. function clearTel(){
  76. userName.value = '';
  77. clearTelIcon.value = false;
  78. }
  79. // 清除密码
  80. function clearPw(){
  81. password.value = '';
  82. clearPwIcon.value = false;
  83. }
  84. // 密码显隐
  85. function changePassword() {
  86. showPassword.value = !showPassword.value;
  87. }
  88. // 登录
  89. function handleLogin() {
  90. if(userName.value.length ===0){
  91. toast('请输入手机号!')
  92. return
  93. }
  94. if(password.value.length ===0){
  95. toast('请输入密码!')
  96. return
  97. }
  98. // 去除 userName 两端的空格
  99. const trimmedUserName = userName.value;
  100. const trimmedPassword = lliPassword.value;
  101. httpApi.login({
  102. // type 1app 2为H5
  103. type:1,
  104. userName: trimmedUserName,
  105. password: lliPassword.value,
  106. }).then(res => {
  107. // 2为家政管理员
  108. if(res.data.type ===2){
  109. cacheManager.set('auth', res.data)
  110. store.setIsCanBack(false)
  111. // 页面跳转
  112. gotoPage();
  113. }else{
  114. toast('登录失败,您的身份有误,请联系管理员。')
  115. }
  116. }).catch(err => {
  117. store.setIsCanBack(true)
  118. })
  119. }
  120. // 跳转
  121. function gotoPage(){
  122. uni.navigateTo({
  123. url: `/pages/admin/ShouYe/shouye`
  124. })
  125. }
  126. function getLoginInit(){
  127. httpApi.getVersion({}).then(res => {
  128. console.log(version,res,'version+res');
  129. if(version!=res.data.version){
  130. tipDialogRef.value.handleShow();
  131. }
  132. })
  133. }
  134. onShow(() => {
  135. // getLoginInit()
  136. })
  137. </script>
  138. <style>
  139. </style>