adminloginBox.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. const appStoreUrl = 'itms-apps://itunes.apple.com/app/6754060756'
  68. plus.runtime.openURL(appStoreUrl)
  69. } else {
  70. initDownload(updateUrl.value)
  71. }
  72. }
  73. // 加密
  74. function handleUpdateLLiPassword() {
  75. passLLiRef.value.lliPassword();
  76. }
  77. function onLliPassword(password) {
  78. console.log('onLliPassword',password)
  79. lliPassword.value = password;
  80. }
  81. // 手机号校验
  82. function userInputChange(event){
  83. if (event.detail.value.length > 0) {
  84. clearTelIcon.value = true;
  85. } else {
  86. clearTelIcon.value = false;
  87. }
  88. }
  89. // 密码校验
  90. function passwordInputChange(event){
  91. if (event.detail.value.length > 0) {
  92. clearPwIcon.value = true;
  93. } else {
  94. clearPwIcon.value = false;
  95. }
  96. }
  97. // 清除手机号
  98. function clearTel(){
  99. userName.value = '';
  100. clearTelIcon.value = false;
  101. }
  102. // 清除密码
  103. function clearPw(){
  104. password.value = '';
  105. clearPwIcon.value = false;
  106. }
  107. // 密码显隐
  108. function changePassword() {
  109. showPassword.value = !showPassword.value;
  110. }
  111. // 登录
  112. function handleLogin() {
  113. if(userName.value.length ===0){
  114. toast('请输入手机号!')
  115. return
  116. }
  117. if(password.value.length ===0){
  118. toast('请输入密码!')
  119. return
  120. }
  121. // 去除 userName 两端的空格
  122. const trimmedUserName = userName.value;
  123. const trimmedPassword = lliPassword.value;
  124. httpApi.login({
  125. // type 1app 2为H5
  126. type:1,
  127. userName: trimmedUserName,
  128. password: lliPassword.value,
  129. }).then(res => {
  130. // 2为家政管理员
  131. if(res.data.type ===2 ||res.data.type ===5){
  132. if (cacheManager.get('auth')) {
  133. cacheManager.clearAll()
  134. }
  135. cacheManager.set('auth', res.data)
  136. store.setIsCanBack(false)
  137. // 页面跳转
  138. gotoPage();
  139. }else{
  140. toast('登录失败,您的身份有误,请联系管理员。')
  141. }
  142. }).catch(err => {
  143. store.setIsCanBack(true)
  144. })
  145. }
  146. // 跳转
  147. function gotoPage(){
  148. uni.navigateTo({
  149. url: `/pages/admin/ShouYe/shouye`
  150. })
  151. }
  152. function getLoginInit(){
  153. httpApi.getVersion({}).then(res => {
  154. if (version != res.data.version) {
  155. updateUrl.value = res.data.updateUrl
  156. const systemInfo = uni.getSystemInfoSync();
  157. if (systemInfo.platform == 'ios') {
  158. } else {
  159. tipDialogRef2.value.handleShow();
  160. }
  161. }
  162. })
  163. }
  164. onShow(() => {
  165. getLoginInit()
  166. })
  167. </script>
  168. <style>
  169. </style>