@@ -24,7 +24,7 @@ const AUTH_RECOVERY_EXEMPT_PATHS = [
|
||||
|
||||
export type PartnerSessionProfile = Pick<
|
||||
PartnerMe,
|
||||
'id' | 'name' | 'phone' | 'companyName' | 'isPrimary' | 'permissions' | 'primaryAccountId' | 'hasWechat'
|
||||
'id' | 'name' | 'phone' | 'companyName' | 'isPrimary' | 'permissions' | 'primaryAccountId' | 'primaryPhone' | 'primaryName' | 'hasWechat'
|
||||
> & {
|
||||
staffRole?: PartnerStaffRole;
|
||||
};
|
||||
@@ -109,6 +109,8 @@ function profileFromMe(me: PartnerMe): PartnerSessionProfile {
|
||||
staffRole: me.staffRole ?? undefined,
|
||||
permissions: me.permissions,
|
||||
primaryAccountId: me.primaryAccountId,
|
||||
primaryPhone: me.primaryPhone,
|
||||
primaryName: me.primaryName,
|
||||
hasWechat: me.hasWechat,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/** 合伙人端客服热线(可后续改为环境变量) */
|
||||
export const PARTNER_SUPPORT_PHONE = '400-000-0000';
|
||||
|
||||
export function dialPhone(phone: string) {
|
||||
const normalized = phone.replace(/\s+/g, '');
|
||||
if (!normalized) return false;
|
||||
window.location.href = `tel:${normalized}`;
|
||||
return true;
|
||||
}
|
||||
|
||||
export function contactSupport() {
|
||||
return dialPhone(PARTNER_SUPPORT_PHONE);
|
||||
}
|
||||
|
||||
export function contactPartnerPhone(phone?: string) {
|
||||
return dialPhone(phone ?? '');
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { PartnerMe, PartnerPermissionKey } from '@dukang/shared-types';
|
||||
|
||||
export type PartnerNavKind = 'primary' | 'store_staff' | 'warehouse_staff';
|
||||
|
||||
export function isPrimaryAccount(account: PartnerMe | null | undefined): boolean {
|
||||
return account?.isPrimary !== false;
|
||||
}
|
||||
@@ -17,15 +19,33 @@ export function hasPartnerPermission(
|
||||
return account.permissions?.includes(permission) ?? false;
|
||||
}
|
||||
|
||||
export function partnerHomePath(account: PartnerMe | null | undefined): string {
|
||||
return isSubAccount(account) ? '/stores/new?step=1' : '/';
|
||||
/** 仓库管理员:warehouse:manage,或仅有 order:view(无门店权限) */
|
||||
export function isWarehouseStaff(account: PartnerMe | null | undefined): boolean {
|
||||
if (!account || isPrimaryAccount(account)) return false;
|
||||
if (hasPartnerPermission(account, 'warehouse:manage')) return true;
|
||||
const hasStore =
|
||||
hasPartnerPermission(account, 'store:create') || hasPartnerPermission(account, 'store:manage');
|
||||
if (hasPartnerPermission(account, 'order:view') && !hasStore) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
export const SUB_ACCOUNT_ALLOWED_PREFIXES = ['/stores', '/me', '/login'];
|
||||
export function getPartnerNavKind(account: PartnerMe | null | undefined): PartnerNavKind {
|
||||
if (!account || isPrimaryAccount(account)) return 'primary';
|
||||
if (isWarehouseStaff(account)) return 'warehouse_staff';
|
||||
return 'store_staff';
|
||||
}
|
||||
|
||||
export function isSubAccountPath(pathname: string): boolean {
|
||||
export function partnerHomePath(account: PartnerMe | null | undefined): string {
|
||||
return '/';
|
||||
}
|
||||
|
||||
const STORE_STAFF_PREFIXES = ['/', '/stores', '/me', '/login'];
|
||||
const WAREHOUSE_STAFF_PREFIXES = ['/', '/orders', '/me', '/login'];
|
||||
|
||||
export function isSubAccountPath(pathname: string, navKind: PartnerNavKind = 'store_staff'): boolean {
|
||||
if (pathname === '/login') return true;
|
||||
return SUB_ACCOUNT_ALLOWED_PREFIXES.some(
|
||||
const prefixes = navKind === 'warehouse_staff' ? WAREHOUSE_STAFF_PREFIXES : STORE_STAFF_PREFIXES;
|
||||
return prefixes.some(
|
||||
(prefix) => prefix !== '/login' && (pathname === prefix || pathname.startsWith(`${prefix}/`)),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user