adminloginBox.vue 5.1 KB

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