feat(jd): 京东工具台纳入后台菜单权限——V209 app菜单组jd_tools+两子行, 预授权沿V163全授组行; 用户端工具台卡片/首页入口按权限显隐(接口失败兜底全显, 同亚马逊形状); 首页computePermissionState抽薄home-permission.ts并修只授京东误亮亚马逊的兜底缺陷
This commit is contained in:
@@ -64,9 +64,10 @@
|
||||
data-column-key="wb"
|
||||
>视频</router-link>
|
||||
|
||||
<!-- 京东入口:一级入口,不挂在亚马逊/视频的权限树里(京东工具台自带两个菜单,
|
||||
权限收口在工具台内部;入口恒显示,避免账号还没配京东菜单时入口凭空消失)。 -->
|
||||
<!-- 京东入口(V209 起纳入 app 菜单权限):jd_tools 组行或其子项/祖先命中即可见。
|
||||
权限接口异常时退回显示(与亚马逊/视频入口同一兜底),不空白。 -->
|
||||
<router-link
|
||||
v-if="canShow.jd"
|
||||
:to="jdHref"
|
||||
class="entrance-btn jd"
|
||||
:class="{ disabled: !jdHref }"
|
||||
@@ -81,7 +82,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { restoreLoginUser } from '@/shared/auth/ensure-auth'
|
||||
import { getCurrentUserAppColumnRaw, readCachedAppColumnPermissions, type PermissionMenuItem } from '@/shared/api/permission'
|
||||
import { getCurrentUserAppColumnRaw, readCachedAppColumnPermissions } from '@/shared/api/permission'
|
||||
import { computePermissionState, type PermissionState } from './home-permission'
|
||||
import { useVersionUpdate } from '@/shared/composables/useVersionUpdate'
|
||||
import UpdateProgressBar from '@/shared/components/UpdateProgressBar.vue'
|
||||
import UpdateLogList from '@/shared/components/UpdateLogList.vue'
|
||||
@@ -116,10 +118,10 @@ const {
|
||||
// 桌面端原 Flask /logout 已随瘦身下线:统一跳登录页并清本地 token(/login?logout=1)
|
||||
const logoutHref = computed(() => `${resolvePageHref('/new_web_source/login.html')}?logout=1`)
|
||||
|
||||
// 桌面端首页仅保留一级入口:亚马逊 / 视频;图片已收进视频页(/image-video)二级菜单。
|
||||
// 桌面端首页仅保留一级入口:亚马逊 / 视频 / 京东;图片已收进视频页(/image-video)二级菜单。
|
||||
// 入口先乐观显示(接口返回后按权限隐藏),避免权限接口慢时首页入口空白"点不了"。
|
||||
type PermissionState = { amazon: boolean; video: boolean }
|
||||
const permissionState = ref<PermissionState>({ amazon: true, video: true })
|
||||
// 权限计算在 ./home-permission(纯函数,tests/desktop-home-permission.test.ts 直测)。
|
||||
const permissionState = ref<PermissionState>({ amazon: true, video: true, jd: true })
|
||||
const permissionUnavailable = ref(false)
|
||||
|
||||
const amazonHref = computed(() => resolvePageHref('/new_web_source/amazon-console.html'))
|
||||
@@ -128,7 +130,7 @@ const videoHref = computed(() => resolvePageHref('/new_web_source/image-video.ht
|
||||
const jdHref = computed(() => resolvePageHref('/new_web_source/jd-console.html'))
|
||||
|
||||
const canShow = computed(() =>
|
||||
permissionUnavailable.value ? { amazon: true, video: true } : permissionState.value,
|
||||
permissionUnavailable.value ? { amazon: true, video: true, jd: true } : permissionState.value,
|
||||
)
|
||||
|
||||
function getUid() {
|
||||
@@ -137,36 +139,6 @@ function getUid() {
|
||||
return Number.isFinite(numeric) && numeric > 0 ? String(numeric) : ''
|
||||
}
|
||||
|
||||
function computePermissionState(items: PermissionMenuItem[]): PermissionState {
|
||||
const allowedKeys: string[] = []
|
||||
const allowedColumnKeys: string[] = []
|
||||
const allowedRootKeys: string[] = []
|
||||
let hasRootMetadata = false
|
||||
const push = (list: string[], value: unknown) => {
|
||||
const key = String(value || '').trim().toLowerCase()
|
||||
if (key && list.indexOf(key) < 0) list.push(key)
|
||||
}
|
||||
;(items || []).forEach((item) => {
|
||||
push(allowedColumnKeys, item.columnKey)
|
||||
push(allowedColumnKeys, item.column_key)
|
||||
const root = item.rootColumnKey || item.root_column_key
|
||||
if (root) {
|
||||
hasRootMetadata = true
|
||||
push(allowedRootKeys, root)
|
||||
}
|
||||
;[item.columnKey, item.column_key, item.routePath, item.route_path].forEach((v) => push(allowedKeys, v))
|
||||
})
|
||||
const videoVisible = allowedKeys.indexOf('wb') >= 0
|
||||
let amazonVisible =
|
||||
allowedRootKeys.indexOf('brand_front_tools') >= 0 ||
|
||||
allowedRootKeys.indexOf('brand_operation_tools') >= 0 ||
|
||||
allowedRootKeys.indexOf('brand_logistics_tools') >= 0
|
||||
if (!hasRootMetadata) {
|
||||
amazonVisible = allowedColumnKeys.some((key) => key !== 'wb')
|
||||
}
|
||||
return { amazon: amazonVisible, video: videoVisible }
|
||||
}
|
||||
|
||||
async function loadPermissions() {
|
||||
const currentUid = getUid()
|
||||
if (!currentUid) {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 桌面首页一级入口的权限计算(亚马逊 / 视频 / 京东)。
|
||||
*
|
||||
* 2026-11-17 自 DesktopHomePage.vue 原样抽薄(逻辑逐字未动):这段判据此前只活在 SFC 里、
|
||||
* 零测试;V209 把京东纳入 app 菜单权限并顺手收紧"只授京东的账号被误判亚马逊可见"的兜底,
|
||||
* 必须有用例钉住,故抽成纯函数模块由 tests/desktop-home-permission.test.ts 直测。
|
||||
* 数据源不变:shared/api/permission 的原始菜单项(含 localStorage 缓存路径),页面不得直连 /newApi。
|
||||
*/
|
||||
import type { PermissionMenuItem } from '@/shared/api/permission'
|
||||
|
||||
/** 京东侧权限键(V209 app 菜单):组行 jd_tools + 子行 jd-collect/jd-publish(route slug jd-tools)。 */
|
||||
export const JD_PERMISSION_KEYS: ReadonlySet<string> = new Set([
|
||||
'jd_tools',
|
||||
'jd-tools',
|
||||
'jd-collect',
|
||||
'jd-publish',
|
||||
])
|
||||
|
||||
export type PermissionState = { amazon: boolean; video: boolean; jd: boolean }
|
||||
|
||||
export function computePermissionState(items: PermissionMenuItem[]): PermissionState {
|
||||
const allowedKeys: string[] = []
|
||||
const allowedColumnKeys: string[] = []
|
||||
const allowedRootKeys: string[] = []
|
||||
let hasRootMetadata = false
|
||||
const push = (list: string[], value: unknown) => {
|
||||
const key = String(value || '').trim().toLowerCase()
|
||||
if (key && list.indexOf(key) < 0) list.push(key)
|
||||
}
|
||||
;(items || []).forEach((item) => {
|
||||
push(allowedColumnKeys, item.columnKey)
|
||||
push(allowedColumnKeys, item.column_key)
|
||||
const root = item.rootColumnKey || item.root_column_key
|
||||
if (root) {
|
||||
hasRootMetadata = true
|
||||
push(allowedRootKeys, root)
|
||||
}
|
||||
;[item.columnKey, item.column_key, item.routePath, item.route_path].forEach((v) => push(allowedKeys, v))
|
||||
})
|
||||
const videoVisible = allowedKeys.indexOf('wb') >= 0
|
||||
// 京东入口:组键命中(V209 预授权授的就是组行),或只授了子项时靠行的 root_column_key 祖先元数据命中。
|
||||
const jdVisible = allowedKeys.indexOf('jd_tools') >= 0 || allowedRootKeys.indexOf('jd_tools') >= 0
|
||||
let amazonVisible =
|
||||
allowedRootKeys.indexOf('brand_front_tools') >= 0 ||
|
||||
allowedRootKeys.indexOf('brand_operation_tools') >= 0 ||
|
||||
allowedRootKeys.indexOf('brand_logistics_tools') >= 0
|
||||
if (!hasRootMetadata) {
|
||||
// 旧权限接口不带 root 元数据时的兜底。原式只排除 'wb':V209 后"只授了京东"的账号会
|
||||
// 在这里被误判亚马逊可见(进去是空卡片墙),顺手把京东键一并排除——同形债不再留第二份。
|
||||
amazonVisible = allowedColumnKeys.some((key) => key !== 'wb' && !JD_PERMISSION_KEYS.has(key))
|
||||
}
|
||||
return { amazon: amazonVisible, video: videoVisible, jd: jdVisible }
|
||||
}
|
||||
@@ -31,11 +31,11 @@
|
||||
<i class="group-dot"></i>
|
||||
<span class="group-name">京东工具</span>
|
||||
<span class="group-desc">采集与上架,两条主线</span>
|
||||
<span class="group-count">{{ JD_TOOLS.length }} 个工具</span>
|
||||
<span class="group-count">{{ visibleTools.length }} 个工具</span>
|
||||
</header>
|
||||
|
||||
<div class="card-grid">
|
||||
<template v-for="tool in JD_TOOLS" :key="tool.id">
|
||||
<template v-for="tool in visibleTools" :key="tool.id">
|
||||
<router-link
|
||||
v-if="tool.href"
|
||||
:to="tool.href"
|
||||
@@ -89,11 +89,15 @@ import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
|
||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||
import { resolvePageHref } from '@/shared/page-prefix'
|
||||
import { JD_TOOLS, type JdToolInfo } from '@/pages/jd/tool-catalog'
|
||||
import { getCurrentUserAppColumnKeys } from '@/shared/api/permission'
|
||||
import { filterJdToolsByPermission, JD_TOOLS, type JdToolInfo } from '@/pages/jd/tool-catalog'
|
||||
|
||||
/** 返回桌面入口首页(亚马逊 / 京东 / 视频 一级入口) */
|
||||
const homeHref = resolvePageHref('/new_web_source/home.html')
|
||||
|
||||
/** 卡片显隐先乐观全量(接口返回后按菜单权限过滤,同 AmazonConsolePage 形状) */
|
||||
const visibleTools = ref<JdToolInfo[]>([...JD_TOOLS])
|
||||
|
||||
const username = ref('admin')
|
||||
const toastText = ref('')
|
||||
let toastTimer: number | undefined
|
||||
@@ -114,9 +118,21 @@ function onPendingClick(tool: JdToolInfo) {
|
||||
showToast(`${tool.name}暂未开通,敬请期待`)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
const localName = (window.localStorage.getItem('username') || '').trim()
|
||||
if (localName) username.value = localName
|
||||
// 判据与 AmazonConsolePage 同形:权限接口异常 ⇒ permissionUnavailable ⇒ 展示全部工具,
|
||||
// 正常 ⇒ 按 app 菜单权限过滤(V209:组键 jd_tools 整放,否则逐项 jd-collect/jd-publish)
|
||||
let allowedKeys: string[] = []
|
||||
let permissionUnavailable = false
|
||||
try {
|
||||
allowedKeys = await getCurrentUserAppColumnKeys()
|
||||
} catch (_error) {
|
||||
permissionUnavailable = true
|
||||
}
|
||||
visibleTools.value = permissionUnavailable
|
||||
? [...JD_TOOLS]
|
||||
: filterJdToolsByPermission(JD_TOOLS, allowedKeys)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
* 2. 商品上架:功能未落地,先按"假菜单"占位(点击提示暂未开通),不发 href。
|
||||
*
|
||||
* 卡片形状照亚马逊工具台(tool-catalog.ts)的 ToolInfo,样式复用同一套深色卡片墙。
|
||||
*
|
||||
* 菜单权限(V209):permissionKeys 与后端 columns(menu_type='app') 的 column_key 逐字一致
|
||||
* (jd_tools 组行 / jd-collect / jd-publish),跨端契约见 tests/jd-console-tool-catalog.test.ts。
|
||||
* 卡片显隐过滤用本文件的 filterJdToolsByPermission——判据与亚马逊 filterGroupsByPermission
|
||||
* 同形(组键命中整放,否则逐项),不直接导入是因为 ToolGroup.key 是 'front'|'ops'|'logi'
|
||||
* 字面量联合且组形状带颜色/工作流等必填件,京东借不了那个类型;改语义两头都要过用例。
|
||||
*/
|
||||
|
||||
export type JdToolInfo = {
|
||||
@@ -19,8 +25,13 @@ export type JdToolInfo = {
|
||||
tag?: string
|
||||
/** 功能页地址;未提供表示暂未开通(占位菜单) */
|
||||
href?: string
|
||||
/** 菜单权限键(小写),与后端 app 菜单 column_key 逐字一致 */
|
||||
permissionKeys: string[]
|
||||
}
|
||||
|
||||
/** app 菜单组键(columns.column_key='jd_tools'):勾中整组放行,同亚马逊 brand_*_tools 语义 */
|
||||
export const JD_GROUP_COLUMN_KEY = 'jd_tools'
|
||||
|
||||
export const JD_TOOLS: ReadonlyArray<JdToolInfo> = [
|
||||
{
|
||||
id: 'jd-collect',
|
||||
@@ -28,15 +39,33 @@ export const JD_TOOLS: ReadonlyArray<JdToolInfo> = [
|
||||
desc: '一键抓取已登录京麦后台的店铺商品(列表 + 详情全部属性 + 图片),导入后台「京东数据库」',
|
||||
tag: '核心',
|
||||
href: '/jd-collect',
|
||||
permissionKeys: ['jd-collect'],
|
||||
},
|
||||
{
|
||||
id: 'jd-publish',
|
||||
name: '商品上架',
|
||||
desc: '把京东数据库里的商品批量上架到京麦店铺(建设中,敬请期待)',
|
||||
tag: '规划中',
|
||||
permissionKeys: ['jd-publish'],
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 按菜单权限过滤京东工具卡片(与亚马逊 tool-catalog.ts::filterGroupsByPermission 同形判据):
|
||||
* 组键 jd_tools 命中则整组放行(预授权授的就是组行,读侧由后端展开子孙);
|
||||
* 否则只放行 permissionKeys 命中的卡片;空权限集 ⇒ 全隐藏。
|
||||
*/
|
||||
export function filterJdToolsByPermission(
|
||||
tools: ReadonlyArray<JdToolInfo>,
|
||||
allowedKeys: ReadonlyArray<string>,
|
||||
): JdToolInfo[] {
|
||||
const allowedSet = new Set(allowedKeys.map((key) => String(key || '').trim().toLowerCase()).filter(Boolean))
|
||||
if (allowedSet.has(JD_GROUP_COLUMN_KEY)) {
|
||||
return [...tools]
|
||||
}
|
||||
return tools.filter((tool) => tool.permissionKeys.some((key) => allowedSet.has(key.toLowerCase())))
|
||||
}
|
||||
|
||||
export const JD_TOOL_MAP: ReadonlyMap<string, JdToolInfo> = new Map(
|
||||
JD_TOOLS.map((tool) => [tool.id, tool] as const),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user