| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <template>
- <view class="phone-login-page">
- <view class="login-wrap-box">
- <view class="bjcx-head-box">
- <icon class="bjcx-logo-box"></icon>
- <view class="bjcx-logo-title">家政学</view>
- </view>
- <!-- 普通登录表单 -->
- <view class="login-input-body">
- <view class="login-input-box">
- <icon class="user-icon"></icon>
- <input class="login-input" type="text" v-model="userName" placeholder="请输入手机号"
- @input="userInputChange">
- <view class="close-btn" v-if="clearTelIcon" @click="clearTel"></view>
- </view>
- <view class="login-input-box">
- <icon class="tel-icon"></icon>
- <input class="login-input" placeholder="请输入证件号后六位" v-model="password" :password="showPassword"
- @input="passwordInputChange" />
- <text class="login-eye" :class="[!showPassword ? 'uni-eye-active' : '']"
- @click="changePassword"></text>
- <view class="close-btn" v-if="clearPwIcon" @click="clearPw"></view>
- </view>
- <!-- 协议勾选框和按钮 -->
- <view class="agreement-checkbox-box">
- <checkbox-group @change="handleChange">
- <checkbox class="agreement-checkbox-input" color="#3fd2a1" value="agree" :checked="isAgreed"
- style="transform:scale(0.7)" />
- </checkbox-group>
- <view class="agreement-text-box">
- 在使用当前小程序服务之前,请仔细阅读<view class="agreement-text" @click="agreeBtn('yhxy')">《诚祥学用户协议》</view>和<view
- @click="agreeBtn('ystk')" class="agreement-text">《诚祥学隐私政策》</view>,如您同意,请勾选后开始使用
- </view>
- </view>
- <button @click="handleLogin" class="phone-green-btn wechat-auth-btn" type="default" hover-class="none">登录</button>
- <view class="qtdl-btn"><text @click="handleChangeYijiandenglu">微信一键登录</text></view>
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import cacheManager from '@/utils/cacheManager.js'
- import * as httpApi from "@/api/login.js"
- import {
- ref,
- onMounted
- } from "vue"
- import {
- toast
- } from "@/utils/common";
- import {
- useIsCanBack
- } from "@/store/isCanBack.js"
- import {
- onLoad
- } from "@dcloudio/uni-app";
- // 原有变量
- const userName = ref('')
- const password = ref('')
- const showPassword = ref(true)
- const clearTelIcon = ref(false)
- const clearPwIcon = ref(false)
- const isAgreed = ref(false)
- const id = ref('')
- const code = ref('')
- const fromPage = ref('');
- // 新增变量
- const fromAppShare = ref(false) // 是否来自APP分享
- const store = useIsCanBack();
- onLoad((options) => {
- fromPage.value = options.from;
- id.value = options.id
- getAllImg();
- })
- function handleChangeYijiandenglu() {
- let str = ``;
- if (id.value) {
- str = str+`id=${id.value}`
- }
- if ( id.value && fromPage.value ) {
- str = str +`&from=${fromPage.value}`
- } else if (!id.value && fromPage.value) {
- str = str + `from=${fromPage.value}`
- }
- if (str) {
- uni.redirectTo({
- url: `/pages/Login/clientIndex?${str}`
- })
- } else {
- uni.redirectTo({
- url: `/pages/Login/clientIndex`
- })
- }
- }
- // 你原有的所有方法都不变
- function handleChange() {
- isAgreed.value = !isAgreed.value
- }
- function agreeBtn(code) {
- if (code === 'yhxy') {
- uni.navigateTo({
- url: "/pages/client/my/xieyi"
- })
- } else {
- uni.navigateTo({
- url: "/pages/client/my/zhengce"
- })
- }
- }
- function userInputChange(event) {
- if (event.detail.value.length > 0) {
- clearTelIcon.value = true;
- } else {
- clearTelIcon.value = false;
- }
- }
- function passwordInputChange(event) {
- if (event.detail.value.length > 0) {
- clearPwIcon.value = true;
- } else {
- clearPwIcon.value = false;
- }
- }
- function clearTel() {
- userName.value = '';
- clearTelIcon.value = false;
- }
- function clearPw() {
- password.value = '';
- clearPwIcon.value = false;
- }
- function changePassword() {
- showPassword.value = !showPassword.value;
- }
- function handleLogin() {
- if (userName.value.length === 0) {
- toast('请输入手机号!')
- return
- }
- if (password.value.length === 0) {
- toast('请输入密码!')
- return
- }
- if (!isAgreed.value) {
- toast('请先阅读并同意用户协议和隐私政策')
- return // 直接返回,不执行后面的授权逻辑
- }
- const trimmedUserName = userName.value;
- const trimmedPassword = password.value;
- uni.showLoading({
- title: '登录中'
- })
- httpApi.appletLoginTel({
- tel: trimmedUserName,
- str: trimmedPassword,
- }).then(res => {
- if (res.data.type === 4) {
- cacheManager.set('auth', res.data)
- store.setIsCanBack(false)
- gotoPage();
- } else if (res.data.type === 6) {
- cacheManager.set('auth', res.data)
- store.setIsCanBack(false)
- gotoPage2();
- } else {
- toast('登录失败,您的身份有误,请联系管理员。')
- }
- uni.hideLoading()
- }).catch(err => {
- store.setIsCanBack(true)
- setTimeout(() => {
- uni.hideLoading()
- },4000)
- }).finally(err => {
- })
- }
- function gotoPage() {
- if (id.value) {
- uni.redirectTo({
- url: `/pages/client/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
- })
- } else {
- uni.redirectTo({
- url: `/pages/client/ShouYe/shouye`
- })
- }
- }
- function gotoPage2() {
- if (id.value) {
- uni.redirectTo({
- url: `/pages/kehu/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
- })
- } else {
- uni.redirectTo({
- url: `/pages/kehu/shouye/shouye`
- })
- }
- }
- function getAllImg() {
- httpApi.getAllImgList({}).then(res => {
- cacheManager.set('projectImg', res.data)
- });
- }
- </script>
|