feat(jd): 京东店铺分类按数据权限分组隔离(V203)
用户口径:不同组不能看到跨组的分类;当前组只管理员可以编辑分类,同组普通号可以进弹窗看但不能增删; 平台超管全量可见可编辑,公司超管管本公司全部组;归类也按组隔离且不再置人工编辑锁。 数据模型:biz_jd_product_group 加 owner_group_id(NOT NULL DEFAULT 0, uk_company_owner_name(company_id, owner_group_id, name));新增 biz_jd_product_group_assign (product_id, owner_group_id, category_id, uk_product_owner) 承接归类,同一商品各组可各自归类; biz_jd_product.group_id 保留但零读零写。 权限:新增 JdCategoryScopeService(GET /api/admin/jd-product-groups/scope 回可见组 + 每组 editable) 四档矩阵;分类增删改与归类走 requireWritableGroup 403;商品行写(编辑/删除)仍只平台超管。 读面:列表/筛选/详情/归类一律按 owner_group_id,分类筛选 group_id 走归属表 EXISTS 下推 (不在 Java 侧 filter);用户端 /api/jd-collect/groups 按登录用户可见组收窄。 前端:工具栏「分组」下拉(多组才渲染,单组锁定显示);店铺分类弹窗对所有有该页菜单权限的人可见, 但按 editable 隐藏新建/改名/删除/勾选/归入移出;编辑抽屉「分类」下拉下线;只读提示改为 「只读:编辑/删除仅超级管理员可用;分类由本组管理员维护」。 验证:后端 mvn -o test 整量 5610 例 0 失败 19 skip;后管 npx vue-tsc 绿 / node --test 1919 绿 / vitest 132 绿;用户端 vue-tsc 绿;python scripts/_push_gate.py --fast overall=pass。 迁移实跑与真机页面验收留发版窗口(本机无 MySQL/OSS);V203 需与另一路 V202 同窗口发布。
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东公共商品库:支持店铺分类和京麦类目组合筛选,分类管理在弹窗中完成。 */
|
||||
/** 京东公共商品库:支持店铺分类和京麦类目组合筛选,分类管理在弹窗中完成。
|
||||
* V203(2026-11-16 用户口径):分类按「数据权限分组」隔离——不同组看不到彼此的分类,
|
||||
* 组管理员可建/改/删分类并归类,同组普通号可开弹窗看但只读;平台超管全量可见可编辑;
|
||||
* 能看多组的人用工具栏「分组」下拉切换当前组(只有一组时锁定显示)。 */
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import {
|
||||
deleteJdProducts,
|
||||
fetchJdCategoryScope,
|
||||
fetchJdProductCategories,
|
||||
fetchJdProductGroups,
|
||||
fetchJdProductList,
|
||||
type JdCategoryGroupOption,
|
||||
type JdProductCategoryOption,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
@@ -24,9 +29,8 @@ import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
|
||||
/** 写权限口径(2026-11-16 用户口径「京东数据库只有超管有编辑删除权限」):读按菜单权限可见,
|
||||
* 写(编辑/删除/勾选批量删/店铺分类与批量归类)只对平台超级管理员渲染;后端同口径兜底 403
|
||||
* (公司超管不在内,判据是站点 super_admin)。 */
|
||||
/** 写权限口径(2026-11-16 用户口径):商品行写(编辑/删除/勾选批量删)只对平台超级管理员渲染;
|
||||
* 分类写(建/改名/删除、归类)由 scope 的每组 editable 决定(本组管理员/公司超管/平台超管)。 */
|
||||
const session = useAdminSessionStore()
|
||||
const isSuperAdmin = computed(() => session.isSuperAdmin)
|
||||
|
||||
@@ -37,8 +41,12 @@ const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const filter = reactive(createJdProductFilterState())
|
||||
/** 分组下拉选项:分组全平台一份(公共),进页取一次即可;选项失败不拦列表,只回空下拉
|
||||
* (可见「全部分组」)。 */
|
||||
/** 分类作用域(V203):可见分组 + 每组可写标记。失败静默回空作用域(分类列全空但商品照常)。 */
|
||||
const categoryScope = ref<JdCategoryGroupOption[]>([])
|
||||
const scopeDefaultGroupId = ref(0)
|
||||
/** 当前分组(数据权限分组 id):分类列/分类筛选/分类管理的共同作用域。 */
|
||||
const ownerGroupId = ref(0)
|
||||
/** 当前分组的分类下拉选项(按 ownerGroupId 取,切组即换)。 */
|
||||
const groupOptions = ref<JdProductGroup[]>([])
|
||||
/** 类目下拉选项(京麦末级类目):与当前行集同源(公共库全量);失败静默回空。 */
|
||||
const categoryOptions = ref<JdProductCategoryOption[]>([])
|
||||
@@ -50,6 +58,15 @@ const groupDialogVisible = ref(false)
|
||||
const editItem = ref<JdProductItem | null>(null)
|
||||
const editVisible = ref(false)
|
||||
|
||||
/** 当前分组的下拉项(带 editable)——分类写入口与「店铺分类」弹窗的可管理档都读它。 */
|
||||
const currentGroupOption = computed<JdCategoryGroupOption | null>(() =>
|
||||
categoryScope.value.find((group) => group.id === ownerGroupId.value) || null)
|
||||
const currentGroupName = computed(() => currentGroupOption.value?.name || '')
|
||||
/** 分类可管理(建/改名/删除/归类):本组管理员、公司超管、平台超管(后端 scope 判)。 */
|
||||
const canManageCategories = computed(() => currentGroupOption.value?.editable === true)
|
||||
/** 分组下拉只在能看多组时才渲染;只有一组(含无可见组)时按锁定态展示。 */
|
||||
const canSwitchGroup = computed(() => categoryScope.value.length > 1)
|
||||
|
||||
function openEdit(item: JdProductItem): void {
|
||||
editItem.value = item
|
||||
editVisible.value = true
|
||||
@@ -74,10 +91,26 @@ function clampJdSyncedRange(): void {
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
|
||||
/** 分组选项失败静默回空——分组只是筛选项,不该让它把首屏行集一起拖死。 */
|
||||
/** 作用域 → 分组列表 → 该组分类:失败一律静默降级(分类只是筛选/归类面,不拦首屏行集)。 */
|
||||
async function loadCategoryScope(): Promise<void> {
|
||||
try {
|
||||
const scope = await fetchJdCategoryScope()
|
||||
categoryScope.value = scope.groups
|
||||
scopeDefaultGroupId.value = scope.defaultGroupId ?? 0
|
||||
} catch {
|
||||
categoryScope.value = []
|
||||
scopeDefaultGroupId.value = 0
|
||||
}
|
||||
// 当前分组:保留用户已选(仍可见时),否则回默认(可见组第一项)。
|
||||
const keep = categoryScope.value.some((group) => group.id === ownerGroupId.value)
|
||||
if (!keep) ownerGroupId.value = scopeDefaultGroupId.value
|
||||
await loadGroupOptions()
|
||||
}
|
||||
|
||||
/** 当前分组的分类选项:按 ownerGroupId 取(跨组不可见);失败静默回空下拉。 */
|
||||
async function loadGroupOptions(): Promise<void> {
|
||||
try {
|
||||
groupOptions.value = await fetchJdProductGroups()
|
||||
groupOptions.value = await fetchJdProductGroups(ownerGroupId.value)
|
||||
} catch {
|
||||
groupOptions.value = []
|
||||
}
|
||||
@@ -92,7 +125,17 @@ async function loadCategoryOptions(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 分组管理弹窗里做过变更:分组下拉与列表都刷新(删除分组后行集的 groupName 会变)。 */
|
||||
/** 切换「分组」下拉:分类筛选(属于上一组的分类)清空,分类选项换成本组,回第一页重取。 */
|
||||
async function changeOwnerGroup(next: number): Promise<void> {
|
||||
if (next === ownerGroupId.value) return
|
||||
ownerGroupId.value = next
|
||||
filter.groupId = ''
|
||||
await loadGroupOptions()
|
||||
page.value = 1
|
||||
await load()
|
||||
}
|
||||
|
||||
/** 分类弹窗里做过变更:分类下拉与列表都刷新(删除分类后行集的 groupName 会变)。 */
|
||||
async function onGroupChanged(deletedGroupId?: number): Promise<void> {
|
||||
if (deletedGroupId && filter.groupId === String(deletedGroupId)) filter.groupId = ''
|
||||
await loadGroupOptions()
|
||||
@@ -111,6 +154,7 @@ async function load(): Promise<void> {
|
||||
titleKeyword: filter.titleKeyword,
|
||||
category: filter.category,
|
||||
groupId: filter.groupId,
|
||||
ownerGroupId: ownerGroupId.value,
|
||||
syncedFrom: filter.syncedFrom,
|
||||
syncedTo: filter.syncedTo,
|
||||
})
|
||||
@@ -232,10 +276,12 @@ async function removeMany(picked: JdProductItem[], message: string): Promise<voi
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadGroupOptions()
|
||||
onMounted(async () => {
|
||||
// 先解析作用域再取列表:首屏的 owner_group_id 必须与分类下拉同一个组(铁律 30 同形——
|
||||
// 不要先发一条不带 owner_group_id 的列表请求再补,两次请求会落在不同默认组上)。
|
||||
await loadCategoryScope()
|
||||
void loadCategoryOptions()
|
||||
void load()
|
||||
await load()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -283,9 +329,21 @@ onMounted(() => {
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<div class="jd-toolbar">
|
||||
<span class="jd-summary">共 {{ total }} 条京东商品</span>
|
||||
<!-- 写入口只对平台超管渲染(2026-11-16「只有超管有编辑删除权限」):非超管看到只读提示。 -->
|
||||
<span v-if="!isSuperAdmin" class="jd-readonly-tip">只读:编辑/删除仅超级管理员可用</span>
|
||||
<button v-if="isSuperAdmin" class="btn btn-secondary" type="button" @click="groupDialogVisible = true">店铺分类</button>
|
||||
<!-- 当前分组(V203):能看多组的人(平台超管/公司超管)用下拉切换;只有一组时锁定显示组名。
|
||||
分组是分类列/分类筛选/分类管理的作用域,不是筛选条件 ⇒ 「重置」不清它。 -->
|
||||
<select
|
||||
v-if="canSwitchGroup"
|
||||
:value="ownerGroupId"
|
||||
aria-label="当前分组"
|
||||
@change="changeOwnerGroup(Number(($event.target as HTMLSelectElement).value))"
|
||||
>
|
||||
<option v-for="group in categoryScope" :key="group.id" :value="group.id">{{ group.label }}</option>
|
||||
</select>
|
||||
<span v-else-if="currentGroupName" class="jd-group-locked" title="你的数据权限内只有这一个分组">分组:{{ currentGroupName }}</span>
|
||||
<!-- 商品行写只对平台超管;分类写由当前分组 editable 决定(本组管理员/公司超管/平台超管)。
|
||||
非超管看到只读提示,但「店铺分类」弹窗照常可开(同组普通号只读查看)。 -->
|
||||
<span v-if="!isSuperAdmin" class="jd-readonly-tip">只读:编辑/删除仅超级管理员可用;分类由本组管理员维护</span>
|
||||
<button class="btn btn-secondary" type="button" @click="groupDialogVisible = true">店铺分类</button>
|
||||
<select v-model="filter.groupId" aria-label="筛选店铺分类" @change="apply">
|
||||
<option value="">全部分类</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
@@ -369,7 +427,16 @@ onMounted(() => {
|
||||
<OldPagination :total="total" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
|
||||
</section>
|
||||
|
||||
<JdProductGroupDialog :visible="groupDialogVisible" :category-options="categoryOptions" @close="groupDialogVisible = false" @changed="onGroupChanged" />
|
||||
<JdProductGroupDialog
|
||||
:visible="groupDialogVisible"
|
||||
:category-options="categoryOptions"
|
||||
:owner-group-id="ownerGroupId"
|
||||
:owner-group-name="currentGroupName"
|
||||
:can-manage="canManageCategories"
|
||||
:can-assign="canManageCategories"
|
||||
@close="groupDialogVisible = false"
|
||||
@changed="onGroupChanged"
|
||||
/>
|
||||
<JdProductDetailDrawer
|
||||
:item="detailItem"
|
||||
:visible="detailVisible"
|
||||
|
||||
Reference in New Issue
Block a user