This commit is contained in:
@@ -41,6 +41,11 @@
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { authApi } from '@/api/index.js';
|
||||
import { useUserStore } from '@/store/index.js';
|
||||
|
||||
const POST_BIND_RELOGIN_NOTICE_KEY = 'postBindReloginNotice';
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
let bind = reactive({
|
||||
phone: '',
|
||||
@@ -60,6 +65,23 @@
|
||||
fromLogin.value = options.fromLogin === 'true';
|
||||
});
|
||||
|
||||
const prepareManualRelogin = () => {
|
||||
const preservedIdentifier = userStore.state.identifier || uni.getStorageSync('identifier') || '';
|
||||
|
||||
userStore.clearUser();
|
||||
if (preservedIdentifier) {
|
||||
userStore.setIdentifier(preservedIdentifier);
|
||||
}
|
||||
|
||||
uni.setStorageSync(POST_BIND_RELOGIN_NOTICE_KEY, '1');
|
||||
|
||||
// #ifdef H5
|
||||
if (typeof sessionStorage !== 'undefined') {
|
||||
sessionStorage.removeItem('assetToken');
|
||||
}
|
||||
// #endif
|
||||
};
|
||||
|
||||
const getCode = async () => {
|
||||
if (!bind.phone) {
|
||||
uni.showToast({ title: '请输入手机号', icon: 'none' });
|
||||
@@ -100,15 +122,17 @@
|
||||
|
||||
try {
|
||||
await authApi.bindPhone(bind.phone, bind.code);
|
||||
|
||||
if (fromLogin.value) {
|
||||
prepareManualRelogin();
|
||||
uni.reLaunch({ url: '/pages/login/login' });
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showToast({ title: '绑定成功', icon: 'success' });
|
||||
setTimeout(() => {
|
||||
if (fromLogin.value) {
|
||||
// 从登录页面过来的,绑定成功后跳转到首页
|
||||
uni.redirectTo({ url: '/pages/index/index' });
|
||||
} else {
|
||||
// 从其他页面过来的,返回上一页
|
||||
uni.navigateBack();
|
||||
}
|
||||
// 从其他页面过来的,返回上一页
|
||||
uni.navigateBack();
|
||||
}, 1500);
|
||||
} catch (e) {
|
||||
console.error('绑定手机号失败', e);
|
||||
@@ -193,4 +217,4 @@
|
||||
.container {
|
||||
padding: var(--space-md);
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user