修复一些问题,个人账号功能完善,注册功能完善,收藏,购物车功能完善,初版基本完成,投入测试

This commit is contained in:
xiaowang
2026-03-03 17:50:10 +08:00
parent b301e37468
commit b0470b8f86
23 changed files with 804 additions and 129 deletions
+171 -8
View File
@@ -49,6 +49,51 @@
</a-input>
</a-form-item>
<a-form-item v-if="activeTab === 'register'" name="account" label="账号">
<a-input
v-model:value="formData.account"
placeholder="请输入账号"
size="large"
>
<template #prefix>
<UserOutlined style="color: #999" />
</template>
</a-input>
</a-form-item>
<a-form-item v-if="activeTab === 'register'" name="phone" label="手机号">
<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 v-if="activeTab === 'register'" name="verificationCode" label="验证码">
<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="account" label="账号" v-if="activeTab === 'login' && loginType === 'password'">
<a-input
v-model:value="formData.account"
@@ -62,7 +107,7 @@
</a-input>
<div v-if="accountStatus" class="account-status">
<span v-if="accountStatus.exists" class="status-success">
账号存在,昵称:{{ accountStatus.nickname }}
账号存在,昵称:{{ accountStatus.nickname }} {{ accountStatus.hasShop ? ',已绑定店铺' : ',请选择店铺' }}
</span>
<span v-else class="status-error">
账号不存在
@@ -75,11 +120,24 @@
v-model:value="formData.phone"
placeholder="请输入手机号"
size="large"
@blur="handlePhoneBlur"
>
<template #prefix>
<UserOutlined style="color: #999" />
</template>
</a-input>
<div class="phone-login-tip">
<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'">
@@ -103,6 +161,34 @@
</a-input>
</a-form-item>
<a-form-item
v-if="activeTab === 'login' && loginType === 'phone' && (phoneUserStatus && !phoneUserStatus.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 name="password" label="密码" v-if="activeTab === 'login' && loginType === 'password' || activeTab === 'register'">
<a-input-password
v-model:value="formData.password"
@@ -115,6 +201,34 @@
</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"
@@ -195,7 +309,7 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { UserOutlined, LockOutlined, WechatOutlined, QqOutlined } from '@ant-design/icons-vue'
import { UserOutlined, LockOutlined, WechatOutlined, QqOutlined, InfoCircleOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { authApi } from '@/api/auth'
import { shopApi } from '@/api/shop'
@@ -209,6 +323,7 @@ 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 formData = reactive({
@@ -291,15 +406,27 @@ 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
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,
rememberMe: formData.rememberMe
rememberMe: formData.rememberMe,
shopId: formData.shopId
})
}
@@ -312,7 +439,6 @@ 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 {
@@ -336,6 +462,8 @@ const handleSubmit = async () => {
account: formData.account,
password: formData.password,
nickname: formData.nickname,
phone: formData.phone,
verificationCode: formData.verificationCode,
shopId: formData.shopId!
})
@@ -369,16 +497,43 @@ const handleAccountBlur = async () => {
if (res) {
accountStatus.value = {
exists: true,
nickname: res.nickname
nickname: res.nickname,
hasShop: res.shopId && res.shopId > 0
}
} else {
accountStatus.value = {
exists: false
exists: false,
hasShop: false
}
}
} catch (error) {
accountStatus.value = {
exists: false
exists: false,
hasShop: false
}
}
}
}
const handlePhoneBlur = async () => {
if (activeTab.value === 'login' && loginType.value === 'phone' && formData.phone) {
try {
const res = await userApi.getUserByAccount(formData.phone)
if (res) {
phoneUserStatus.value = {
exists: true,
hasShop: res.shopId && res.shopId > 0
}
} else {
phoneUserStatus.value = {
exists: false,
hasShop: false
}
}
} catch (error) {
phoneUserStatus.value = {
exists: false,
hasShop: false
}
}
}
@@ -588,4 +743,12 @@ onMounted(() => {
.status-error {
color: #f5222d;
}
.phone-login-tip {
margin-top: 8px;
font-size: 12px;
color: #1890ff;
display: flex;
align-items: center;
}
</style>