mirror of
http://36.133.248.69:3088/admin/RentWeAppFront.git
synced 2026-06-07 06:22:27 +08:00
修复bug
This commit is contained in:
@@ -1,36 +1,25 @@
|
||||
<template>
|
||||
<view class="login-container">
|
||||
<!-- 顶部状态栏 -->
|
||||
<!-- <view class="status-bar">
|
||||
<u-icon name="arrow-left" size="40" color="#333" @tap="goBack" class="nav-left"></u-icon>
|
||||
<u-icon :name="btn.icon" :color="btn.color || '#333'" :size="btn.size || 40"></u-icon>
|
||||
</view> -->
|
||||
<customNavbar opacity="0" :show-home="true" :show-back="false" :is-transparent="true" />
|
||||
<customNavbar opacity="0" :show-home="true" :show-back="false" :is-transparent="true" />
|
||||
|
||||
<!-- 主体内容区 -->
|
||||
<view class="content">
|
||||
<!-- 标题区域 -->
|
||||
<view class="title">登录</view>
|
||||
|
||||
<!-- 登录插图区域 -->
|
||||
<view class="illustration">
|
||||
<image :src="staticHost + '/public/static/login/bg.png'" mode="aspectFit" />
|
||||
</view>
|
||||
|
||||
<!-- 登录按钮 -->
|
||||
<button class="login-btn" open-type="getPhoneNumber" @getphonenumber="onGetPhone">
|
||||
手机号快捷登录
|
||||
</button>
|
||||
|
||||
<!-- 用户类型选择 -->
|
||||
<view class="user-type" shape="square">
|
||||
<view class="user-type">
|
||||
<u-radio-group v-model="loginType" active-color="#EA414A" shape="square">
|
||||
<u-radio name="0">个人</u-radio>
|
||||
<u-radio name="1">企业</u-radio>
|
||||
</u-radio-group>
|
||||
</view>
|
||||
|
||||
<!-- 协议勾选 -->
|
||||
<view class="agreement">
|
||||
<u-checkbox v-model="agreeProtocol" shape="square" active-color="#EA414A">
|
||||
<text class="agreement-text">
|
||||
@@ -45,287 +34,206 @@
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
designWidth: 750,
|
||||
screenWidth: 0,
|
||||
scale: 1,
|
||||
loginType: "0",
|
||||
agreeProtocol: false,
|
||||
menuRect: {}
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
wx.getWindowInfo({
|
||||
success: (res) => {
|
||||
this.screenWidth = res.windowWidth
|
||||
this.scale = this.screenWidth / this.designWidth
|
||||
}
|
||||
})
|
||||
const menuRect = wx.getMenuButtonBoundingClientRect()
|
||||
this.menuRect = menuRect
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
|
||||
agreeProtocol: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// title 样式
|
||||
titleStyle() {
|
||||
const s = this.scale;
|
||||
return {
|
||||
width: `${93 * s}rpx`,
|
||||
height: `${45 * s}rpx`,
|
||||
fontSize: `${48 * s}rpx`,
|
||||
lineHeight: `${40 * s}rpx`,
|
||||
fontWeight: 500,
|
||||
color: '#222222',
|
||||
fontFamily: 'Noto Sans S Chinese',
|
||||
textAlign: 'center'
|
||||
}
|
||||
},
|
||||
navStyle() {
|
||||
const rect = this.menuRect
|
||||
if (!rect.top) return {}
|
||||
return {
|
||||
paddingTop: rect.top + 'px',
|
||||
height: rect.height + 'px',
|
||||
lineHeight: rect.height + 'px'
|
||||
}
|
||||
},
|
||||
staticHost() {
|
||||
return this.$config.staticUrl
|
||||
},
|
||||
headerStyle() {
|
||||
const s = this.scale;
|
||||
return {
|
||||
marginTop: `${214 * s}rpx`,
|
||||
flex: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'center', // 水平居中
|
||||
justifyContent: 'flex-start' // 从顶部开始
|
||||
}
|
||||
},
|
||||
// cover 样式
|
||||
coverStyle() {
|
||||
const s = this.scale;
|
||||
return {
|
||||
width: `${428 * s}rpx`,
|
||||
height: `${608 * s}rpx`
|
||||
}
|
||||
return this.$config.staticUrl;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
/** 微信手机号授权 */
|
||||
onGetPhone(e) {
|
||||
const {
|
||||
code
|
||||
} = e.detail;
|
||||
|
||||
if (!code) {
|
||||
this.$mytip.toast("授权失败");
|
||||
// 微信获取手机号(修复版)
|
||||
async onGetPhone(e) {
|
||||
// 用户拒绝
|
||||
if (e.detail.errMsg !== "getPhoneNumber:ok") {
|
||||
this.$mytip.toast("已取消授权");
|
||||
return;
|
||||
}
|
||||
this.doLogin(code);
|
||||
},
|
||||
goBack() {
|
||||
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
|
||||
},
|
||||
/** 执行登录逻辑 */
|
||||
async doLogin(phoneGetCode) {
|
||||
|
||||
// 必须勾选协议
|
||||
if (!this.agreeProtocol) {
|
||||
this.$mytip.toast('请先阅读并同意用户协议和隐私政策')
|
||||
return
|
||||
this.$mytip.toast("请先同意用户协议与隐私政策");
|
||||
return;
|
||||
}
|
||||
uni.showLoading({
|
||||
title: "登录中...",
|
||||
mask: true
|
||||
});
|
||||
|
||||
try {
|
||||
// 微信登录
|
||||
// 1. 先拿微信登录 code
|
||||
const loginRes = await new Promise((resolve, reject) => {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
provider: "weixin",
|
||||
success: resolve,
|
||||
fail: reject
|
||||
});
|
||||
});
|
||||
|
||||
// 调用后端登录接口
|
||||
const authRes = await this.$u.post(`/login/weChatLogin`, {
|
||||
phoneGetCode: phoneGetCode,
|
||||
// 2. 传给后端登录
|
||||
await this.doLogin({
|
||||
loginCode: loginRes.code,
|
||||
encryptedData: e.detail.encryptedData,
|
||||
iv: e.detail.iv,
|
||||
loginType: this.loginType
|
||||
});
|
||||
|
||||
// 保存token
|
||||
let token = authRes.data;
|
||||
this.$u.vuex('vuex_token', token);
|
||||
} catch (err) {
|
||||
this.$mytip.toast("授权失败,请重试");
|
||||
}
|
||||
},
|
||||
|
||||
// 登录接口(修复:用户信息 + 全局刷新)
|
||||
async doLogin(data) {
|
||||
uni.showLoading({ title: "登录中...", mask: true });
|
||||
|
||||
try {
|
||||
// 1. 登录拿 token
|
||||
const authRes = await this.$u.post("/login/weChatLogin", data);
|
||||
const token = authRes.data;
|
||||
|
||||
if (!token) {
|
||||
uni.hideLoading();
|
||||
this.$mytip.toast("登录失败");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 保存 token(全局)
|
||||
this.$u.vuex("vuex_token", token);
|
||||
|
||||
// 3. 获取并保存用户信息(修复:必须 await 等它完成)
|
||||
await this.getUserOtherInfo(this.loginType, token);
|
||||
|
||||
// 4. 登录成功 → 强制刷新全局状态 + 跳首页
|
||||
uni.hideLoading();
|
||||
this.getUserOtherInfo(this.loginType, token)
|
||||
// 跳转首页
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
});
|
||||
this.$mytip.toast("登录成功");
|
||||
|
||||
// 🔥 关键:强制刷新页面,解决用户信息不显示
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: "/pages/index/index",
|
||||
success() {
|
||||
const page = getCurrentPages().pop();
|
||||
if (page) page.onLoad();
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
|
||||
} catch (err) {
|
||||
uni.hideLoading();
|
||||
this.$mytip.toast("登录失败");
|
||||
console.error('Login failed:', err);
|
||||
this.$mytip.toast("登录失败,请稍后重试");
|
||||
}
|
||||
},
|
||||
getUserOtherInfo(loginType, token) {
|
||||
let url = `/login/userInfo`;
|
||||
this.$u.get(url, {}, {
|
||||
'WT': token,
|
||||
'USERTYPE': loginType
|
||||
}).then(obj => {
|
||||
if (obj.flag) {
|
||||
uni.setStorageSync('userInfo', {
|
||||
userType: obj.data.userType,
|
||||
oaAuth: obj.data.oaAuth,
|
||||
cusNo: obj.data.cusNo,
|
||||
userName: obj.data.userName,
|
||||
openId: obj.data.openId,
|
||||
subscribe: obj.data.subscribeMsg
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 触发手机号选择(子组件 → 父组件) */
|
||||
showPhoneSelector(phoneList, openid) {
|
||||
this.$emit("choosePhone", {
|
||||
phoneList,
|
||||
openid
|
||||
});
|
||||
},
|
||||
/** 查看协议 */
|
||||
goPrivacy(type) {
|
||||
console.log(type)
|
||||
const url = type === 'user' ?
|
||||
'/pages-biz/privacy/userAgreement' :
|
||||
'/pages-biz/privacy/privacyPolicy';
|
||||
|
||||
uni.navigateTo({
|
||||
url
|
||||
// 获取用户信息(修复:必须返回 Promise)
|
||||
getUserOtherInfo(loginType, token) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.$u.get("/login/userInfo", {}, {
|
||||
"WT": token,
|
||||
"USERTYPE": loginType
|
||||
}).then(obj => {
|
||||
if (obj?.flag) {
|
||||
// 🔥 保存用户信息到缓存
|
||||
uni.setStorageSync('userInfo', obj.data);
|
||||
|
||||
// 🔥 同时存入 vuex 全局状态(首页就能实时刷新)
|
||||
this.$u.vuex('vuex_userInfo', obj.data);
|
||||
}
|
||||
resolve();
|
||||
}).catch(() => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// 返回
|
||||
goBack() {
|
||||
uni.navigateBack({ delta: 1 });
|
||||
},
|
||||
|
||||
// 协议
|
||||
goPrivacy(type) {
|
||||
const url = type === "user"
|
||||
? "/pages-biz/privacy/userAgreement"
|
||||
: "/pages-biz/privacy/privacyPolicy";
|
||||
uni.navigateTo({ url });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.login-container {
|
||||
height: 100vh;
|
||||
background-color: #fff;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
padding-top: var(--status-bar-height);
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-top: 11.56%;
|
||||
height: var(--status-bar-height);
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 0 40rpx;
|
||||
margin-top: 200rpx;
|
||||
}
|
||||
|
||||
}
|
||||
.title {
|
||||
font-size: 48rpx;
|
||||
font-weight: 500;
|
||||
color: #222;
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.nav-left {
|
||||
width: 80rpx;
|
||||
display: flex;
|
||||
padding-left: 5%;
|
||||
align-items: center;
|
||||
}
|
||||
.illustration {
|
||||
width: 100%;
|
||||
height: 400rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 60rpx;
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
height: calc(100vh - var(--status-bar-height));
|
||||
margin-top: 12.8%;
|
||||
}
|
||||
|
||||
.title {
|
||||
height: 45rpx;
|
||||
font-family: Noto Sans S Chinese;
|
||||
font-weight: 500;
|
||||
font-size: 48rpx;
|
||||
color: #222222;
|
||||
line-height: 40rpx;
|
||||
}
|
||||
|
||||
.illustration {
|
||||
width: 100%;
|
||||
height: 44.6%;
|
||||
padding: 0 21.47%;
|
||||
margin-bottom: 6%;
|
||||
}
|
||||
|
||||
.illustration image {
|
||||
width: 100%;
|
||||
image {
|
||||
width: 80%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 78.6%;
|
||||
height: 7.12%;
|
||||
background: linear-gradient(90deg, #FF2F31 0%, #FF9379 100%);
|
||||
border-radius: 49rpx;
|
||||
font-size: 36rpx;
|
||||
color: #ffffff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.user-type {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 40rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.agreement {
|
||||
margin-top: 6.24%;
|
||||
padding: 0 40rpx;
|
||||
}
|
||||
|
||||
.agreement-text {
|
||||
font-size: 26rpx;
|
||||
color: #cecece;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: #334254;
|
||||
}
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background: linear-gradient(90deg, #FF2F31 0%, #FF9379 100%);
|
||||
border-radius: 49rpx;
|
||||
font-size: 36rpx;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 40rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.user-type {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 40rpx;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
/* 响应式适配 */
|
||||
@media (max-width: 320rpx) {
|
||||
.title {
|
||||
font-size: 42rpx;
|
||||
margin-bottom: 100rpx;
|
||||
}
|
||||
.agreement {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.illustration {
|
||||
height: 360rpx;
|
||||
}
|
||||
.agreement-text {
|
||||
font-size: 26rpx;
|
||||
color: #cecece;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
height: 80rpx;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.link {
|
||||
color: #334254;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user