fix login

This commit is contained in:
Daniel Kou 2026-06-22 13:56:12 +08:00
parent 3ed8bd5327
commit 96f2ee15eb
3 changed files with 135 additions and 5 deletions

View File

@ -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;

View File

@ -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;
},

View File

@ -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>