feat: 品牌 Logo 可配置,并加固本地登录进系统跳转
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m2s

其他配置支持上传系统顶栏/官网 Logo;登录成功后进系统增加超时与整页兜底,避免 Vite 热更新下卡在登录页。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-11-19 16:03:32 +08:00
parent 25874478d0
commit 4434f9552a
9 changed files with 338 additions and 23 deletions

View File

@ -76,6 +76,30 @@ export async function uploadPaymentReceiveQr(channel: PaymentReceiveQrChannel, f
return unwrapData<PaymentReceiveQrDto>(res.data)
}
export type BrandLogoChannel = 'portal' | 'site'
export interface BrandLogoDto {
portalUrl?: string
siteUrl?: string
}
/** 获取品牌 Logo(系统顶栏 / 官网)可访问地址 */
export async function getBrandLogo() {
const res = await axiosInstance.get(omsUrl('/system/other-config/brand-logo'))
return unwrapData<BrandLogoDto>(res.data)
}
/** 上传并替换品牌 Logo */
export async function uploadBrandLogo(channel: BrandLogoChannel, file: File) {
const form = new FormData()
form.append('channel', channel)
form.append('file', file)
const res = await axiosInstance.post(omsUrl('/system/other-config/brand-logo/upload'), form, {
headers: { 'Content-Type': 'multipart/form-data' },
})
return unwrapData<BrandLogoDto>(res.data)
}
/** 轨迹服务默认配置编码 */
export const TRACK_SERVICE_CONFIG_CODE = 'track_service'

View File

