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) {
|
||||
|
||||
Reference in New Issue
Block a user