This commit is contained in:
@@ -1,29 +1,46 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="card flex-col-g20">
|
||||
<view class="flex-row-g20">
|
||||
<label for="">手机号:</label>
|
||||
<up-input placeholder="请输入绑定的手机号" border="surround" v-model="bind.phone" />
|
||||
<view class="page">
|
||||
<!-- 自定义导航栏 -->
|
||||
<view v-if="!fromLogin" class="custom-navbar">
|
||||
<view class="navbar-back" @tap="goBack">
|
||||
<text class="back-icon">←</text>
|
||||
<text class="back-text">返回</text>
|
||||
</view>
|
||||
<view class="navbar-title">绑定手机号</view>
|
||||
<view class="navbar-placeholder"></view>
|
||||
</view>
|
||||
|
||||
<view class="flex-row-g20">
|
||||
<label for="">验证码:</label>
|
||||
<up-input placeholder="验证码" v-model="bind.code">
|
||||
<template #suffix>
|
||||
<up-button @tap="getCode" :text="codeText" type="success" :disabled="cooldown > 0"></up-button>
|
||||
</template>
|
||||
</up-input>
|
||||
</view>
|
||||
<view class="container" :style="{ paddingTop: fromLogin ? '0' : '0' }">
|
||||
<view class="card flex-col-g20">
|
||||
<view class="flex-row-g20">
|
||||
<label for="">手机号:</label>
|
||||
<up-input placeholder="请输入绑定的手机号" border="surround" v-model="bind.phone" />
|
||||
</view>
|
||||
|
||||
<view class="btn">
|
||||
<up-button type="primary" @tap="bindPhone">绑定手机号</up-button>
|
||||
<view class="flex-row-g20">
|
||||
<label for="">验证码:</label>
|
||||
<up-input placeholder="验证码" v-model="bind.code">
|
||||
<template #suffix>
|
||||
<up-button @tap="getCode" :text="codeText" type="success" :disabled="cooldown > 0"></up-button>
|
||||
</template>
|
||||
</up-input>
|
||||
</view>
|
||||
|
||||
<view class="btn">
|
||||
<up-button type="primary" @tap="bindPhone">绑定手机号</up-button>
|
||||
</view>
|
||||
|
||||
<!-- 如果从登录页面跳转过来,显示退出按钮 -->
|
||||
<view class="btn" v-if="fromLogin">
|
||||
<up-button type="error" @tap="logout">退出</up-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue';
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { authApi } from '@/api/index.js';
|
||||
|
||||
let bind = reactive({
|
||||
@@ -33,7 +50,16 @@
|
||||
|
||||
let cooldown = ref(0);
|
||||
let codeText = ref('获取验证码');
|
||||
let timer = null;
|
||||
let timer = null;
|
||||
let fromLogin = ref(false);
|
||||
|
||||
onMounted(() => {
|
||||
// 获取页面参数,判断是否从登录页面跳转过来
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const options = currentPage.options;
|
||||
fromLogin.value = options.fromLogin === 'true';
|
||||
});
|
||||
|
||||
const getCode = async () => {
|
||||
if (!bind.phone) {
|
||||
@@ -77,13 +103,88 @@ let timer = null;
|
||||
await authApi.bindPhone(bind.phone, bind.code);
|
||||
uni.showToast({ title: '绑定成功', icon: 'success' });
|
||||
setTimeout(() => {
|
||||
uni.navigateBack();
|
||||
if (fromLogin.value) {
|
||||
// 从登录页面过来的,绑定成功后跳转到首页
|
||||
uni.redirectTo({ url: '/pages/index/index' });
|
||||
} else {
|
||||
// 从其他页面过来的,返回上一页
|
||||
uni.navigateBack();
|
||||
}
|
||||
}, 1500);
|
||||
} catch (e) {
|
||||
console.error('绑定手机号失败', e);
|
||||
}
|
||||
};
|
||||
|
||||
const logout = () => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要退出登录吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.clearStorageSync();
|
||||
uni.reLaunch({ url: '/pages/login/login' });
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const goBack = () => {
|
||||
uni.navigateBack();
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
<style lang="scss" scoped>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.custom-navbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 88rpx;
|
||||
background: var(--bg-primary);
|
||||
border-bottom: 1rpx solid var(--border-light);
|
||||
padding: 0 24rpx;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
|
||||
.navbar-back {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
padding: 8rpx;
|
||||
cursor: pointer;
|
||||
|
||||
.back-icon {
|
||||
font-size: 36rpx;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.back-text {
|
||||
font-size: 28rpx;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.navbar-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.navbar-placeholder {
|
||||
width: 100rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.container {
|
||||
padding: var(--space-md);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user