@ -3,7 +3,7 @@
<div class="top-nav-header">
<!-- Logo 区域:点击跳转官网首页 -->
<a class="top-nav-logo" href="/" :title="t('brand.fullName')" @click="goOfficialSite">
<img :src="navLogo" :alt="t('brand.name')" />
<img :src="navLogoSrc" :alt="t('brand.name')" />
<div class="top-nav-logo__brand">
<span class="top-nav-logo__name">{{ t('brand.name') }}</span>
<span class="top-nav-logo__full">{{ t('brand.fullName') }}</span>
@ -282,7 +282,8 @@ import { Message } from '@arco-design/web-vue';
import { openWindow, regexUrl } from '@/utils';
import { MenuService, AuthService } from '@/api/rbac';
import type { MenuTreeDto } from '@/api/rbac';
import navLogo from '@/assets/500x500.png';
import navLogoFallback from '@/assets/500x500.png';
import { loadBrandLogoUrls } from '@/utils/brandLogo';
import {
initHiprintClientState,
setHiprintClientEnabled,
@ -313,6 +314,11 @@ const appStore = useAppStore();
const tabBarStore = useTabBarStore();
const rbacUserStore = useRbacUserStore();
const navLogoSrc = ref(navLogoFallback);
void loadBrandLogoUrls().then((urls) => {
navLogoSrc.value = urls.portal;
});
const topMenuCon = ref<HTMLElement | null>(null);
const topNavEnable = computed(() => true); // 启用顶部导航
const tabNavEnable = computed(() => appStore.tabBar);

View File

@ -4251,6 +4251,17 @@ export default {
'system.otherConfig.actions.save': 'Save',
'system.otherConfig.actions.cancel': 'Cancel',
'system.otherConfig.actions.paymentQr': 'Payment QR',
'system.otherConfig.actions.brandLogo': 'Brand logo',
'system.otherConfig.brandLogo.title': 'Brand logo',
'system.otherConfig.brandLogo.tip':
'Shown on the system top nav and official site header. Takes effect immediately; defaults are used when empty.',
'system.otherConfig.brandLogo.portal': 'System top nav',
'system.otherConfig.brandLogo.site': 'Official site',
'system.otherConfig.brandLogo.replace': 'Replace',
'system.otherConfig.brandLogo.empty': 'Not uploaded',
'system.otherConfig.brandLogo.uploadSuccess': 'Brand logo updated',
'system.otherConfig.brandLogo.uploadFailed': 'Upload failed',
'system.otherConfig.brandLogo.loadFailed': 'Failed to load brand logo',
'system.otherConfig.actions.wechatOrderNotify': 'WeChat order notify',
'system.otherConfig.wechatOrderNotify.title': 'WeChat order notify templates',
'system.otherConfig.wechatOrderNotify.tip':

View File

@ -4263,6 +4263,17 @@ export default {
'system.otherConfig.actions.save': '保存',
'system.otherConfig.actions.cancel': '取消',
'system.otherConfig.actions.paymentQr': '收款码',
'system.otherConfig.actions.brandLogo': '品牌 Logo',
'system.otherConfig.brandLogo.title': '品牌 Logo',
'system.otherConfig.brandLogo.tip':
'用于系统顶栏与官网头部展示。更换后立即生效;未上传时前端使用默认图。',
'system.otherConfig.brandLogo.portal': '系统顶栏',
'system.otherConfig.brandLogo.site': '官网',
'system.otherConfig.brandLogo.replace': '更换图片',
'system.otherConfig.brandLogo.empty': '尚未上传',
'system.otherConfig.brandLogo.uploadSuccess': '品牌 Logo 已更新',
'system.otherConfig.brandLogo.uploadFailed': '上传失败',
'system.otherConfig.brandLogo.loadFailed': '加载品牌 Logo 失败',
'system.otherConfig.actions.wechatOrderNotify': '微信订单通知',
'system.otherConfig.wechatOrderNotify.title': '微信订单通知模板',
'system.otherConfig.wechatOrderNotify.tip':

51
src/utils/brandLogo.ts Normal file
View File

@ -0,0 +1,51 @@
import { getBrandLogo, type BrandLogoDto } from '@/api/system/otherConfig'
import { resolveOmsAssetUrl, unwrapData } from '@/api/oms/common'
import { resolveAdminApiPath } from '@/utils/adminApi'
import portalLogoFallback from '@/assets/500x500.png'
export type BrandLogoUrls = {
portal: string
site: string
}
const SITE_LOGO_FALLBACK = '/site/img/logo1.png'
function mapBrandLogoDto(data?: BrandLogoDto | null): BrandLogoUrls {
return {
portal: resolveOmsAssetUrl(data?.portalUrl) || portalLogoFallback,
site: resolveOmsAssetUrl(data?.siteUrl) || SITE_LOGO_FALLBACK,
}
}
/** 拉取配置的品牌 Logo;未配置或失败时回退本地默认图(需登录态) */
export async function loadBrandLogoUrls(): Promise<BrandLogoUrls> {
try {
const data = await getBrandLogo()
return mapBrandLogoDto(data)
} catch {
return {
portal: portalLogoFallback,
site: SITE_LOGO_FALLBACK,
}
}
}
/** 官网匿名拉取品牌 Logo(不依赖登录态) */
export async function fetchBrandLogoUrlsPublic(): Promise<BrandLogoUrls> {
try {
const res = await fetch(resolveAdminApiPath('/system/other-config/brand-logo'), {
method: 'GET',
headers: { Accept: 'application/json' },
credentials: 'omit',
})
if (!res.ok) throw new Error(`HTTP ${res.status}`)
const body = await res.json()
const data = unwrapData<BrandLogoDto>(body)
return mapBrandLogoDto(data)
} catch {
return {
portal: portalLogoFallback,
site: SITE_LOGO_FALLBACK,
}
}
}

View File

@ -46,6 +46,51 @@ function stillOnLoginPage(): boolean {
return isLoginRouteName(router.currentRoute.value.name as string);
}
function resolveEnterHref(path: string, query: LocationQueryRaw): string {
try {
const href = router.resolve({ path, query }).href;
if (href) return href;
} catch {
/* ignore */
}
const qs = new URLSearchParams();
Object.entries(query || {}).forEach(([k, v]) => {
if (v == null) return;
if (Array.isArray(v)) {
v.forEach((item) => {
if (item != null) qs.append(k, String(item));
});
return;
}
qs.set(k, String(v));
});
const q = qs.toString();
return q ? `${path}?${q}` : path;
}
function hardEnter(path: string, query: LocationQueryRaw) {
// 整页进入:用 Token 冷启动重建动态路由,避开 rematch / 守卫挂死
window.location.assign(resolveEnterHref(path, query));
}
function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
return new Promise<T>((resolve, reject) => {
const timer = window.setTimeout(() => {
reject(new Error(`enter-system timeout after ${ms}ms`));
}, ms);
promise.then(
(value) => {
window.clearTimeout(timer);
resolve(value);
},
(err) => {
window.clearTimeout(timer);
reject(err);
},
);
});
}
/**
* 登录成功后进入系统(客户端 / 管理端共用)
*
@ -65,13 +110,27 @@ export async function enterSystemAfterLogin(options: {
void options.playExit?.();
void ensureHeavyPlugins();
const query = (options.target.query || {}) as LocationQueryRaw;
const fallbackPath =
(typeof options.target.path === 'string' && options.target.path) ||
options.fallbackPath;
const isAgentPortal = useRbacUserStore().loginPortalType === OmsLoginType.Agent;
await Promise.all([
ensureFullLocaleMessages(),
isAgentPortal
? Promise.resolve().then(() => markDynamicRouterInitialized(true))
: ensureDynamicRouterReady({ forceRefresh: false }),
]);
try {
await withTimeout(
Promise.all([
ensureFullLocaleMessages(),
isAgentPortal
? Promise.resolve().then(() => markDynamicRouterInitialized(true))
: ensureDynamicRouterReady({ forceRefresh: false }),
]),
8000,
);
} catch (err) {
console.error('[enterSystemAfterLogin] bootstrap failed, hard enter', err);
hardEnter(fallbackPath, query);
return;
}
// 等 addRoute 触发的 rematch 落定,再 replace,降低与守卫并发
await nextTick();
@ -80,30 +139,45 @@ export async function enterSystemAfterLogin(options: {
// 登录壳不进业务页签;进系统前清空,避免残留「login」标签
useTabBarStore().resetTabList();
const query = (options.target.query || {}) as LocationQueryRaw;
const tryReplace = async () => {
try {
await router.replace({ ...options.target } as RouteLocationRaw);
await withTimeout(
router.replace({ ...options.target } as RouteLocationRaw),
4000,
);
} catch (navErr) {
if (navErr instanceof Error && navErr.message.includes('timeout')) {
throw navErr;
}
if (!isNavigationFailure(navErr)) throw navErr;
await router.replace({
path: options.fallbackPath,
query,
});
await withTimeout(
router.replace({
path: options.fallbackPath,
query,
}),
4000,
);
}
};
await tryReplace();
try {
await tryReplace();
} catch (err) {
console.error('[enterSystemAfterLogin] replace failed, hard enter', err);
hardEnter(fallbackPath, query);
return;
}
// 兜底:动态路由 rematch 仍可能吞掉 replace,Token 已在但人停在登录页
if (stillOnLoginPage()) {
await nextTick();
await tryReplace();
try {
await tryReplace();
} catch {
/* fall through */
}
}
if (stillOnLoginPage()) {
const path =
(typeof options.target.path === 'string' && options.target.path) ||
options.fallbackPath;
window.location.assign(router.resolve({ path, query }).href);
hardEnter(fallbackPath, query);
}
}

