注册集成手机号登录,修改密码,修改手机号
This commit is contained in:
@@ -35,6 +35,14 @@ const cartCount = ref(0)
|
||||
// 加载购物车数量
|
||||
const loadCartCount = async () => {
|
||||
try {
|
||||
// 检查用户是否已登录
|
||||
const token = localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')
|
||||
if (!token) {
|
||||
console.log('用户未登录,不加载购物车数据')
|
||||
cartCount.value = 0
|
||||
return
|
||||
}
|
||||
|
||||
const response = await cartApi.getCartList() as any
|
||||
const data = response || []
|
||||
const cartList = Array.isArray(data) ? data : []
|
||||
@@ -43,6 +51,7 @@ const loadCartCount = async () => {
|
||||
cartCount.value = totalQuantity
|
||||
} catch (error) {
|
||||
console.error('获取购物车数量失败:', error)
|
||||
cartCount.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,11 @@ export interface LoginRequest {
|
||||
rememberMe?: boolean
|
||||
}
|
||||
|
||||
export interface PhoneLoginRequest {
|
||||
phone: string
|
||||
verificationCode: string
|
||||
}
|
||||
|
||||
export interface RegisterRequest {
|
||||
account: string
|
||||
password: string
|
||||
@@ -44,6 +49,10 @@ export const authApi = {
|
||||
return api.post<LoginResponse>('/user/login', data)
|
||||
},
|
||||
|
||||
phoneLogin: (data: PhoneLoginRequest) => {
|
||||
return api.post<LoginResponse>('/user/phone-login', data)
|
||||
},
|
||||
|
||||
adminLogin: (data: LoginRequest) => {
|
||||
return api.post<LoginResponse>('/admin/auth/login', data)
|
||||
},
|
||||
|
||||
@@ -131,6 +131,8 @@ api.interceptors.response.use(
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/user/send-verification-code') ||
|
||||
url?.includes('/user/phone-login') ||
|
||||
url?.includes('/shop/list/simple') ||
|
||||
url?.includes('/admin/login')
|
||||
}
|
||||
|
||||
@@ -48,6 +48,21 @@ export interface UpdateUserRequest {
|
||||
shopId?: number
|
||||
}
|
||||
|
||||
export interface UpdatePasswordRequest {
|
||||
password: string
|
||||
}
|
||||
|
||||
export interface BindPhoneRequest {
|
||||
phone: string
|
||||
verificationCode: string
|
||||
}
|
||||
|
||||
export interface UpdatePhoneRequest {
|
||||
oldPhone: string
|
||||
newPhone: string
|
||||
verificationCode: string
|
||||
}
|
||||
|
||||
export const userApi = {
|
||||
getUserInfo: () => {
|
||||
return api.get<UserVO>('/user/info')
|
||||
@@ -55,10 +70,22 @@ export const userApi = {
|
||||
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
||||
return api.put('/user/info', data)
|
||||
},
|
||||
updatePassword: (data: UpdatePasswordRequest) => {
|
||||
return api.put('/user/password', data)
|
||||
},
|
||||
bindPhone: (data: BindPhoneRequest) => {
|
||||
return api.post('/user/bind-phone', data)
|
||||
},
|
||||
updatePhone: (data: UpdatePhoneRequest) => {
|
||||
return api.put('/user/phone', data)
|
||||
},
|
||||
getUserByAccount: (account: string) => {
|
||||
return api.get<UserVO>(`/user/get/account/${account}`)
|
||||
},
|
||||
listUsersByType: (type: number) => {
|
||||
return api.get<UserVO[]>(`/user/list/type/${type}`)
|
||||
},
|
||||
sendVerificationCode: (data: { phone: string }) => {
|
||||
return api.post('/user/send-verification-code', data)
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -49,6 +49,7 @@ declare module 'vue' {
|
||||
APageHeader: typeof import('ant-design-vue/es')['PageHeader']
|
||||
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
|
||||
ARadio: typeof import('ant-design-vue/es')['Radio']
|
||||
ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
|
||||
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
|
||||
ARow: typeof import('ant-design-vue/es')['Row']
|
||||
ASegmented: typeof import('ant-design-vue/es')['Segmented']
|
||||
|
||||
@@ -63,6 +63,18 @@ const router = createRouter({
|
||||
component: () => import('../views/SettingsView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/settings/account',
|
||||
name: 'account-settings',
|
||||
component: () => import('../views/AccountSettingsView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/settings/password',
|
||||
name: 'password-settings',
|
||||
component: () => import('../views/PasswordSettingsView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/coupons',
|
||||
name: 'coupons',
|
||||
|
||||
@@ -0,0 +1,565 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>账号设置</h1>
|
||||
<div class="empty"></div>
|
||||
</header>
|
||||
|
||||
<!-- 账号设置内容 -->
|
||||
<div class="account-settings">
|
||||
<!-- 状态提示 -->
|
||||
<div v-if="!hasPassword || !hasPhone" class="status-tips">
|
||||
<a-alert
|
||||
v-if="!hasPassword"
|
||||
type="warning"
|
||||
message="请设置密码"
|
||||
description="为了账户安全,建议您设置一个安全的密码"
|
||||
show-icon
|
||||
:closable="false"
|
||||
>
|
||||
<template #action>
|
||||
<a-button size="small" type="primary" @click="handleSetPassword">去设置</a-button>
|
||||
</template>
|
||||
</a-alert>
|
||||
<a-alert
|
||||
v-if="!hasPhone"
|
||||
type="warning"
|
||||
message="请绑定手机号"
|
||||
description="绑定手机号可以提高账户安全性"
|
||||
show-icon
|
||||
:closable="false"
|
||||
>
|
||||
<template #action>
|
||||
<a-button size="small" type="primary" @click="handleBindPhone">去绑定</a-button>
|
||||
</template>
|
||||
</a-alert>
|
||||
</div>
|
||||
|
||||
<!-- 账号设置选项 -->
|
||||
<a-card :bordered="false" class="settings-card" v-if="hasPassword && hasPhone">
|
||||
<a-list :data-source="accountSettings" :split="false">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item class="setting-item" @click="handleSettingClick(item.key)">
|
||||
<template #actions>
|
||||
<RightOutlined />
|
||||
</template>
|
||||
<a-list-item-meta>
|
||||
<template #avatar>
|
||||
<div class="setting-icon" :style="{ backgroundColor: item.bgColor }">
|
||||
<component :is="item.icon" />
|
||||
</div>
|
||||
</template>
|
||||
<template #title>
|
||||
<span>{{ item.title }}</span>
|
||||
</template>
|
||||
<template #description v-if="item.desc">
|
||||
<span>{{ item.desc }}</span>
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</div>
|
||||
|
||||
<!-- 绑定手机号弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="bindPhoneModalVisible"
|
||||
title="绑定手机号"
|
||||
@ok="handleBindPhoneSubmit"
|
||||
@cancel="handleBindPhoneCancel"
|
||||
:confirmLoading="bindPhoneLoading"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="手机号" name="phone">
|
||||
<a-input
|
||||
v-model:value="bindPhoneForm.phone"
|
||||
placeholder="请输入手机号"
|
||||
:disabled="!!userInfo.phone"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="bindPhoneForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !bindPhoneForm.phone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 修改手机号弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="changePhoneModalVisible"
|
||||
title="修改手机号"
|
||||
@ok="handleChangePhoneSubmit"
|
||||
@cancel="handleChangePhoneCancel"
|
||||
:confirmLoading="changePhoneLoading"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="旧手机号">
|
||||
<a-input :value="userInfo.phone" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="新手机号" name="newPhone">
|
||||
<a-input
|
||||
v-model:value="changePhoneForm.newPhone"
|
||||
placeholder="请输入新手机号"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="changePhoneForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !changePhoneForm.newPhone"
|
||||
@click="handleSendChangePhoneVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 修改密码弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="changePasswordModalVisible"
|
||||
title="修改密码"
|
||||
@ok="handleChangePasswordSubmit"
|
||||
@cancel="handleChangePasswordCancel"
|
||||
:confirmLoading="changePasswordLoading"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-form-item label="手机号">
|
||||
<a-input :value="userInfo.phone" disabled />
|
||||
</a-form-item>
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="changePasswordForm.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0"
|
||||
@click="handleSendChangePasswordVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
<a-form-item label="新密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="changePasswordForm.password"
|
||||
placeholder="请输入新密码"
|
||||
/>
|
||||
<div class="password-tip">
|
||||
密码长度至少8位,包含字母和数字
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="确认密码" name="confirmPassword">
|
||||
<a-input-password
|
||||
v-model:value="changePasswordForm.confirmPassword"
|
||||
placeholder="请再次输入新密码"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined, RightOutlined, LockOutlined, PhoneOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { userApi } from '@/api/user'
|
||||
import type { UserVO } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 用户信息
|
||||
const userInfo = ref<UserVO>({
|
||||
id: 0,
|
||||
nickname: '',
|
||||
account: '',
|
||||
avatar: '',
|
||||
type: 0,
|
||||
status: 0,
|
||||
createTime: '',
|
||||
updateTime: ''
|
||||
})
|
||||
|
||||
// 状态标识
|
||||
const hasPassword = ref(false)
|
||||
const hasPhone = ref(false)
|
||||
|
||||
// 绑定手机号表单
|
||||
const bindPhoneModalVisible = ref(false)
|
||||
const bindPhoneLoading = ref(false)
|
||||
const bindPhoneForm = reactive({
|
||||
phone: '',
|
||||
verificationCode: ''
|
||||
})
|
||||
|
||||
// 修改手机号表单
|
||||
const changePhoneModalVisible = ref(false)
|
||||
const changePhoneLoading = ref(false)
|
||||
const changePhoneForm = reactive({
|
||||
newPhone: '',
|
||||
verificationCode: ''
|
||||
})
|
||||
|
||||
// 修改密码表单
|
||||
const changePasswordModalVisible = ref(false)
|
||||
const changePasswordLoading = ref(false)
|
||||
const changePasswordForm = reactive({
|
||||
verificationCode: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
// 倒计时
|
||||
const countdown = ref(0)
|
||||
|
||||
// 账号设置选项
|
||||
const accountSettings = ref([
|
||||
{
|
||||
key: 'changePhone',
|
||||
title: '修改手机号',
|
||||
icon: PhoneOutlined,
|
||||
bgColor: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
key: 'changePassword',
|
||||
title: '修改密码',
|
||||
icon: LockOutlined,
|
||||
bgColor: '#f6ffed'
|
||||
}
|
||||
])
|
||||
|
||||
// 获取用户信息
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const response = await userApi.getUserInfo() as any
|
||||
userInfo.value = response
|
||||
// 检查是否绑定手机号
|
||||
hasPhone.value = !!userInfo.value.phone
|
||||
// 检查是否设置密码(通过localStorage中的标识)
|
||||
hasPassword.value = localStorage.getItem('needSetPassword') !== 'true'
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
message.error('获取用户信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 处理返回
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 处理设置项点击
|
||||
const handleSettingClick = (key: string) => {
|
||||
switch (key) {
|
||||
case 'changePhone':
|
||||
changePhoneModalVisible.value = true
|
||||
break
|
||||
case 'changePassword':
|
||||
changePasswordModalVisible.value = true
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 处理设置密码
|
||||
const handleSetPassword = () => {
|
||||
router.push('/settings/password')
|
||||
}
|
||||
|
||||
// 处理绑定手机号
|
||||
const handleBindPhone = () => {
|
||||
bindPhoneModalVisible.value = true
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
const handleSendVerificationCode = async () => {
|
||||
if (!bindPhoneForm.phone) {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await userApi.sendVerificationCode({ phone: bindPhoneForm.phone })
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送修改手机号验证码
|
||||
const handleSendChangePhoneVerificationCode = async () => {
|
||||
if (!changePhoneForm.newPhone) {
|
||||
message.error('请输入新手机号')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await userApi.sendVerificationCode({ phone: changePhoneForm.newPhone })
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 发送修改密码验证码
|
||||
const handleSendChangePasswordVerificationCode = async () => {
|
||||
if (!userInfo.value.phone) {
|
||||
message.error('请先绑定手机号')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await userApi.sendVerificationCode({ phone: userInfo.value.phone })
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error('发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 开始倒计时
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
// 处理绑定手机号提交
|
||||
const handleBindPhoneSubmit = async () => {
|
||||
if (!bindPhoneForm.phone || !bindPhoneForm.verificationCode) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
bindPhoneLoading.value = true
|
||||
try {
|
||||
await userApi.bindPhone({
|
||||
phone: bindPhoneForm.phone,
|
||||
verificationCode: bindPhoneForm.verificationCode
|
||||
})
|
||||
message.success('手机号绑定成功')
|
||||
bindPhoneModalVisible.value = false
|
||||
await fetchUserInfo()
|
||||
} catch (error: any) {
|
||||
console.error('绑定手机号失败:', error)
|
||||
message.error(error.message || '绑定手机号失败')
|
||||
} finally {
|
||||
bindPhoneLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理绑定手机号取消
|
||||
const handleBindPhoneCancel = () => {
|
||||
bindPhoneModalVisible.value = false
|
||||
bindPhoneForm.phone = ''
|
||||
bindPhoneForm.verificationCode = ''
|
||||
}
|
||||
|
||||
// 处理修改手机号提交
|
||||
const handleChangePhoneSubmit = async () => {
|
||||
if (!changePhoneForm.newPhone || !changePhoneForm.verificationCode) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
changePhoneLoading.value = true
|
||||
try {
|
||||
await userApi.updatePhone({
|
||||
oldPhone: userInfo.value.phone!,
|
||||
newPhone: changePhoneForm.newPhone,
|
||||
verificationCode: changePhoneForm.verificationCode
|
||||
})
|
||||
message.success('手机号修改成功')
|
||||
changePhoneModalVisible.value = false
|
||||
await fetchUserInfo()
|
||||
} catch (error: any) {
|
||||
console.error('修改手机号失败:', error)
|
||||
message.error(error.message || '修改手机号失败')
|
||||
} finally {
|
||||
changePhoneLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理修改手机号取消
|
||||
const handleChangePhoneCancel = () => {
|
||||
changePhoneModalVisible.value = false
|
||||
changePhoneForm.newPhone = ''
|
||||
changePhoneForm.verificationCode = ''
|
||||
}
|
||||
|
||||
// 处理修改密码提交
|
||||
const handleChangePasswordSubmit = async () => {
|
||||
if (!changePasswordForm.verificationCode || !changePasswordForm.password || !changePasswordForm.confirmPassword) {
|
||||
message.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
|
||||
if (changePasswordForm.password !== changePasswordForm.confirmPassword) {
|
||||
message.error('两次输入的密码不一致')
|
||||
return
|
||||
}
|
||||
|
||||
changePasswordLoading.value = true
|
||||
try {
|
||||
await userApi.updatePassword({ password: changePasswordForm.password })
|
||||
message.success('密码修改成功')
|
||||
changePasswordModalVisible.value = false
|
||||
// 清除需要设置密码的标识
|
||||
localStorage.removeItem('needSetPassword')
|
||||
hasPassword.value = true
|
||||
} catch (error: any) {
|
||||
console.error('修改密码失败:', error)
|
||||
message.error(error.message || '修改密码失败')
|
||||
} finally {
|
||||
changePasswordLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理修改密码取消
|
||||
const handleChangePasswordCancel = () => {
|
||||
changePasswordModalVisible.value = false
|
||||
changePasswordForm.verificationCode = ''
|
||||
changePasswordForm.password = ''
|
||||
changePasswordForm.confirmPassword = ''
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: white;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.empty {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.account-settings {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.status-tips {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.settings-card :deep(.ant-card-body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.setting-item:hover {
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.setting-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-action) {
|
||||
margin-left: 8px;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.setting-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-title) {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.setting-item :deep(.ant-list-item-meta-description) {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -23,6 +23,13 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="activeTab === 'login'" class="login-type-toggle">
|
||||
<a-radio-group v-model:value="loginType" button-style="solid">
|
||||
<a-radio-button value="password">账号密码登录</a-radio-button>
|
||||
<a-radio-button value="phone">手机验证码登录</a-radio-button>
|
||||
</a-radio-group>
|
||||
</div>
|
||||
|
||||
<a-form
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
@@ -42,7 +49,7 @@
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="account" label="账号">
|
||||
<a-form-item name="account" label="账号" v-if="activeTab === 'login' && loginType === 'password'">
|
||||
<a-input
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
@@ -63,7 +70,40 @@
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="password" label="密码">
|
||||
<a-form-item name="phone" label="手机号" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||
<a-input
|
||||
v-model:value="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="verificationCode" label="验证码" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||
<a-input
|
||||
v-model:value="formData.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !formData.phone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="password" label="密码" v-if="activeTab === 'login' && loginType === 'password' || activeTab === 'register'">
|
||||
<a-input-password
|
||||
v-model:value="formData.password"
|
||||
placeholder="请输入密码"
|
||||
@@ -164,10 +204,12 @@ import { userApi } from '@/api/user'
|
||||
const router = useRouter()
|
||||
|
||||
const activeTab = ref<'login' | 'register'>('login')
|
||||
const loginType = ref<'password' | 'phone'>('password')
|
||||
const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const shops = ref<any[]>([])
|
||||
const accountStatus = ref<any>(null)
|
||||
const countdown = ref(0)
|
||||
|
||||
const formData = reactive({
|
||||
account: '',
|
||||
@@ -175,6 +217,8 @@ const formData = reactive({
|
||||
confirmPassword: '',
|
||||
nickname: '',
|
||||
shopId: undefined as number | undefined,
|
||||
phone: '',
|
||||
verificationCode: '',
|
||||
rememberMe: false
|
||||
})
|
||||
|
||||
@@ -201,6 +245,14 @@ const rules = {
|
||||
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' },
|
||||
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||
],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
{ validator: validatePassword, trigger: 'blur' }
|
||||
@@ -236,11 +288,20 @@ const handleSubmit = async () => {
|
||||
try {
|
||||
if (activeTab.value === 'login') {
|
||||
console.log('开始登录...')
|
||||
const response = await authApi.login({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
rememberMe: formData.rememberMe
|
||||
})
|
||||
let response
|
||||
|
||||
if (loginType.value === 'phone') {
|
||||
response = await authApi.phoneLogin({
|
||||
phone: formData.phone,
|
||||
verificationCode: formData.verificationCode
|
||||
})
|
||||
} else {
|
||||
response = await authApi.login({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
rememberMe: formData.rememberMe
|
||||
})
|
||||
}
|
||||
|
||||
console.log('登录响应:', response)
|
||||
|
||||
@@ -251,6 +312,12 @@ const handleSubmit = async () => {
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
// 存储是否需要设置密码的标识
|
||||
if (loginData.needSetPassword) {
|
||||
localStorage.setItem('needSetPassword', 'true')
|
||||
} else {
|
||||
localStorage.removeItem('needSetPassword')
|
||||
}
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
|
||||
console.log('Token存储成功')
|
||||
@@ -317,6 +384,27 @@ const handleAccountBlur = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleSendVerificationCode = async () => {
|
||||
if (!formData.phone) {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await userApi.sendVerificationCode({ phone: formData.phone })
|
||||
message.success('验证码已发送')
|
||||
countdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleAdminLogin = () => {
|
||||
console.log('跳转到管理后台登录')
|
||||
localStorage.removeItem('accessToken')
|
||||
@@ -406,6 +494,11 @@ onMounted(() => {
|
||||
background: #667eea;
|
||||
}
|
||||
|
||||
.login-type-toggle {
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>设置密码</h1>
|
||||
<div class="empty"></div>
|
||||
</header>
|
||||
|
||||
<!-- 密码设置表单 -->
|
||||
<div class="password-form">
|
||||
<a-card :bordered="false" class="form-card">
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="formState"
|
||||
:rules="formRules"
|
||||
layout="vertical"
|
||||
@finish="handleSubmit"
|
||||
>
|
||||
<a-form-item label="新密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="formState.password"
|
||||
placeholder="请输入新密码"
|
||||
size="large"
|
||||
@pressEnter="handleSubmit"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
<div class="password-tip">
|
||||
密码长度至少8位,包含字母和数字
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="确认密码" name="confirmPassword">
|
||||
<a-input-password
|
||||
v-model:value="formState.confirmPassword"
|
||||
placeholder="请再次输入新密码"
|
||||
size="large"
|
||||
@pressEnter="handleSubmit"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="loading"
|
||||
>
|
||||
确认设置
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { userApi } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
|
||||
const formState = reactive({
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
password: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{ min: 8, message: '密码长度至少8位', trigger: 'blur' },
|
||||
{ pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/, message: '密码必须包含字母和数字', trigger: 'blur' }
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: '请确认新密码', trigger: 'blur' },
|
||||
{ validator: validateConfirmPassword, trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const validateConfirmPassword = (_, value: string) => {
|
||||
if (value !== formState.password) {
|
||||
return Promise.reject(new Error('两次输入的密码不一致'))
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
loading.value = true
|
||||
|
||||
await userApi.updatePassword({
|
||||
password: formState.password
|
||||
})
|
||||
|
||||
message.success('密码设置成功')
|
||||
// 清除需要设置密码的标识
|
||||
localStorage.removeItem('needSetPassword')
|
||||
// 跳转回个人中心
|
||||
router.push('/profile')
|
||||
} catch (error: any) {
|
||||
console.error('设置密码失败:', error)
|
||||
message.error(error.message || '设置密码失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
background: white;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.empty {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.password-form {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.form-card :deep(.ant-card-body) {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.form-card :deep(.ant-btn-primary) {
|
||||
height: 48px;
|
||||
border-radius: 12px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border: none;
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
</style>
|
||||
@@ -33,6 +33,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 密码设置提示 -->
|
||||
<div v-if="needSetPassword" class="password-tip">
|
||||
<a-alert
|
||||
type="warning"
|
||||
message="请尽快设置密码"
|
||||
description="为了账户安全,建议您设置一个安全的密码"
|
||||
show-icon
|
||||
:closable="false"
|
||||
>
|
||||
<template #action>
|
||||
<a-button size="small" type="primary" @click="handleSetPassword">去设置</a-button>
|
||||
</template>
|
||||
</a-alert>
|
||||
</div>
|
||||
<a-button type="primary" block @click="handleEditProfile" class="edit-btn">
|
||||
编辑资料
|
||||
</a-button>
|
||||
@@ -217,6 +231,7 @@ const userInfo = ref<UserVO>({
|
||||
})
|
||||
|
||||
const hasNotification = ref(true)
|
||||
const needSetPassword = ref(false)
|
||||
|
||||
const editModalVisible = ref(false)
|
||||
const saving = ref(false)
|
||||
@@ -282,6 +297,8 @@ const fetchUserInfo = async () => {
|
||||
console.log('获取到的用户信息:', response)
|
||||
userInfo.value = response
|
||||
console.log('设置后的 userInfo:', userInfo.value)
|
||||
// 检查是否需要设置密码
|
||||
needSetPassword.value = localStorage.getItem('needSetPassword') === 'true'
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
message.error('获取用户信息失败')
|
||||
@@ -438,6 +455,8 @@ const handleLogout = () => {
|
||||
} finally {
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('userInfo')
|
||||
localStorage.removeItem('needSetPassword')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
message.success('已退出登录')
|
||||
router.push('/')
|
||||
@@ -451,6 +470,11 @@ const handleSettingsClick = () => {
|
||||
router.push('/settings')
|
||||
}
|
||||
|
||||
const handleSetPassword = () => {
|
||||
console.log('去设置密码')
|
||||
router.push('/settings/password')
|
||||
}
|
||||
|
||||
const handleShopClick = () => {
|
||||
console.log('店铺信息被点击')
|
||||
if (userInfo.value.shopId) {
|
||||
|
||||
@@ -157,7 +157,7 @@ const handleSettingClick = (key: string) => {
|
||||
|
||||
switch (key) {
|
||||
case 'account':
|
||||
message.info('账号设置功能开发中...')
|
||||
router.push('/settings/account')
|
||||
break
|
||||
case 'notifications':
|
||||
message.info('消息通知功能开发中...')
|
||||
|
||||
Reference in New Issue
Block a user