功能:完善多店铺登录与首次部署SQL

This commit is contained in:
xiaowang
2026-03-26 10:28:28 +08:00
parent 5601428087
commit 764bfadb51
79 changed files with 6524 additions and 2603 deletions
+223 -10
View File
@@ -180,30 +180,39 @@
<a-form-item
v-if="activeTab === 'login'"
label="选择店铺(可选)"
name="shopId"
label="选择登录店铺"
>
<a-select
v-model:value="formData.shopId"
placeholder="如需绑定店铺或首次手机号登录,请选择店铺"
:placeholder="loginShopPlaceholder"
size="large"
:loading="loadingShops"
:disabled="!allowLoginShopless && !loginShops.length"
allow-clear
>
<a-select-option
v-if="shops.length === 0"
v-if="loginShops.length === 0"
disabled
value=""
>
暂无店铺数据
{{ allowLoginShopless ? '当前无需选择店铺' : '暂无可用店铺' }}
</a-select-option>
<a-select-option
v-for="shop in shops"
v-for="shop in loginShops"
:key="shop.id"
:value="shop.id"
:value="normalizeShopOptionValue(shop.id)"
>
{{ shop.shopName }}
</a-select-option>
</a-select>
<div
v-if="loginShopMessage"
class="field-status"
:class="loginShops.length || allowLoginShopless ? 'success' : 'error'"
>
{{ loginShopMessage }}
</div>
</a-form-item>
<a-form-item
@@ -251,7 +260,7 @@
<a-select-option
v-for="shop in shops"
:key="shop.id"
:value="shop.id"
:value="normalizeShopOptionValue(shop.id)"
>
{{ shop.shopName }}
</a-select-option>
@@ -385,7 +394,12 @@ 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, type AvailabilityCheckResponse, type LoginAccountCheckResponse } from '@/api/user'
import {
userApi,
type AvailabilityCheckResponse,
type LoginAccountCheckResponse,
type LoginShopSelectionResponse
} from '@/api/user'
const router = useRouter()
@@ -394,10 +408,13 @@ const loginType = ref<'password' | 'phone'>('password')
const loading = ref(false)
const loadingShops = ref(false)
const shops = ref<any[]>([])
const loginShops = ref<Array<{ id: number | string; shopName: string }>>([])
const countdown = ref(0)
const loginAccountStatus = ref<LoginAccountCheckResponse | null>(null)
const registerAccountStatus = ref<AvailabilityCheckResponse | null>(null)
const registerPhoneStatus = ref<AvailabilityCheckResponse | null>(null)
const loginShopMessage = ref('')
const allowLoginShopless = ref(false)
const forgotPasswordVisible = ref(false)
const forgotCountdown = ref(0)
@@ -414,16 +431,33 @@ const formData = reactive({
password: '',
confirmPassword: '',
nickname: '',
shopId: undefined as number | undefined,
shopId: undefined as string | undefined,
phone: '',
verificationCode: '',
rememberMe: false
})
let loginAccountCheckTimer: number | undefined
let loginPhoneShopCheckTimer: number | undefined
const phoneRegex = /^1[3-9]\d{9}$/
const verificationCodeRegex = /^\d{6}$/
const loginShopPlaceholder = computed(() => {
if (allowLoginShopless.value) {
return '当前暂无启用店铺,可直接登录'
}
if (loadingShops.value) {
return '正在加载可登录店铺'
}
return loginShops.value.length ? '请选择登录店铺' : '请先输入账号或手机号'
})
const validateLoginShopRequired = async () => {
if (allowLoginShopless.value || !loginShops.value.length || formData.shopId) {
return Promise.resolve()
}
return Promise.reject('请选择登录店铺')
}
const validatePassword = async (_rule: Rule, value: string) => {
if (!value || value.length < 6) {
@@ -489,6 +523,9 @@ const loginPasswordRules: Record<string, Rule[]> = {
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' }
],
shopId: [
{ validator: validateLoginShopRequired, trigger: 'change' }
]
}
@@ -500,6 +537,9 @@ const loginPhoneRules: Record<string, Rule[]> = {
verificationCode: [
{ required: true, message: '请输入验证码', trigger: 'blur' },
{ pattern: verificationCodeRegex, message: '验证码必须为 6 位数字', trigger: 'blur' }
],
shopId: [
{ validator: validateLoginShopRequired, trigger: 'change' }
]
}
@@ -545,6 +585,140 @@ const resetLoginAccountStatus = () => {
loginAccountStatus.value = null
}
const resetPhoneLoginShopCheck = () => {
if (loginPhoneShopCheckTimer !== undefined) {
window.clearTimeout(loginPhoneShopCheckTimer)
loginPhoneShopCheckTimer = undefined
}
}
const resetLoginShopState = (clearSelectedShop = activeTab.value === 'login') => {
resetPhoneLoginShopCheck()
loginShops.value = []
loginShopMessage.value = ''
allowLoginShopless.value = false
if (clearSelectedShop) {
formData.shopId = undefined
}
}
const normalizeShopOptionValue = (shopId?: string | number | null) => {
if (shopId === undefined || shopId === null || shopId === '') {
return undefined
}
return String(shopId)
}
const isLoginShopPrefetchUnsupported = (error: unknown) => {
const status = (error as any)?.response?.status
return status === 404
}
const applyLoginShopSelection = (selection?: LoginShopSelectionResponse | null) => {
loginShops.value = selection?.shops || []
allowLoginShopless.value = Boolean(selection?.allowShoplessLogin)
loginShopMessage.value = selection?.message || ''
if (allowLoginShopless.value) {
formData.shopId = undefined
return
}
if (!loginShops.value.length) {
formData.shopId = undefined
return
}
const currentShopId = normalizeShopOptionValue(formData.shopId)
const matchedShop = loginShops.value.find(shop => normalizeShopOptionValue(shop.id) === currentShopId)
if (matchedShop) {
formData.shopId = normalizeShopOptionValue(matchedShop.id)
return
}
if (loginShops.value.length === 1) {
const [onlyShop] = loginShops.value
if (onlyShop) {
formData.shopId = normalizeShopOptionValue(onlyShop.id)
return
}
}
formData.shopId = undefined
}
const loadLoginShopsByAccount = async (account = formData.account) => {
const trimmedAccount = account.trim()
if (activeTab.value !== 'login' || loginType.value !== 'password' || !trimmedAccount) {
resetLoginShopState()
return null
}
try {
const selection = await userApi.getLoginShopsByAccount(trimmedAccount) as unknown as LoginShopSelectionResponse
if (
activeTab.value === 'login'
&& loginType.value === 'password'
&& formData.account.trim() === trimmedAccount
) {
applyLoginShopSelection(selection)
}
return selection
} catch (error) {
if (formData.account.trim() === trimmedAccount) {
if (isLoginShopPrefetchUnsupported(error)) {
applyLoginShopSelection({
allowShoplessLogin: true,
message: '当前环境暂未开放登录前店铺预加载,可直接登录。',
shops: []
})
} else {
resetLoginShopState()
}
}
if (!isLoginShopPrefetchUnsupported(error)) {
console.error('登录店铺查询失败:', error)
}
return null
}
}
const loadLoginShopsByPhone = async (phone = formData.phone) => {
const trimmedPhone = phone.trim()
if (activeTab.value !== 'login' || loginType.value !== 'phone' || !phoneRegex.test(trimmedPhone)) {
resetLoginShopState()
return null
}
try {
const selection = await userApi.getLoginShopsByPhone(trimmedPhone) as unknown as LoginShopSelectionResponse
if (
activeTab.value === 'login'
&& loginType.value === 'phone'
&& formData.phone.trim() === trimmedPhone
) {
applyLoginShopSelection(selection)
}
return selection
} catch (error) {
if (formData.phone.trim() === trimmedPhone) {
if (isLoginShopPrefetchUnsupported(error)) {
applyLoginShopSelection({
allowShoplessLogin: true,
message: '当前环境暂未开放登录前店铺预加载,可直接登录。',
shops: []
})
} else {
resetLoginShopState()
}
}
if (!isLoginShopPrefetchUnsupported(error)) {
console.error('手机号登录店铺查询失败:', error)
}
return null
}
}
const checkLoginAccountAvailability = async (account = formData.account) => {
const trimmedAccount = account.trim()
if (activeTab.value !== 'login' || loginType.value !== 'password' || !trimmedAccount) {
@@ -818,6 +992,20 @@ const handleAdminLogin = () => {
watch([activeTab, loginType], () => {
resetLoginAccountStatus()
resetLoginShopState(activeTab.value === 'login')
if (activeTab.value !== 'login') {
return
}
if (loginType.value === 'password' && formData.account.trim()) {
void Promise.all([
checkLoginAccountAvailability(formData.account.trim()),
loadLoginShopsByAccount(formData.account.trim())
])
return
}
if (loginType.value === 'phone' && phoneRegex.test(formData.phone.trim())) {
void loadLoginShopsByPhone(formData.phone.trim())
}
})
watch(
@@ -835,7 +1023,31 @@ watch(
loginAccountCheckTimer = window.setTimeout(() => {
loginAccountCheckTimer = undefined
void checkLoginAccountAvailability(trimmedAccount)
void Promise.all([
checkLoginAccountAvailability(trimmedAccount),
loadLoginShopsByAccount(trimmedAccount)
])
}, 400)
}
)
watch(
() => formData.phone,
value => {
if (activeTab.value !== 'login' || loginType.value !== 'phone') {
return
}
resetPhoneLoginShopCheck()
const trimmedPhone = value.trim()
if (!phoneRegex.test(trimmedPhone)) {
resetLoginShopState()
return
}
loginPhoneShopCheckTimer = window.setTimeout(() => {
loginPhoneShopCheckTimer = undefined
void loadLoginShopsByPhone(trimmedPhone)
}, 400)
}
)
@@ -846,6 +1058,7 @@ onMounted(() => {
onBeforeUnmount(() => {
resetLoginAccountStatus()
resetPhoneLoginShopCheck()
})
</script>