View File

@ -480,8 +480,14 @@ async function handleSubmit() {
await refreshCaptchaAfterFail();
loginCharacters.value?.onLoginFailed();
}
} catch {
errorBox.value = t('login.form.login.failed');
} catch (err: unknown) {
const msg = err instanceof Error ? loginErrorForUser(err.message) : '';
// 无菜单权限等进系统失败时,保留可读原因,避免只显示泛化「登录失败」
errorBox.value =
msg && !/timeout|enter-system/i.test(msg)
? msg
: t('login.form.login.failed');
console.error('[login] submit failed', err);
await syncGuard(loginForm.account);
await refreshCaptchaAfterFail();
loginCharacters.value?.onLoginFailed();

View File

@ -2,7 +2,7 @@
<header id="header" class="header d-flex align-items-center fixed-top">
<div class="container-fluid container-xl d-flex align-items-center justify-content-between">
<a href="/" class="logo d-flex align-items-center" @click="$emit('home')">
<img src="/site/img/logo1.png" alt="BCD logo" width="40" height="40" />
<img :src="siteLogoSrc" alt="BCD logo" width="40" height="40" />
<span class="brand-lockup">
<h1>BCD</h1>
<small class="brand-fullname">Business & Customer & Delivery</small>
@ -117,6 +117,7 @@
<script lang="ts" setup>
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { fetchBrandLogoUrlsPublic } from '@/utils/brandLogo';
import { useUserStore } from '@/store';
import { useRbacUserStore } from '@/store/modules/rbac-user';
import { applyRbacUserToUserStore } from '@/utils/enter-system';
@ -150,6 +151,10 @@
const rbacUserStore = useRbacUserStore();
const signedIn = computed(() => rbacUserStore.isLoggedIn);
const homeUrl = officialAppHomeUrl();
const siteLogoSrc = ref('/site/img/logo1.png');
void fetchBrandLogoUrlsPublic().then((urls) => {
siteLogoSrc.value = urls.site;
});
function onLoginClick(e: MouseEvent) {
goOfficialLogin(router, undefined, e);

View File

@ -12,6 +12,10 @@
<template #icon><icon-qrcode /></template>
{{ t('system.otherConfig.actions.paymentQr') }}
</a-button>
<a-button class="header-tool-btn" @click="openBrandLogoModal">
<template #icon><icon-image /></template>
{{ t('system.otherConfig.actions.brandLogo') }}
</a-button>
<a-button class="header-tool-btn" @click="openWechatNotifyModal">
<template #icon><icon-notification /></template>
{{ t('system.otherConfig.actions.wechatOrderNotify') }}
@ -499,6 +503,55 @@
</div>
</div>
</a-modal>
<a-modal
v-model:visible="brandLogoVisible"
:title="t('system.otherConfig.brandLogo.title')"
:footer="false"
width="640px"
:mask-closable="false"
unmount-on-close
>
<a-alert type="info" :show-icon="false" class="modal-form-tip">
{{ t('system.otherConfig.brandLogo.tip') }}
</a-alert>
<div v-if="brandLogoLoading" class="payment-qr-loading">
<a-spin />
</div>
<div v-else class="payment-qr-grid">
<div
v-for="item in brandLogoCards"
:key="item.channel"
class="payment-qr-card"
>
<div class="payment-qr-card__head">
<span class="payment-qr-card__title">{{ item.title }}</span>
<a-upload
:show-file-list="false"
accept="image/png,image/jpeg,image/jpg,image/webp,image/gif,image/bmp"
:disabled="item.uploading"
:custom-request="(option) => handleBrandLogoUpload(item.channel, option)"
>
<a-button size="small" :loading="item.uploading">
{{ t('system.otherConfig.brandLogo.replace') }}
</a-button>
</a-upload>
</div>
<div class="payment-qr-card__preview">
<a-image
v-if="item.url"
:src="item.url"
:preview="true"
width="200"
fit="contain"
/>
<div v-else class="payment-qr-card__empty">
{{ t('system.otherConfig.brandLogo.empty') }}
</div>
</div>
</div>
</div>
</a-modal>
</div>
</template>
@ -515,11 +568,14 @@ import {
WECHAT_MP_FOLLOW_CONFIG_CODE,
createSystemOtherConfig,
deleteSystemOtherConfig,
getBrandLogo,
getPaymentReceiveQr,
getSystemOtherConfigDetail,
getSystemOtherConfigList,
updateSystemOtherConfig,
uploadBrandLogo,
uploadPaymentReceiveQr,
type BrandLogoChannel,
type PaymentReceiveQrChannel,
type SystemOtherConfigDto,
} from '@/api/system/otherConfig'
@ -1023,6 +1079,57 @@ async function openPaymentQrModal() {
await loadPaymentQr()
}
const brandLogoVisible = ref(false)
const brandLogoLoading = ref(false)
const brandLogoUrls = reactive({
portal: '',
site: '',
})
const brandLogoUploading = reactive({
portal: false,
site: false,
})
const brandLogoCards = computed(() => [
{
channel: 'portal' as BrandLogoChannel,
title: t('system.otherConfig.brandLogo.portal'),
url: brandLogoUrls.portal,
uploading: brandLogoUploading.portal,
},
{
channel: 'site' as BrandLogoChannel,
title: t('system.otherConfig.brandLogo.site'),
url: brandLogoUrls.site,
uploading: brandLogoUploading.site,
},
])
function applyBrandLogoDto(data?: { portalUrl?: string; siteUrl?: string } | null) {
const stamp = Date.now()
const portal = resolveOmsAssetUrl(data?.portalUrl)
const site = resolveOmsAssetUrl(data?.siteUrl)
brandLogoUrls.portal = portal ? `${portal}${portal.includes('?') ? '&' : '?'}_t=${stamp}` : ''
brandLogoUrls.site = site ? `${site}${site.includes('?') ? '&' : '?'}_t=${stamp}` : ''
}
async function loadBrandLogo() {
brandLogoLoading.value = true
try {
const data = await getBrandLogo()
applyBrandLogoDto(data)
} catch (e: any) {
Message.error(e?.message || t('system.otherConfig.brandLogo.loadFailed'))
} finally {
brandLogoLoading.value = false
}
}
async function openBrandLogoModal() {
brandLogoVisible.value = true
await loadBrandLogo()
}
const wechatNotifyVisible = ref(false)
const wechatNotifyLoading = ref(false)
const wechatNotifyTemplates = ref<WechatOrderNotifyTemplateDto[]>([])
@ -1125,6 +1232,26 @@ async function handlePaymentQrUpload(channel: PaymentReceiveQrChannel, option: a
}
}
async function handleBrandLogoUpload(channel: BrandLogoChannel, option: any) {
const file: File | undefined = option?.fileItem?.file ?? option?.file
if (!file) {
option?.onError?.(new Error('no file'))
return
}
brandLogoUploading[channel] = true
try {
const data = await uploadBrandLogo(channel, file)
applyBrandLogoDto(data)
option?.onSuccess?.(data)
Message.success(t('system.otherConfig.brandLogo.uploadSuccess'))
} catch (e: any) {
option?.onError?.(e)
Message.error(e?.message || t('system.otherConfig.brandLogo.uploadFailed'))
} finally {
brandLogoUploading[channel] = false
}
}
async function handleSave() {
if (!editingId.value) return
try {