feat(多公司): 两端接上公司身份 —— 后台公司目录页、建号必选公司、顶栏显示所属公司
- 新后台新增「公司管理」页(列/新建/改名/启停,不提供删除),路由 menuKey 与 columns 表的 admin_companies 逐字一致,由用例钉住;操作指引补该菜单一条。 - 建号弹窗对超管必须显式选一家(后端对"不传"仍落操作者自己公司,是给旧后台兜底); admin 只能落自己公司,越权直接 403。账号列表显示 company_name,可按公司筛。 - 客户端登录后把 companyId/companyName 落到 localStorage 并在顶栏显示; 两个登出出口(handleKicked 与切号/登出)连公司名一起清 —— 残留会把上一个账号 的归属显示给下一个账号。 - 契约分层:列表端点用 snake_case(company_id/company_name),current-user 与登录 回包用 camelCase;解析器读到另一套写法必须忽略,防止前后端各猜一套。 admin-frontend-vue 1678/1678、frontend-vue 672/672,两边 build(含 vue-tsc --noEmit)干净。
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
<div class="top-right">
|
||||
<NotificationBell />
|
||||
<BrandApiSecretSettingsButton variant="topbar" />
|
||||
<span v-if="companyName" class="company-name" :title="`所属公司:${companyName}`">{{ companyName }}</span>
|
||||
<span class="admin-name">{{ username }}</span>
|
||||
</div>
|
||||
</header>
|
||||
@@ -45,6 +46,7 @@ import { filterGroupsByPermission, TOOL_GROUPS } from '@/pages/amazon/tool-catal
|
||||
import type { VisibleGroup } from '@/pages/amazon/tool-catalog'
|
||||
import { resolvePageHref } from '@/shared/page-prefix'
|
||||
import { getCurrentUserAppColumnKeys } from '@/shared/api/permission'
|
||||
import { readCompanyIdentity } from '@/shared/auth/company-identity'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -61,6 +63,8 @@ const emit = defineEmits<{ change: [key: 'front' | 'ops' | 'logi'] }>()
|
||||
const activeCat = computed(() => props.activeCat)
|
||||
const visibleCats = ref<VisibleGroup[]>(TOOL_GROUPS.map((group) => ({ ...group, tools: [...group.tools] })))
|
||||
const username = ref('admin')
|
||||
/** 所属公司名:后端未返回时为空串,该段整体不渲染(不能显示 undefined)。 */
|
||||
const companyName = ref('')
|
||||
|
||||
/** 分类 tab 点击回到工具台对应分组 */
|
||||
const toolbarHref = resolvePageHref('/new_web_source/amazon-console.html')
|
||||
@@ -84,6 +88,7 @@ function underlineStyle(cat: VisibleGroup) {
|
||||
onMounted(async () => {
|
||||
const localName = typeof window === 'undefined' ? '' : (window.localStorage.getItem('username') || '').trim()
|
||||
if (localName) username.value = localName
|
||||
companyName.value = readCompanyIdentity()
|
||||
try {
|
||||
const keys = await getCurrentUserAppColumnKeys()
|
||||
visibleCats.value = filterGroupsByPermission(TOOL_GROUPS, keys)
|
||||
@@ -253,6 +258,18 @@ onMounted(async () => {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.company-name {
|
||||
max-width: 180px;
|
||||
padding: 3px 10px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 999px;
|
||||
color: #9fb0c9;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.admin-name {
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
|
||||
@@ -112,6 +112,7 @@ import { onMounted, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { loginWithDevice } from '@/shared/api/user'
|
||||
import { KICK_NOTICE_KEY } from '@/shared/auth/kick-handler'
|
||||
import { COMPANY_NAME_STORAGE_KEY, writeCompanyIdentity } from '@/shared/auth/company-identity'
|
||||
import { useVersionUpdate } from '@/shared/composables/useVersionUpdate'
|
||||
import { clearApiSecretCache } from '@/shared/utils/api-secret-store'
|
||||
import UpdateProgressBar from '@/shared/components/UpdateProgressBar.vue'
|
||||
@@ -432,6 +433,8 @@ async function submitLogin() {
|
||||
/* 忽略 */
|
||||
}
|
||||
}
|
||||
// 公司名随后端可选返回:没有就删键,顶栏不显示该段(见 shared/auth/company-identity)
|
||||
writeCompanyIdentity(data)
|
||||
// 登录成功即持久化记住/自动登录凭据(桌面与网页均可,密码 AES 加密落 localStorage)
|
||||
void saveCredentials(account)
|
||||
// 桌面端 Flask cookie 同步已随瘦身下线:登录态只存 localStorage(JWT 走 Bearer),无 cookie 依赖
|
||||
@@ -453,6 +456,7 @@ onMounted(() => {
|
||||
window.localStorage.removeItem(AUTH_TOKEN_KEY)
|
||||
window.localStorage.removeItem('uid')
|
||||
window.localStorage.removeItem('username')
|
||||
window.localStorage.removeItem(COMPANY_NAME_STORAGE_KEY)
|
||||
} catch {
|
||||
/* 忽略 */
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ export interface LoginData {
|
||||
token?: string
|
||||
userId?: number | string
|
||||
username?: string
|
||||
/** 所属公司(company.id,V143 新增;旧 jar 不返回该字段) */
|
||||
companyId?: number | string
|
||||
companyName?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 用户端公司身份(设计文档 §2.4)
|
||||
*
|
||||
* app-web 没有 Pinia,登录态一直靠 localStorage(uid/username/auth token),所以公司名也走同一通道。
|
||||
* 只信后端确认过的值:登录/check_login 的 data 里没有 companyName 时删键,而不是留着——
|
||||
* 同一台机器换账号登录时,残留的公司名会把上一个账号的归属显示给当前账号。
|
||||
*/
|
||||
|
||||
export const COMPANY_NAME_STORAGE_KEY = 'company_name'
|
||||
|
||||
function storage(): Storage | null {
|
||||
if (typeof window === 'undefined') return null
|
||||
try {
|
||||
return window.localStorage
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/** 从登录/check_login 的 data 段落公司名;缺字段或空白一律清键。 */
|
||||
export function writeCompanyIdentity(data: unknown): void {
|
||||
const db = storage()
|
||||
if (!db) return
|
||||
const raw = data && typeof data === 'object' ? (data as { companyName?: unknown }).companyName : undefined
|
||||
const name = typeof raw === 'string' ? raw.trim() : ''
|
||||
if (name) db.setItem(COMPANY_NAME_STORAGE_KEY, name)
|
||||
else db.removeItem(COMPANY_NAME_STORAGE_KEY)
|
||||
}
|
||||
|
||||
/** 当前账号所属公司名;没有则空串(调用方据此不渲染该段,不得显示 undefined)。 */
|
||||
export function readCompanyIdentity(): string {
|
||||
const db = storage()
|
||||
if (!db) return ''
|
||||
try {
|
||||
return (db.getItem(COMPANY_NAME_STORAGE_KEY) || '').trim()
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
import { get } from '@/shared/api/http'
|
||||
import { writeCompanyIdentity } from './company-identity'
|
||||
|
||||
const AUTH_TOKEN_KEY = 'aiimage_auth_token'
|
||||
const UID_KEY = 'uid'
|
||||
@@ -16,6 +17,8 @@ const UID_KEY = 'uid'
|
||||
interface CheckLoginData {
|
||||
userId?: number | string
|
||||
username?: string
|
||||
companyId?: number | string
|
||||
companyName?: string
|
||||
}
|
||||
|
||||
/** 确保当前页面具备登录态;返回是否可继续进入页面 */
|
||||
@@ -38,6 +41,7 @@ export async function ensureAuth(): Promise<boolean> {
|
||||
if (response.data.username) {
|
||||
window.localStorage.setItem('username', String(response.data.username))
|
||||
}
|
||||
writeCompanyIdentity(response.data)
|
||||
return true
|
||||
} catch {
|
||||
// token 失效:清掉本地登录态(跳转交给路由守卫)
|
||||
@@ -74,6 +78,7 @@ export async function restoreLoginUser(): Promise<{ username?: string } | null>
|
||||
if (response.data.username) {
|
||||
window.localStorage.setItem('username', String(response.data.username))
|
||||
}
|
||||
writeCompanyIdentity(response.data)
|
||||
return { username: response.data.username }
|
||||
} catch {
|
||||
return null
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
* 记住的账号密码保留,手动点一次即可重新登录(此时顶掉对方,最后登录者胜)。
|
||||
*/
|
||||
|
||||
import { COMPANY_NAME_STORAGE_KEY } from './company-identity.ts'
|
||||
|
||||
const AUTH_TOKEN_KEY = 'aiimage_auth_token'
|
||||
const UID_KEY = 'uid'
|
||||
const USERNAME_KEY = 'username'
|
||||
@@ -69,6 +71,7 @@ export function handleKicked(): void {
|
||||
storage.removeItem(AUTH_TOKEN_KEY)
|
||||
storage.removeItem(UID_KEY)
|
||||
storage.removeItem(USERNAME_KEY)
|
||||
storage.removeItem(COMPANY_NAME_STORAGE_KEY)
|
||||
storage.setItem(AUTO_LOGIN_KEY, '0')
|
||||
storage.setItem(KICK_NOTICE_KEY, '1')
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user