fix login
This commit is contained in:
parent
3ed8bd5327
commit
96f2ee15eb
@ -53,6 +53,12 @@ page {
|
||||
font-size: 36rpx;
|
||||
color: #ffffff;
|
||||
}
|
||||
.logout-btn {
|
||||
margin-top: 40rpx;
|
||||
background: #ffffff;
|
||||
border: 1rpx solid #ff370b;
|
||||
color: #ff370b;
|
||||
}
|
||||
.tabel1 {
|
||||
margin: 0 20rpx;
|
||||
border-bottom: 1rpx solid #ebebeb;
|
||||
|
||||
@ -73,6 +73,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="btn logout-btn" @click="headerLogoutClick">退出登录</view>
|
||||
<nav-footer :current="4"/>
|
||||
</view>
|
||||
</template>
|
||||
@ -191,6 +192,36 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
// 退出登录
|
||||
headerLogoutClick() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要退出登录吗?',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return;
|
||||
// 清除全部登录态缓存
|
||||
const keys = [
|
||||
'ctoken', 'userId', 'openId', 'phone', 'is_deal', 'is_dev',
|
||||
'is_shop', 'is_merchant', 'is_worker', 'shopId',
|
||||
'order_dispatch_permission', 'work_order_permission',
|
||||
'nickName', 'headPhoto', 'changeCommData', 'currentRoomNo'
|
||||
];
|
||||
keys.forEach(k => uni.removeStorageSync(k));
|
||||
uni.showToast({
|
||||
title: '已退出登录',
|
||||
icon: 'success',
|
||||
mask: true,
|
||||
duration: 1500,
|
||||
success: () => {
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/login/login' });
|
||||
}, 1500);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
headerRadioClick(item) {
|
||||
this.sex = item;
|
||||
},
|
||||
|
||||
@ -17,6 +17,16 @@
|
||||
<view class="login-tip" style="font-size: 28rpx; color: #555555; margin-top: 30rpx;">为了更好的体验,申请获取您的公开信息
|
||||
</view>
|
||||
<view class="login-tip" style="font-size: 28rpx; color: #555555; margin-top: 14rpx;">(头像、昵称等)</view>
|
||||
|
||||
<view class="profile-fill">
|
||||
<button class="avatar-btn" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
|
||||
<image class="avatar-img" :src="avatarUrl || defaultAvatar" mode="aspectFill"></image>
|
||||
<text class="avatar-tip">点击选择头像</text>
|
||||
</button>
|
||||
<input type="nickname" class="nickname-input" :value="nickName" placeholder="点击填写昵称"
|
||||
@blur="onNickInput" @input="onNickInput" />
|
||||
</view>
|
||||
|
||||
<view class="login-button">
|
||||
<button class="login-btn" open-type="getPhoneNumber" @click="headerLoginClick"
|
||||
@getphonenumber="getPhoneNumber">
|
||||
@ -37,6 +47,7 @@
|
||||
import { apiArr } from '../../api/login';
|
||||
import { apiArr as apiArr2 } from '../../api/v2User';
|
||||
import { request } from '../../utils';
|
||||
import { uploadOSS } from '@/utils/uploadOSS';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -44,10 +55,26 @@ export default {
|
||||
loginChannel: '', // 登录渠道
|
||||
userId: '',
|
||||
passWord: '',
|
||||
nickName: '', // 微信昵称(头像昵称填写能力)
|
||||
avatarUrl: '', // 头像预览地址(临时或OSS)
|
||||
avatarTemp: '', // 微信头像临时路径,登录后再传OSS
|
||||
defaultAvatar: 'https://static.hshuishang.com/loginMainImg.png',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
// 选择头像回调:此时尚未登录(无 token),仅暂存临时路径,
|
||||
// 待 get-phone 成功拿到 token 后再上传 OSS
|
||||
onChooseAvatar(e) {
|
||||
this.avatarTemp = e.detail.avatarUrl || '';
|
||||
this.avatarUrl = this.avatarTemp; // 仅用于界面预览
|
||||
},
|
||||
|
||||
// 昵称输入回调
|
||||
onNickInput(e) {
|
||||
this.nickName = e.detail.value || '';
|
||||
},
|
||||
|
||||
headerInputClick(e) {
|
||||
const { name } = e.currentTarget.dataset;
|
||||
const { value } = e.detail;
|
||||
@ -114,12 +141,30 @@ export default {
|
||||
// return
|
||||
if (event.detail.errMsg === "getPhoneNumber:ok") {
|
||||
request(apiArr.loginGetUserPhone, 'POST', {
|
||||
code: event.detail.code
|
||||
}, { silent: false }).then((res) => {
|
||||
code: event.detail.code,
|
||||
user_id: uni.getStorageSync('userId'),
|
||||
nick_name: this.nickName || ''
|
||||
}, { silent: false }).then(async (res) => {
|
||||
console.log(res);
|
||||
uni.hideLoading();
|
||||
if (isLogin) {
|
||||
uni.setStorageSync('phone', res.phone);
|
||||
if (this.nickName) uni.setStorageSync('nickName', this.nickName);
|
||||
// 此时已登录(有 token),把头像临时路径上传到 OSS 并落库
|
||||
if (this.avatarTemp) {
|
||||
try {
|
||||
const { objectKey } = await uploadOSS({ filePath: this.avatarTemp, scene: 'avatar', showLoading: false });
|
||||
// 数据库统一存相对 object key(带前导/),显示时再拼 CDN 域名
|
||||
const avatarPath = '/' + objectKey;
|
||||
await request(apiArr2.userInfoUpdate, 'POST', {
|
||||
user_id: uni.getStorageSync('userId'),
|
||||
avatar: avatarPath
|
||||
}, { silent: true });
|
||||
uni.setStorageSync('headPhoto', avatarPath);
|
||||
} catch (err) {
|
||||
console.error('头像上传/保存失败:', err);
|
||||
}
|
||||
}
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success',
|
||||
@ -132,6 +177,7 @@ export default {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '登录失败',
|
||||
icon: 'error',
|
||||
@ -181,8 +227,10 @@ export default {
|
||||
page_num: 1,
|
||||
page_size: 10,
|
||||
}, { silent: false }).then((res3) => {
|
||||
const { rows: [{}] } = res3;
|
||||
uni.setStorageSync("changeCommData",{ name: rows[0].name, id: rows[0].community_id })
|
||||
const rows = (res3 && res3.rows) || [];
|
||||
if (rows.length > 0) {
|
||||
uni.setStorageSync("changeCommData", { name: rows[0].name, id: rows[0].community_id });
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@ -260,4 +308,49 @@ export default {
|
||||
|
||||
<style>
|
||||
@import url("./login.css");
|
||||
|
||||
.profile-fill {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.avatar-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.avatar-btn::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.avatar-img {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
border-radius: 50%;
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
.avatar-tip {
|
||||
font-size: 24rpx;
|
||||
color: #999999;
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
|
||||
.nickname-input {
|
||||
width: 420rpx;
|
||||
height: 80rpx;
|
||||
margin-top: 24rpx;
|
||||
padding: 0 24rpx;
|
||||
border: 1rpx solid #e0e0e0;
|
||||
border-radius: 12rpx;
|
||||
font-size: 28rpx;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
Loading…
x
Reference in New Issue
Block a user