标签功能初版实现
This commit is contained in:
@@ -0,0 +1,396 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<div class="auth-container">
|
||||
<div class="logo-section">
|
||||
<div class="logo">Yumi</div>
|
||||
<div class="subtitle">美甲服务平台</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-container">
|
||||
<div
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'login' }"
|
||||
@click="activeTab = 'login'"
|
||||
>
|
||||
登录
|
||||
</div>
|
||||
<div
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'register' }"
|
||||
@click="activeTab = 'register'"
|
||||
>
|
||||
注册
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a-form
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
@finish="handleSubmit"
|
||||
layout="vertical"
|
||||
class="auth-form"
|
||||
>
|
||||
<a-form-item 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 name="password" label="密码">
|
||||
<a-input-password
|
||||
v-model:value="formData.password"
|
||||
placeholder="请输入密码"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'register'" name="confirmPassword" label="确认密码">
|
||||
<a-input-password
|
||||
v-model:value="formData.confirmPassword"
|
||||
placeholder="请再次输入密码"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input-password>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'register'" 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="nickname" label="昵称">
|
||||
<a-input
|
||||
v-model:value="formData.nickname"
|
||||
placeholder="请输入昵称"
|
||||
size="large"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="activeTab === 'login'" style="margin-bottom: 8px">
|
||||
<div class="form-actions">
|
||||
<a-checkbox v-model:checked="formData.rememberMe">记住我</a-checkbox>
|
||||
<a class="forgot-password" @click="handleForgotPassword">忘记密码?</a>
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="loading"
|
||||
>
|
||||
{{ activeTab === 'login' ? '登录' : '注册' }}
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
|
||||
<div class="social-login">
|
||||
<div class="divider">
|
||||
<span>其他登录方式</span>
|
||||
</div>
|
||||
<div class="social-buttons">
|
||||
<a-button shape="circle" size="large" @click="handleWeChatLogin">
|
||||
<WechatOutlined />
|
||||
</a-button>
|
||||
<a-button shape="circle" size="large" @click="handleQQLogin">
|
||||
<QqOutlined />
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<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 { message } from 'ant-design-vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { shopApi } from '@/api/shop'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const activeTab = ref<'login' | 'register'>('login')
|
||||
const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const shops = ref<any[]>([])
|
||||
|
||||
const formData = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
nickname: '',
|
||||
shopId: undefined as number | undefined,
|
||||
rememberMe: false
|
||||
})
|
||||
|
||||
const validatePassword = async (_rule: any, value: string) => {
|
||||
if (value.length < 6) {
|
||||
return Promise.reject('密码长度不能少于6位')
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const validateConfirmPassword = async (_rule: any, value: string) => {
|
||||
if (!value) {
|
||||
return Promise.reject('请确认密码')
|
||||
}
|
||||
if (value !== formData.password) {
|
||||
return Promise.reject('两次输入的密码不一致')
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const rules = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
{ min: 3, max: 50, message: '账号长度在3到50个字符', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
{ validator: validatePassword, trigger: 'blur' }
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: '请确认密码', trigger: 'blur' },
|
||||
{ validator: validateConfirmPassword, trigger: 'blur' }
|
||||
],
|
||||
nickname: [
|
||||
{ required: true, message: '请输入昵称', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '昵称长度在2到20个字符', trigger: 'blur' }
|
||||
],
|
||||
shopId: [
|
||||
{ required: true, message: '请选择店铺', trigger: 'change' }
|
||||
]
|
||||
}
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const response = await shopApi.getShopsSimple()
|
||||
shops.value = response.data || []
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
message.error('获取店铺列表失败')
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
if (activeTab.value === 'login') {
|
||||
const response = await authApi.login({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
rememberMe: formData.rememberMe
|
||||
})
|
||||
|
||||
const loginData = response as any
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
|
||||
message.success('登录成功')
|
||||
router.push('/products')
|
||||
} else {
|
||||
await authApi.register({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
nickname: formData.nickname,
|
||||
shopId: formData.shopId!
|
||||
})
|
||||
|
||||
message.success('注册成功,请登录')
|
||||
activeTab.value = 'login'
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || (activeTab.value === 'login' ? '登录失败' : '注册失败'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleForgotPassword = () => {
|
||||
message.info('忘记密码功能开发中')
|
||||
}
|
||||
|
||||
const handleWeChatLogin = () => {
|
||||
message.info('微信登录功能开发中')
|
||||
}
|
||||
|
||||
const handleQQLogin = () => {
|
||||
message.info('QQ登录功能开发中')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchShops()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.auth-container {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.logo-section {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 48px;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 16px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.tab-container {
|
||||
display: flex;
|
||||
margin-bottom: 30px;
|
||||
border-bottom: 2px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.tab-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 15px;
|
||||
font-size: 16px;
|
||||
color: #999;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tab-item.active {
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.tab-item.active::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -2px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2px;
|
||||
background: #667eea;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.forgot-password {
|
||||
color: #667eea;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.social-login {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.divider::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 50%;
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
.divider span {
|
||||
background: white;
|
||||
padding: 0 15px;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.social-buttons {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.social-buttons .ant-btn {
|
||||
border-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.social-buttons .ant-btn:hover {
|
||||
border-color: #667eea;
|
||||
color: #667eea;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user