修复:统一后台登录店铺展示和中文提示

This commit is contained in:
xiaowang
2026-03-21 14:33:33 +08:00
parent 3b8965a168
commit c2fb02fe47
8 changed files with 133 additions and 22 deletions
+18 -6
View File
@@ -96,13 +96,16 @@ const { loadUserPermissions } = usePermission()
const formState = reactive({
account: '',
password: '',
shopId: undefined as number | undefined
shopId: undefined as string | undefined
})
const getShopIdValue = (shop: ShopSimpleVO) => String(shop.id ?? '')
const getShopLabel = (shop: ShopSimpleVO) => String(shop.shopName || shop.name || `店铺 ${shop.id}`)
const shopOptions = computed(() =>
shops.value.map(shop => ({
label: shop.name,
value: shop.id
label: getShopLabel(shop),
value: getShopIdValue(shop)
}))
)
const hasAvailableShops = computed(() => shopOptions.value.length > 0)
@@ -135,7 +138,7 @@ const restoreLoginShop = () => {
try {
const parsed = JSON.parse(cached)
if (parsed?.shopId) {
formState.shopId = parsed.shopId
formState.shopId = String(parsed.shopId)
}
} catch (error) {
console.error('恢复后台登录店铺失败:', error)
@@ -150,12 +153,21 @@ const loadShops = async () => {
formState.shopId = undefined
return
}
if (!formState.shopId && shops.value.length === 1) {
const hasMatchedShop = shopOptions.value.some(option => option.value === formState.shopId)
if (hasMatchedShop) {
return
}
if (shops.value.length === 1) {
const [onlyShop] = shops.value
if (onlyShop) {
formState.shopId = onlyShop.id
formState.shopId = getShopIdValue(onlyShop)
}
return
}
formState.shopId = undefined
} catch (error) {
console.error('获取登录店铺列表失败:', error)
message.error('店铺列表加载失败,请刷新后重试')