杂务:打包并提交当前改动
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import axios, { AxiosError } from 'axios'
|
||||
import { authApi } from './auth'
|
||||
import { adminAuthApi } from './admin'
|
||||
import { wishlistApi } from './wishlist'
|
||||
import router from '../router'
|
||||
import { message } from 'ant-design-vue'
|
||||
@@ -136,7 +137,8 @@ api.interceptors.response.use(
|
||||
url?.includes('/user/send-verification-code') ||
|
||||
url?.includes('/user/phone-login') ||
|
||||
url?.includes('/shop/list/simple') ||
|
||||
url?.includes('/admin/login')
|
||||
url?.includes('/admin/auth/login') ||
|
||||
url?.includes('/admin/auth/refresh')
|
||||
}
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
@@ -174,7 +176,9 @@ api.interceptors.response.use(
|
||||
|
||||
// 这里需要根据是否是后台请求调用不同的refreshToken API
|
||||
// 暂时使用同一个API,实际项目中可能需要分开
|
||||
const response = await authApi.refreshToken({ refreshToken })
|
||||
const response = isAdminRequest
|
||||
? await adminAuthApi.refreshToken(refreshToken)
|
||||
: await authApi.refreshToken({ refreshToken })
|
||||
const newToken = (response as any).accessToken
|
||||
const newRefreshToken = (response as any).refreshToken
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ export interface UpdateUserInfoRequest {
|
||||
nickname?: string
|
||||
avatar?: string
|
||||
signature?: string
|
||||
phone?: string
|
||||
}
|
||||
|
||||
export interface ListUsersParams {
|
||||
@@ -52,6 +51,7 @@ export interface UpdateUserRequest {
|
||||
|
||||
export interface UpdatePasswordRequest {
|
||||
password: string
|
||||
verificationCode: string
|
||||
}
|
||||
|
||||
export interface BindPhoneRequest {
|
||||
@@ -59,6 +59,11 @@ export interface BindPhoneRequest {
|
||||
verificationCode: string
|
||||
}
|
||||
|
||||
export interface AvailabilityCheckResponse {
|
||||
available: boolean
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface UpdatePhoneRequest {
|
||||
oldPhone: string
|
||||
newPhone: string
|
||||
@@ -70,7 +75,7 @@ export const userApi = {
|
||||
return api.get<UserVO>('/user/info')
|
||||
},
|
||||
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
||||
return api.put('/user/info', data)
|
||||
return api.put('/user/update', data)
|
||||
},
|
||||
updatePassword: (data: UpdatePasswordRequest) => {
|
||||
return api.put('/user/password', data)
|
||||
@@ -84,6 +89,12 @@ export const userApi = {
|
||||
getUserByAccount: (account: string) => {
|
||||
return api.get<UserVO>(`/user/get/account/${account}`)
|
||||
},
|
||||
checkAccountAvailability: (account: string) => {
|
||||
return api.get<AvailabilityCheckResponse>(`/user/check/account/${encodeURIComponent(account)}`)
|
||||
},
|
||||
checkPhoneAvailability: (phone: string) => {
|
||||
return api.get<AvailabilityCheckResponse>(`/user/check/phone/${encodeURIComponent(phone)}`)
|
||||
},
|
||||
listUsersByType: (type: number) => {
|
||||
return api.get<UserVO[]>(`/user/list/type/${type}`)
|
||||
},
|
||||
|
||||
Vendored
+1
@@ -49,6 +49,7 @@ declare module 'vue' {
|
||||
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||
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']
|
||||
|
||||
@@ -61,7 +61,7 @@ const router = createRouter({
|
||||
path: '/artist-orders',
|
||||
name: 'artist-orders',
|
||||
component: () => import('../views/ArtistOrderView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false, permissionCode: 'order:artist:view' }
|
||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false, permissionCode: 'order:view' }
|
||||
},
|
||||
{
|
||||
path: '/settings',
|
||||
@@ -283,4 +283,4 @@ router.beforeEach((to, _from, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
export default router
|
||||
|
||||
@@ -490,7 +490,10 @@ const handleChangePasswordSubmit = async () => {
|
||||
|
||||
changePasswordLoading.value = true
|
||||
try {
|
||||
await userApi.updatePassword({ password: changePasswordForm.password })
|
||||
await userApi.updatePassword({
|
||||
password: changePasswordForm.password,
|
||||
verificationCode: changePasswordForm.verificationCode
|
||||
})
|
||||
message.success('密码修改成功')
|
||||
changePasswordModalVisible.value = false
|
||||
// 清除需要设置密码的标识
|
||||
@@ -522,17 +525,6 @@ const handleDeactivateAccount = async () => {
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
try {
|
||||
// 在删除前先重命名账号和手机号,添加删除时间戳
|
||||
const timestamp = new Date().getTime()
|
||||
const newPhone = `${userInfo.value.phone}_deleted_${timestamp}`
|
||||
|
||||
try {
|
||||
await userApi.updateUserInfo({ phone: newPhone })
|
||||
} catch (renameError) {
|
||||
console.error('重命名手机号失败:', renameError)
|
||||
// 重命名失败也继续删除流程
|
||||
}
|
||||
|
||||
await userApi.deactivateAccount()
|
||||
message.success('账号注销成功')
|
||||
} catch (error) {
|
||||
@@ -658,4 +650,4 @@ onMounted(() => {
|
||||
color: #999;
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
+115
-129
@@ -54,11 +54,19 @@
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
size="large"
|
||||
@blur="handleRegisterAccountBlur"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
<div
|
||||
v-if="registerAccountStatus"
|
||||
class="field-status"
|
||||
:class="registerAccountStatus.available ? 'success' : 'error'"
|
||||
>
|
||||
{{ registerAccountStatus.message }}
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'register'" name="phone" label="手机号">
|
||||
@@ -66,11 +74,19 @@
|
||||
v-model:value="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
size="large"
|
||||
@blur="handleRegisterPhoneBlur"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
<div
|
||||
v-if="registerPhoneStatus"
|
||||
class="field-status"
|
||||
:class="registerPhoneStatus.available ? 'success' : 'error'"
|
||||
>
|
||||
{{ registerPhoneStatus.message }}
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'register'" name="verificationCode" label="验证码">
|
||||
@@ -99,20 +115,11 @@
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
size="large"
|
||||
@blur="handleAccountBlur"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
<div v-if="accountStatus" class="account-status">
|
||||
<span v-if="accountStatus.exists" class="status-success">
|
||||
账号存在,昵称:{{ accountStatus.nickname }} {{ accountStatus.hasShop ? ',已绑定店铺' : ',请选择店铺' }}
|
||||
</span>
|
||||
<span v-else class="status-error">
|
||||
账号不存在
|
||||
</span>
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="phone" label="手机号" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||
@@ -120,7 +127,6 @@
|
||||
v-model:value="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
size="large"
|
||||
@blur="handlePhoneBlur"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
@@ -130,14 +136,6 @@
|
||||
<InfoCircleOutlined style="color: #1890ff; margin-right: 4px;" />
|
||||
<span>新用户将自动注册</span>
|
||||
</div>
|
||||
<div v-if="phoneUserStatus" class="account-status">
|
||||
<span v-if="phoneUserStatus.exists" class="status-success">
|
||||
{{ phoneUserStatus.hasShop ? '账号已存在,已绑定店铺' : '账号已存在,请选择店铺' }}
|
||||
</span>
|
||||
<span v-else class="status-error">
|
||||
新用户,请选择店铺
|
||||
</span>
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="verificationCode" label="验证码" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||
@@ -161,27 +159,27 @@
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login' && loginType === 'phone' && (phoneUserStatus && !phoneUserStatus.hasShop)"
|
||||
name="shopId"
|
||||
label="选择店铺"
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login'"
|
||||
label="选择店铺(可选)"
|
||||
>
|
||||
<a-select
|
||||
v-model:value="formData.shopId"
|
||||
placeholder="请选择店铺"
|
||||
placeholder="如需绑定店铺或首次手机号登录,请选择店铺"
|
||||
size="large"
|
||||
:loading="loadingShops"
|
||||
allow-clear
|
||||
>
|
||||
<a-select-option
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
disabled
|
||||
value=""
|
||||
>
|
||||
暂无店铺数据
|
||||
</a-select-option>
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
@@ -201,34 +199,6 @@
|
||||
</a-input-password>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login' && loginType === 'password' && (accountStatus && accountStatus.exists && !accountStatus.hasShop)"
|
||||
name="shopId"
|
||||
label="选择店铺"
|
||||
>
|
||||
<a-select
|
||||
v-model:value="formData.shopId"
|
||||
placeholder="请选择店铺"
|
||||
size="large"
|
||||
:loading="loadingShops"
|
||||
>
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
disabled
|
||||
value=""
|
||||
>
|
||||
暂无店铺数据
|
||||
</a-select-option>
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'register'" name="confirmPassword" label="确认密码">
|
||||
<a-input-password
|
||||
v-model:value="formData.confirmPassword"
|
||||
@@ -393,7 +363,7 @@ import { message } from 'ant-design-vue'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { shopApi } from '@/api/shop'
|
||||
import { userApi } from '@/api/user'
|
||||
import { userApi, type AvailabilityCheckResponse } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
@@ -402,9 +372,9 @@ const loginType = ref<'password' | 'phone'>('password')
|
||||
const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const shops = ref<any[]>([])
|
||||
const accountStatus = ref<any>(null)
|
||||
const phoneUserStatus = ref<any>(null)
|
||||
const countdown = ref(0)
|
||||
const registerAccountStatus = ref<AvailabilityCheckResponse | null>(null)
|
||||
const registerPhoneStatus = ref<AvailabilityCheckResponse | null>(null)
|
||||
|
||||
const forgotPasswordVisible = ref(false)
|
||||
const forgotCountdown = ref(0)
|
||||
@@ -503,7 +473,7 @@ const fetchShops = async () => {
|
||||
shops.value = (response as unknown as any[]) || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
message.error('未登录,请先登录')
|
||||
message.warning('店铺列表加载失败,普通登录不受影响')
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
@@ -516,22 +486,12 @@ const handleSubmit = async () => {
|
||||
let response
|
||||
|
||||
if (loginType.value === 'phone') {
|
||||
if (phoneUserStatus.value && !phoneUserStatus.value.hasShop && !formData.shopId) {
|
||||
message.error('请选择店铺')
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
response = await authApi.phoneLogin({
|
||||
phone: formData.phone,
|
||||
verificationCode: formData.verificationCode,
|
||||
shopId: formData.shopId
|
||||
})
|
||||
} else {
|
||||
if (accountStatus.value && accountStatus.value.exists && !accountStatus.value.hasShop && !formData.shopId) {
|
||||
message.error('请选择店铺')
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
response = await authApi.login({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
@@ -563,6 +523,13 @@ const handleSubmit = async () => {
|
||||
message.error('登录失败:响应数据异常')
|
||||
}
|
||||
} else {
|
||||
const accountAvailable = await checkRegisterAccountAvailability(false)
|
||||
const phoneAvailable = await checkRegisterPhoneAvailability(false)
|
||||
if (!accountAvailable || !phoneAvailable) {
|
||||
message.error('请先处理注册信息中的占用问题')
|
||||
return
|
||||
}
|
||||
|
||||
await authApi.register({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
@@ -643,54 +610,65 @@ const handleQQLogin = () => {
|
||||
message.info('QQ登录功能开发中')
|
||||
}
|
||||
|
||||
const handleAccountBlur = async () => {
|
||||
if (activeTab.value === 'login' && formData.account) {
|
||||
try {
|
||||
const res = await userApi.getUserByAccount(formData.account)
|
||||
const userData = res as any
|
||||
if (userData) {
|
||||
accountStatus.value = {
|
||||
exists: true,
|
||||
nickname: userData.nickname,
|
||||
hasShop: userData.shopId && userData.shopId > 0
|
||||
}
|
||||
} else {
|
||||
accountStatus.value = {
|
||||
exists: false,
|
||||
hasShop: false
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
accountStatus.value = {
|
||||
exists: false,
|
||||
hasShop: false
|
||||
}
|
||||
}
|
||||
const checkRegisterAccountAvailability = async (showSuccessMessage = true) => {
|
||||
if (activeTab.value !== 'register' || !formData.account.trim()) {
|
||||
registerAccountStatus.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await userApi.checkAccountAvailability(formData.account.trim()) as unknown as AvailabilityCheckResponse
|
||||
registerAccountStatus.value = response
|
||||
if (showSuccessMessage && !response.available) {
|
||||
message.warning(response.message)
|
||||
}
|
||||
return response.available
|
||||
}
|
||||
|
||||
const checkRegisterPhoneAvailability = async (showSuccessMessage = true) => {
|
||||
if (activeTab.value !== 'register' || !formData.phone.trim()) {
|
||||
registerPhoneStatus.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await userApi.checkPhoneAvailability(formData.phone.trim()) as unknown as AvailabilityCheckResponse
|
||||
registerPhoneStatus.value = response
|
||||
if (showSuccessMessage && !response.available) {
|
||||
message.warning(response.message)
|
||||
}
|
||||
return response.available
|
||||
}
|
||||
|
||||
const handleRegisterAccountBlur = async () => {
|
||||
if (activeTab.value !== 'register' || !formData.account.trim()) {
|
||||
registerAccountStatus.value = null
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await checkRegisterAccountAvailability(false)
|
||||
} catch (error: any) {
|
||||
registerAccountStatus.value = null
|
||||
message.error(error.message || '账号校验失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handlePhoneBlur = async () => {
|
||||
if (activeTab.value === 'login' && loginType.value === 'phone' && formData.phone) {
|
||||
try {
|
||||
const res = await userApi.getUserByAccount(formData.phone)
|
||||
const userData = res as any
|
||||
if (userData) {
|
||||
phoneUserStatus.value = {
|
||||
exists: true,
|
||||
hasShop: userData.shopId && userData.shopId > 0
|
||||
}
|
||||
} else {
|
||||
phoneUserStatus.value = {
|
||||
exists: false,
|
||||
hasShop: false
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
phoneUserStatus.value = {
|
||||
exists: false,
|
||||
hasShop: false
|
||||
}
|
||||
}
|
||||
const handleRegisterPhoneBlur = async () => {
|
||||
if (activeTab.value !== 'register' || !formData.phone.trim()) {
|
||||
registerPhoneStatus.value = null
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(formData.phone)) {
|
||||
registerPhoneStatus.value = null
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await checkRegisterPhoneAvailability(false)
|
||||
} catch (error: any) {
|
||||
registerPhoneStatus.value = null
|
||||
message.error(error.message || '手机号校验失败')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -705,8 +683,16 @@ const handleSendVerificationCode = async () => {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (activeTab.value === 'register') {
|
||||
const phoneAvailable = await checkRegisterPhoneAvailability(false)
|
||||
if (!phoneAvailable) {
|
||||
message.warning(registerPhoneStatus.value?.message || '该手机号已被注册')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
await userApi.sendVerificationCode({ phone: formData.phone })
|
||||
message.success('验证码已发送')
|
||||
countdown.value = 60
|
||||
@@ -824,6 +810,19 @@ onMounted(() => {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.field-status {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.field-status.success {
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.field-status.error {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.forgot-password {
|
||||
color: #667eea;
|
||||
cursor: pointer;
|
||||
@@ -891,19 +890,6 @@ onMounted(() => {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.account-status {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.status-error {
|
||||
color: #f5222d;
|
||||
}
|
||||
|
||||
.phone-login-tip {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
@@ -911,4 +897,4 @@ onMounted(() => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
@@ -9,7 +8,6 @@
|
||||
<div class="empty"></div>
|
||||
</header>
|
||||
|
||||
<!-- 密码设置表单 -->
|
||||
<div class="password-form">
|
||||
<a-card :bordered="false" class="form-card">
|
||||
<a-form
|
||||
@@ -19,6 +17,28 @@
|
||||
layout="vertical"
|
||||
@finish="handleSubmit"
|
||||
>
|
||||
<a-form-item label="手机号">
|
||||
<a-input :value="userPhone || '未绑定手机号'" disabled size="large" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="验证码" name="verificationCode">
|
||||
<a-input
|
||||
v-model:value="formState.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
size="large"
|
||||
>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !userPhone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}秒后重发` : '发送验证码' }}
|
||||
</a-button>
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="新密码" name="password">
|
||||
<a-input-password
|
||||
v-model:value="formState.password"
|
||||
@@ -31,7 +51,7 @@
|
||||
</template>
|
||||
</a-input-password>
|
||||
<div class="password-tip">
|
||||
密码长度至少8位,包含字母和数字
|
||||
密码长度至少 8 位,且需包含字母和数字
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
@@ -66,7 +86,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
@@ -77,12 +97,18 @@ import { userApi } from '@/api/user'
|
||||
const router = useRouter()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const countdown = ref(0)
|
||||
const userInfo = ref<{ phone?: string } | null>(null)
|
||||
let countdownTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const formState = reactive({
|
||||
verificationCode: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const userPhone = computed(() => userInfo.value?.phone || '')
|
||||
|
||||
const validateConfirmPassword = (_rule: any, value: string) => {
|
||||
if (value !== formState.password) {
|
||||
return Promise.reject(new Error('两次输入的密码不一致'))
|
||||
@@ -91,6 +117,10 @@ const validateConfirmPassword = (_rule: any, value: string) => {
|
||||
}
|
||||
|
||||
const formRules: Record<string, Rule[]> = {
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{ min: 8, message: '密码长度至少8位', trigger: 'blur' },
|
||||
@@ -102,21 +132,64 @@ const formRules: Record<string, Rule[]> = {
|
||||
]
|
||||
}
|
||||
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
}
|
||||
countdownTimer = setInterval(() => {
|
||||
countdown.value -= 1
|
||||
if (countdown.value <= 0 && countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
countdownTimer = null
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const res = await userApi.getUserInfo()
|
||||
userInfo.value = res as unknown as { phone?: string }
|
||||
} catch (error: any) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
message.error(error.message || '获取用户信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleSendVerificationCode = async () => {
|
||||
if (!userPhone.value) {
|
||||
message.error('请先绑定手机号')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await userApi.sendVerificationCode({ phone: userPhone.value })
|
||||
message.success('验证码发送成功')
|
||||
startCountdown()
|
||||
} catch (error: any) {
|
||||
console.error('发送验证码失败:', error)
|
||||
message.error(error.message || '发送验证码失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (!userPhone.value) {
|
||||
message.error('请先绑定手机号')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
|
||||
await userApi.updatePassword({
|
||||
password: formState.password
|
||||
password: formState.password,
|
||||
verificationCode: formState.verificationCode
|
||||
})
|
||||
|
||||
|
||||
message.success('密码设置成功')
|
||||
// 清除需要设置密码的标识
|
||||
localStorage.removeItem('needSetPassword')
|
||||
// 跳转回个人中心
|
||||
router.push('/profile')
|
||||
} catch (error: any) {
|
||||
console.error('设置密码失败:', error)
|
||||
@@ -129,6 +202,16 @@ const handleSubmit = async () => {
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -171,23 +254,9 @@ const handleBackClick = () => {
|
||||
background: white;
|
||||
}
|
||||
|
||||
.form-card :deep(.ant-card-body) {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.password-tip {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-top: 8px;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.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>
|
||||
</style>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, inject } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
LeftOutlined,
|
||||
@@ -169,6 +169,7 @@ import { tagApi, type TagVO } from '@/api/tag'
|
||||
import { cartApi } from '@/api/cart'
|
||||
import { fileApi } from '@/api/file'
|
||||
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
|
||||
const router = useRouter()
|
||||
@@ -298,6 +299,7 @@ const handleProductClick = (item: any) => {
|
||||
const handleAddToCart = async (item: any) => {
|
||||
try {
|
||||
await cartApi.addToCart({ productId: item.id, quantity: 1 })
|
||||
await updateCartCount()
|
||||
message.success(`已将 ${item.title || item.name || '作品'} 添加到购物车`)
|
||||
} catch (error) {
|
||||
message.error('添加到购物车失败,请重试')
|
||||
@@ -566,4 +568,4 @@ onMounted(async () => {
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, inject } from 'vue'
|
||||
import { ArrowLeft, Delete, StarFilled } from '@element-plus/icons-vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
@@ -55,6 +55,7 @@ import { cartApi } from '@/api/cart'
|
||||
import { fileApi } from '@/api/file'
|
||||
|
||||
const router = useRouter()
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
const wishlistItems = ref<WishlistItem[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
@@ -113,6 +114,7 @@ const getProductImages = (product: any): string[] => {
|
||||
const handleAddToCart = async (productId: number) => {
|
||||
try {
|
||||
await cartApi.addToCart({ productId, quantity: 1 })
|
||||
await updateCartCount()
|
||||
ElMessage.success('已添加到购物车')
|
||||
} catch (error) {
|
||||
console.error('添加到购物车失败:', error)
|
||||
@@ -257,4 +259,4 @@ onMounted(() => {
|
||||
margin: 20px 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user