功能:统一账号输入校验并调整首页轮播图
This commit is contained in:
@@ -7,6 +7,8 @@ export interface ShopVO {
|
||||
address: string
|
||||
businessHours: string
|
||||
status?: number
|
||||
coverImageFileId?: string
|
||||
coverImageUrls?: string[]
|
||||
imageFileIds: string
|
||||
imageUrls?: string[]
|
||||
createTime: string
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export const ACCOUNT_REGEX = /^[A-Za-z0-9]+$/
|
||||
const ACCOUNT_SANITIZE_REGEX = /[^A-Za-z0-9]/g
|
||||
|
||||
export const ACCOUNT_RULE_MESSAGE = '账号只能包含字母和数字'
|
||||
|
||||
export const sanitizeAccountInput = (value: string) => (value || '').replace(ACCOUNT_SANITIZE_REGEX, '')
|
||||
@@ -54,6 +54,7 @@
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
size="large"
|
||||
@input="handleAccountInput"
|
||||
@blur="handleRegisterAccountBlur"
|
||||
>
|
||||
<template #prefix>
|
||||
@@ -119,6 +120,7 @@
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
size="large"
|
||||
@input="handleAccountInput"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined style="color: #999" />
|
||||
@@ -394,6 +396,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 { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||
import {
|
||||
userApi,
|
||||
type AvailabilityCheckResponse,
|
||||
@@ -487,9 +490,17 @@ const validateConfirmPassword = async (_rule: Rule, value: string) => {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const handleAccountInput = () => {
|
||||
const normalized = sanitizeAccountInput(formData.account)
|
||||
if (normalized !== formData.account) {
|
||||
formData.account = normalized
|
||||
}
|
||||
}
|
||||
|
||||
const registerRules: Record<string, Rule[]> = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||
],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
@@ -519,7 +530,8 @@ const registerRules: Record<string, Rule[]> = {
|
||||
|
||||
const loginPasswordRules: Record<string, Rule[]> = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' }
|
||||
|
||||
@@ -35,49 +35,31 @@
|
||||
description="先逛作品和门店,收藏、加购、下单时再登录即可。"
|
||||
/>
|
||||
|
||||
<div class="banner-container">
|
||||
<div class="banner-carousel">
|
||||
<a-carousel v-if="bannerImages.length" autoplay :autoplay-speed="3200" effect="fade">
|
||||
<div
|
||||
v-for="banner in bannerImages"
|
||||
:key="banner.shopId"
|
||||
class="banner-slide"
|
||||
@click="openShopById(banner.shopId)"
|
||||
>
|
||||
<img :src="banner.url" :alt="banner.shopName" class="banner-img" />
|
||||
<div class="banner-copy">
|
||||
<a-tag color="blue">门店推荐</a-tag>
|
||||
<h3>{{ banner.shopName }}</h3>
|
||||
<p>{{ banner.businessHours || '欢迎到店体验' }}</p>
|
||||
<section class="section">
|
||||
<div class="banner-container">
|
||||
<div class="banner-carousel">
|
||||
<a-carousel v-if="bannerImages.length" autoplay :autoplay-speed="3200" effect="fade">
|
||||
<div
|
||||
v-for="banner in bannerImages"
|
||||
:key="banner.id"
|
||||
class="banner-slide"
|
||||
@click="openShopById(banner.shopId)"
|
||||
>
|
||||
<img :src="banner.url" :alt="banner.shopName" class="banner-img" />
|
||||
<div class="banner-copy">
|
||||
<a-tag color="blue">门店推荐</a-tag>
|
||||
<h3>{{ banner.shopName }}</h3>
|
||||
<p>{{ banner.businessHours || '欢迎到店体验' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a-carousel>
|
||||
<div v-else class="banner-empty">
|
||||
<h3>发现适合你的美甲风格</h3>
|
||||
<p>先看看门店 Banner 和精选作品,再决定今天预约谁。</p>
|
||||
<a-button type="primary" @click="router.push('/products')">浏览作品</a-button>
|
||||
</div>
|
||||
</a-carousel>
|
||||
<div v-else class="banner-empty">
|
||||
<h3>发现适合你的美甲风格</h3>
|
||||
<p>先看看热门门店和精选作品,再决定今天预约谁。</p>
|
||||
<a-button type="primary" @click="router.push('/products')">浏览作品</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section v-if="featuredShops.length" class="section">
|
||||
<div class="section-header">
|
||||
<h3>热门门店</h3>
|
||||
<a class="see-all" @click="router.push('/products')">去看作品</a>
|
||||
</div>
|
||||
<div class="shop-strip">
|
||||
<a-card
|
||||
v-for="shop in featuredShops"
|
||||
:key="shop.id"
|
||||
class="shop-card"
|
||||
hoverable
|
||||
@click="openShop(shop)"
|
||||
>
|
||||
<div class="shop-card-name">{{ shop.shopName }}</div>
|
||||
<div class="shop-card-address">{{ shop.address || '门店地址待完善' }}</div>
|
||||
<div class="shop-card-hours">{{ shop.businessHours || '营业时间待完善' }}</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section">
|
||||
@@ -158,6 +140,7 @@ import { fileApi } from '../api/file'
|
||||
import { DEFAULT_AVATAR, DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
|
||||
interface BannerImage {
|
||||
id: string
|
||||
shopId: number
|
||||
shopName: string
|
||||
businessHours?: string
|
||||
@@ -191,7 +174,6 @@ const pageSize = 8
|
||||
const isLoggedIn = computed(() => Boolean(localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')))
|
||||
const greeting = computed(() => (isLoggedIn.value ? '欢迎回来' : '游客模式'))
|
||||
const displayName = computed(() => userInfo.value?.nickname || (isLoggedIn.value ? '用户' : '先看看门店和作品'))
|
||||
const featuredShops = computed(() => publicShops.value.slice(0, 4))
|
||||
|
||||
const getRandomColor = (): string => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
@@ -262,12 +244,16 @@ const loadPublicShops = async () => {
|
||||
const loadBannerImages = async () => {
|
||||
const banners: BannerImage[] = []
|
||||
for (const shop of publicShops.value) {
|
||||
const coverIds = (shop as any).coverImageFileId?.split(',').map((id: string) => id.trim()).filter(Boolean) || []
|
||||
const coverIds = (shop.coverImageFileId || shop.imageFileIds || '')
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(Boolean)
|
||||
for (const id of coverIds) {
|
||||
try {
|
||||
const url = await fileApi.getSignedUrl(Number(id)) as unknown as string
|
||||
if (url) {
|
||||
banners.push({
|
||||
id: `${shop.id}-${id}`,
|
||||
shopId: Number(shop.id),
|
||||
shopName: shop.shopName,
|
||||
businessHours: shop.businessHours,
|
||||
@@ -353,10 +339,6 @@ const handleProductClick = (item: ProductCardItem) => {
|
||||
router.push(`/product/${item.id}`)
|
||||
}
|
||||
|
||||
const openShop = (shop: ShopVO) => {
|
||||
router.push(`/shop/${shop.id}`)
|
||||
}
|
||||
|
||||
const openShopById = (shopId: number) => {
|
||||
router.push(`/shop/${shopId}`)
|
||||
}
|
||||
@@ -418,9 +400,6 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
.banner-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 18px 0 0;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
@@ -513,7 +492,6 @@ onUnmounted(() => {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.shop-strip,
|
||||
.horizontal-scroll {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
@@ -522,31 +500,10 @@ onUnmounted(() => {
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.shop-strip::-webkit-scrollbar,
|
||||
.horizontal-scroll::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.shop-card {
|
||||
min-width: 220px;
|
||||
border-radius: 18px;
|
||||
background: linear-gradient(135deg, #fff 0%, #f7faff 100%);
|
||||
}
|
||||
|
||||
.shop-card-name {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.shop-card-address,
|
||||
.shop-card-hours {
|
||||
margin-top: 8px;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.product-card {
|
||||
width: 152px;
|
||||
flex-shrink: 0;
|
||||
@@ -643,15 +600,6 @@ onUnmounted(() => {
|
||||
max-width: var(--frontend-content-max-width);
|
||||
}
|
||||
|
||||
.shop-strip {
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.shop-card {
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.horizontal-scroll {
|
||||
overflow: visible;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
size="large"
|
||||
placeholder="请输入用户名"
|
||||
:prefix-icon="UserOutlined"
|
||||
@input="handleAccountInput"
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
@@ -82,6 +83,7 @@ import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||
import { adminAuthApi, type LoginShopSelectionResponse } from '@/api/admin'
|
||||
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -100,6 +102,13 @@ const formState = reactive({
|
||||
})
|
||||
let loginShopTimer: number | undefined
|
||||
|
||||
const handleAccountInput = () => {
|
||||
const normalized = sanitizeAccountInput(formState.account)
|
||||
if (normalized !== formState.account) {
|
||||
formState.account = normalized
|
||||
}
|
||||
}
|
||||
|
||||
const getShopIdValue = (shop: { id: number | string; shopName: string }) => String(shop.id ?? '')
|
||||
const getShopLabel = (shop: { id: number | string; shopName: string }) => String(shop.shopName || `店铺 ${shop.id}`)
|
||||
|
||||
@@ -127,7 +136,7 @@ const shopPlaceholder = computed(() => {
|
||||
const formRules = {
|
||||
account: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
shopId: [{
|
||||
|
||||
@@ -111,7 +111,11 @@
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="账号" name="account">
|
||||
<a-input v-model:value="formState.account" placeholder="请输入账号" />
|
||||
<a-input
|
||||
v-model:value="formState.account"
|
||||
placeholder="请输入账号"
|
||||
@input="handleAccountInput"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="昵称" name="nickname">
|
||||
<a-input v-model:value="formState.nickname" placeholder="请输入昵称" />
|
||||
@@ -360,6 +364,7 @@ import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||
import {
|
||||
adminShopApi,
|
||||
adminUserApi,
|
||||
@@ -427,6 +432,13 @@ const formState = reactive({
|
||||
shopIds: [] as string[]
|
||||
})
|
||||
|
||||
const handleAccountInput = () => {
|
||||
const normalized = sanitizeAccountInput(formState.account)
|
||||
if (normalized !== formState.account) {
|
||||
formState.account = normalized
|
||||
}
|
||||
}
|
||||
|
||||
const balanceForm = reactive<AdminUserBalanceChangeRequest>({
|
||||
changeScene: 'RECHARGE',
|
||||
amount: undefined as unknown as number,
|
||||
@@ -441,7 +453,10 @@ const vipForm = reactive<AdminUserVipOverrideRequest>({
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||||
],
|
||||
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
|
||||
Reference in New Issue
Block a user