|
|
@@ -6,20 +6,22 @@
|
|
|
<view class="bjcx-logo-title">家政学</view>
|
|
|
</view>
|
|
|
|
|
|
- <!-- 新增:APP分享过来的微信授权 -->
|
|
|
- <view v-if="fromAppShare && !showNormalLogin" class="wechat-auth-box">
|
|
|
+ <!-- 如果是APP分享过来的,显示微信授权界面 @getuserinfo="onWechatAuth"-->
|
|
|
+
|
|
|
+ <view v-if="fromAppShare" class="wechat-auth-box">
|
|
|
<view class="auth-tips">欢迎使用小程序</view>
|
|
|
<button
|
|
|
class="wechat-auth-btn"
|
|
|
open-type="getUserInfo"
|
|
|
- @getuserinfo="onWechatAuth"
|
|
|
+ @click="onWechatAuth"
|
|
|
+
|
|
|
>
|
|
|
微信一键登录
|
|
|
</button>
|
|
|
- <view class="switch-login" @click="showNormalLogin = true">使用账号登录</view>
|
|
|
+ <view class="switch-login" @click="switchToNormalLogin">使用账号登录</view>
|
|
|
</view>
|
|
|
|
|
|
- <!-- 原有登录表单 -->
|
|
|
+ <!-- 普通登录表单 -->
|
|
|
<view v-else>
|
|
|
<view class="login-input-box">
|
|
|
<icon class="user-icon"></icon>
|
|
|
@@ -56,7 +58,7 @@
|
|
|
<script setup>
|
|
|
import cacheManager from '@/utils/cacheManager.js'
|
|
|
import * as httpApi from "@/api/login.js"
|
|
|
- import {ref} from "vue"
|
|
|
+ import {ref, onMounted} from "vue"
|
|
|
import {toast} from "@/utils/common";
|
|
|
import {useIsCanBack} from "@/store/isCanBack.js"
|
|
|
import { onLoad } from "@dcloudio/uni-app";
|
|
|
@@ -70,8 +72,7 @@
|
|
|
const isAgreed = ref(false)
|
|
|
|
|
|
// 新增变量
|
|
|
- const fromAppShare = ref(false) // 是否来自APP分享
|
|
|
- const showNormalLogin = ref(false) // 是否显示普通登录
|
|
|
+ const fromAppShare = ref(true) // 是否来自APP分享
|
|
|
|
|
|
const store = useIsCanBack();
|
|
|
|
|
|
@@ -79,52 +80,78 @@
|
|
|
// 判断是否来自APP分享
|
|
|
if (options.from === 'appcx') {
|
|
|
fromAppShare.value = true
|
|
|
+ // APP分享过来直接显示微信授权界面,不需要自动弹窗
|
|
|
}
|
|
|
getAllImg();
|
|
|
})
|
|
|
|
|
|
+ // 切换到普通登录
|
|
|
+ function switchToNormalLogin() {
|
|
|
+ fromAppShare.value = false
|
|
|
+ }
|
|
|
+
|
|
|
// 微信授权登录
|
|
|
async function onWechatAuth(e) {
|
|
|
- if (e.detail.errMsg.includes('fail')) {
|
|
|
- toast('授权失败')
|
|
|
- return
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/Login/AliyunCaptcha?scene=login',
|
|
|
+ events: {
|
|
|
+ getCaptchaVerifyParam: (captchaVerifyParam) => {
|
|
|
+ // 接收到验证码返回结果
|
|
|
+ console.log('验证码返回结果:', captchaVerifyParam)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ success: () => {
|
|
|
+ console.log('跳转到验证码页面成功')
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('跳转到验证码页面失败:', err)
|
|
|
+ toast('验证码加载失败,请重试')
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // if (e.detail.errMsg.includes('fail')) {
|
|
|
+ // toast('授权失败')
|
|
|
+ // return
|
|
|
+ // }
|
|
|
|
|
|
- uni.showLoading({ title: '登录中' })
|
|
|
-
|
|
|
- try {
|
|
|
- // 获取微信code
|
|
|
- const loginRes = await uni.login()
|
|
|
-
|
|
|
- // 调用后端微信登录接口
|
|
|
- const result = await httpApi.wechatLogin({
|
|
|
- code: loginRes.code,
|
|
|
- userInfo: e.detail.userInfo
|
|
|
- })
|
|
|
-
|
|
|
- if (result.data.success) {
|
|
|
- // 保存用户信息
|
|
|
- cacheManager.set('auth', result.data)
|
|
|
+ // uni.showLoading({ title: '登录中' })
|
|
|
+ // console.log('e',e);
|
|
|
+ // try {
|
|
|
+ // // 获取微信code
|
|
|
+ // const loginRes = await uni.login()
|
|
|
+ // console.log('loginRes',loginRes);
|
|
|
+ // // 调用后端微信登录接口
|
|
|
+ // const result = await httpApi.loginApplet({
|
|
|
+ // code: loginRes.code,
|
|
|
+ // userInfo: e.detail.userInfo
|
|
|
+ // })
|
|
|
+ // console.log('result',result);
|
|
|
+ // console.log('result',result);
|
|
|
+ // if (result.data.success) {
|
|
|
+ // // 保存用户信息
|
|
|
+ // cacheManager.set('auth', result.data)
|
|
|
|
|
|
- // 检查手机号绑定状态
|
|
|
- const bindResult = await httpApi.checkPhoneBind()
|
|
|
+ // // // 检查手机号绑定状态
|
|
|
+ // // const bindResult = await httpApi.checkPhoneBind()
|
|
|
|
|
|
- if (bindResult.data.hasPhone) {
|
|
|
- // 已绑定手机号,进入首页
|
|
|
- store.setIsCanBack(false)
|
|
|
- gotoPage()
|
|
|
- } else {
|
|
|
- // 未绑定手机号,跳转绑定页面
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/bind-phone/bind-phone'
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- toast('微信登录失败')
|
|
|
- } finally {
|
|
|
- uni.hideLoading()
|
|
|
- }
|
|
|
+ // // if (bindResult.data.hasPhone) {
|
|
|
+ // // // 已绑定手机号,进入首页
|
|
|
+ // // store.setIsCanBack(false)
|
|
|
+ // // gotoPage()
|
|
|
+ // // } else {
|
|
|
+ // // // 未绑定手机号,跳转绑定页面
|
|
|
+ // // uni.navigateTo({
|
|
|
+ // // url: '/pages/bind-phone/bind-phone'
|
|
|
+ // // })
|
|
|
+ // // }
|
|
|
+ // }
|
|
|
+ // } catch (error) {
|
|
|
+ // toast('微信登录失败')
|
|
|
+ // } finally {
|
|
|
+ // uni.hideLoading()
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
// 你原有的所有方法都不变
|