修复:修复无店铺后台登录引导
This commit is contained in:
@@ -14,6 +14,15 @@
|
||||
layout="vertical"
|
||||
@finish="handleLogin"
|
||||
>
|
||||
<a-alert
|
||||
v-if="!shopLoading && !hasAvailableShops"
|
||||
type="warning"
|
||||
show-icon
|
||||
message="当前暂无可选店铺"
|
||||
description="如果你使用的是平台管理员账号,可以直接登录后台先创建第一家店铺;其他后台账号仍需先绑定店铺。"
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<a-form-item label="用户名" name="account">
|
||||
<a-input
|
||||
v-model:value="formState.account"
|
||||
@@ -37,10 +46,10 @@
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
size="large"
|
||||
placeholder="请选择登录店铺"
|
||||
:placeholder="hasAvailableShops ? '请选择登录店铺' : '当前暂无可选店铺'"
|
||||
:loading="shopLoading"
|
||||
:options="shopOptions"
|
||||
:disabled="shopLoading || shopOptions.length === 0"
|
||||
:disabled="shopLoading || !hasAvailableShops"
|
||||
show-search
|
||||
:filter-option="filterShopOption"
|
||||
/>
|
||||
@@ -96,6 +105,7 @@ const shopOptions = computed(() =>
|
||||
value: shop.id
|
||||
}))
|
||||
)
|
||||
const hasAvailableShops = computed(() => shopOptions.value.length > 0)
|
||||
|
||||
const formRules = {
|
||||
account: [
|
||||
@@ -103,7 +113,15 @@ const formRules = {
|
||||
{ pattern: /^[a-zA-Z0-9_\-@.]+$/, message: '账号只能包含数字、字母、下划线、连字符、@和点号', trigger: 'blur' }
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择登录店铺', trigger: 'change' }]
|
||||
shopId: [{
|
||||
validator: async () => {
|
||||
if (!hasAvailableShops.value || formState.shopId) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
return Promise.reject(new Error('请选择登录店铺'))
|
||||
},
|
||||
trigger: 'change'
|
||||
}]
|
||||
} as any
|
||||
|
||||
const filterShopOption = (input: string, option: { label?: string | number } | undefined) =>
|
||||
@@ -128,6 +146,10 @@ const loadShops = async () => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
shops.value = await shopApi.getShopsSimple() as unknown as ShopSimpleVO[]
|
||||
if (!shops.value.length) {
|
||||
formState.shopId = undefined
|
||||
return
|
||||
}
|
||||
if (!formState.shopId && shops.value.length === 1) {
|
||||
const [onlyShop] = shops.value
|
||||
if (onlyShop) {
|
||||
@@ -150,7 +172,7 @@ const handleLogin = async () => {
|
||||
const res = await adminAuthApi.login({
|
||||
account: formState.account,
|
||||
password: formState.password,
|
||||
shopId: formState.shopId as number
|
||||
shopId: formState.shopId
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user