61ab844e5d
用户口径:不同组不能看到跨组的分类;当前组只管理员可以编辑分类,同组普通号可以进弹窗看但不能增删; 平台超管全量可见可编辑,公司超管管本公司全部组;归类也按组隔离且不再置人工编辑锁。 数据模型: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 同窗口发布。
455 lines
13 KiB
Vue
455 lines
13 KiB
Vue
<script setup lang="ts">
|
||
/** 店铺分类弹窗右栏:按京麦类目和标题筛选商品,勾选后归入左侧目标或移出分类。
|
||
* V203(2026-11-16 用户口径):归类写「本组」的归属行(biz_jd_product_group_assign,
|
||
* 一组一商品一行),行集与归入/移出都带当前分组 ownerGroupId,同一商品在其他组可另归一类;
|
||
* 归类不再置人工编辑锁(采集照常更新价格/库存)。`canAssign=false`(同组普通号只读)
|
||
* 时勾选列与底部两个写按钮都不渲染,只留行集浏览。 */
|
||
import { computed, onMounted, ref, watch } from 'vue'
|
||
import JdCategoryCascader from './JdCategoryCascader.vue'
|
||
import { batchAssignJdProductGroup, fetchJdProductList } from './jd-product-api.ts'
|
||
import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.ts'
|
||
import type { JdProductItem } from './jd-product-model.ts'
|
||
import OldPagination from '@/components/OldPagination.vue'
|
||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||
|
||
const props = defineProps<{
|
||
/** 左栏点亮的分类=归类目标;null=尚未点亮(「归入」按钮置灰)。 */
|
||
selectedGroup: JdProductGroup | null
|
||
categoryOptions: JdProductCategoryOption[]
|
||
refreshVersion: number
|
||
/** 当前数据权限分组:行集的分类列与归类落点都以它为作用域。 */
|
||
ownerGroupId: number
|
||
/** 本账号可归类(本组管理员/公司超管/平台超管);false=只读浏览。 */
|
||
canAssign: boolean
|
||
}>()
|
||
|
||
const emit = defineEmits<{ (event: 'changed'): void }>()
|
||
|
||
const category = ref('')
|
||
const keyword = ref('')
|
||
const PRODUCT_PAGE_SIZE = 20
|
||
const products = ref<JdProductItem[]>([])
|
||
const productTotal = ref(0)
|
||
const productPage = ref(1)
|
||
const productsLoading = ref(false)
|
||
const productsError = ref('')
|
||
/** 本页勾选集(按行 id):切范围/翻页/重取后清空,防「看不见的勾选被一起归类」。 */
|
||
const selectedProductIds = ref<Set<number>>(new Set())
|
||
const assigning = ref(false)
|
||
|
||
const selectedCount = computed(() => selectedProductIds.value.size)
|
||
/** 归入所选分类:必须先在左侧点亮一个分类且有勾选行。 */
|
||
const removableIds = computed(() => products.value.filter(row => selectedProductIds.value.has(row.id) && row.groupId != null && row.groupId > 0).map(row => row.id))
|
||
/** 可提交「归入」(props.canAssign 是权限,这里的名字避开与 prop 同名)。 */
|
||
const canSubmitAssign = computed(() => props.canAssign && !!props.selectedGroup && selectedCount.value > 0 && !assigning.value && !productsLoading.value)
|
||
const canRemove = computed(() => props.canAssign && removableIds.value.length > 0 && !assigning.value && !productsLoading.value)
|
||
const allSelected = computed(() =>
|
||
products.value.length > 0 && products.value.every((row) => selectedProductIds.value.has(row.id)))
|
||
|
||
let requestVersion = 0
|
||
async function loadProducts(): Promise<void> {
|
||
const request = ++requestVersion
|
||
selectedProductIds.value = new Set()
|
||
productsLoading.value = true
|
||
productsError.value = ''
|
||
try {
|
||
const result = await fetchJdProductList({
|
||
page: productPage.value,
|
||
pageSize: PRODUCT_PAGE_SIZE,
|
||
titleKeyword: keyword.value.trim(),
|
||
category: category.value,
|
||
ownerGroupId: props.ownerGroupId,
|
||
})
|
||
if (request !== requestVersion) return
|
||
products.value = result.items
|
||
productTotal.value = result.total
|
||
if (result.page >= 1) productPage.value = result.page
|
||
selectedProductIds.value = new Set()
|
||
} catch (error) {
|
||
if (request !== requestVersion) return
|
||
productsError.value = requestErrorMessage(error) || '商品列表加载失败'
|
||
products.value = []
|
||
productTotal.value = 0
|
||
selectedProductIds.value = new Set()
|
||
} finally {
|
||
if (request === requestVersion) productsLoading.value = false
|
||
}
|
||
}
|
||
|
||
watch(() => props.refreshVersion, () => { void loadProducts() })
|
||
|
||
function pickCategory(next: string): void {
|
||
category.value = next
|
||
productPage.value = 1
|
||
void loadProducts()
|
||
}
|
||
|
||
function searchProducts(): void {
|
||
productPage.value = 1
|
||
void loadProducts()
|
||
}
|
||
|
||
function changeProductPage(next: number): void {
|
||
if (next < 1 || next === productPage.value) return
|
||
productPage.value = next
|
||
void loadProducts()
|
||
}
|
||
|
||
function toggleSelect(row: JdProductItem, checked: boolean): void {
|
||
const next = new Set(selectedProductIds.value)
|
||
if (checked) next.add(row.id)
|
||
else next.delete(row.id)
|
||
selectedProductIds.value = next
|
||
}
|
||
|
||
function toggleSelectAll(checked: boolean): void {
|
||
selectedProductIds.value = checked ? new Set(products.value.map((row) => row.id)) : new Set()
|
||
}
|
||
|
||
/** 勾选行 → 归入左栏点亮的分类(写本组归属行)。成功后分类商品数(父件)与右栏行集都刷新
|
||
* (归类过的行离开「未分类」)。 */
|
||
async function assignToSelected(): Promise<void> {
|
||
const target = props.selectedGroup
|
||
if (!target || !canSubmitAssign.value) return
|
||
assigning.value = true
|
||
productsError.value = ''
|
||
try {
|
||
const updated = await batchAssignJdProductGroup([...selectedProductIds.value], target.id, props.ownerGroupId)
|
||
showAdminFeedback(`已把 ${updated} 个商品归入「${target.name}」`, 'success')
|
||
emit('changed')
|
||
await loadProducts()
|
||
} catch (error) {
|
||
productsError.value = requestErrorMessage(error) || '归类失败,请稍后重试'
|
||
} finally {
|
||
assigning.value = false
|
||
}
|
||
}
|
||
|
||
/** 勾选行 → 移出本组分类(删本组归属行,商品回到未分类;别组的归类不受影响)。 */
|
||
async function removeFromCategory(): Promise<void> {
|
||
if (!canRemove.value) return
|
||
assigning.value = true
|
||
productsError.value = ''
|
||
try {
|
||
const updated = await batchAssignJdProductGroup(removableIds.value, null, props.ownerGroupId)
|
||
showAdminFeedback(`已把 ${updated} 个商品移出分类`, 'success')
|
||
emit('changed')
|
||
await loadProducts()
|
||
} catch (error) {
|
||
productsError.value = requestErrorMessage(error) || '移出分类失败,请稍后重试'
|
||
} finally {
|
||
assigning.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
void loadProducts()
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<section class="right-pane">
|
||
<div class="product-toolbar">
|
||
<JdCategoryCascader class="assign-category" :model-value="category" :options="categoryOptions" tree-only @change="pickCategory" />
|
||
<input v-model="keyword" type="text" class="keyword-input" placeholder="标题关键字" @keyup.enter="searchProducts" />
|
||
<button class="btn btn-small" type="button" @click="searchProducts">查询</button>
|
||
</div>
|
||
<p v-if="productsError" class="pane-error">
|
||
{{ productsError }}
|
||
<button class="btn btn-secondary btn-mini" type="button" @click="loadProducts">重试</button>
|
||
</p>
|
||
|
||
<div class="product-list">
|
||
<table v-if="products.length">
|
||
<thead>
|
||
<tr>
|
||
<th v-if="canAssign" class="col-check"><input type="checkbox" :disabled="productsLoading || assigning" :checked="allSelected" @change="toggleSelectAll(($event.target as HTMLInputElement).checked)" /></th>
|
||
<th>商品信息</th>
|
||
<th class="col-group">当前分类</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-for="row in products" :key="row.id">
|
||
<td v-if="canAssign" class="col-check">
|
||
<input
|
||
type="checkbox"
|
||
:disabled="productsLoading || assigning"
|
||
:checked="selectedProductIds.has(row.id)"
|
||
@change="toggleSelect(row, ($event.target as HTMLInputElement).checked)"
|
||
/>
|
||
</td>
|
||
<td>
|
||
<div class="product-cell">
|
||
<img v-if="row.mainImageUrl" class="product-thumb" :src="row.mainImageUrl" alt="" loading="lazy" />
|
||
<span v-else class="product-thumb product-thumb-empty">无图</span>
|
||
<div class="product-body">
|
||
<div class="product-title" :title="row.title">{{ row.title || '-' }}</div>
|
||
<div class="product-meta">商品编码:{{ row.productCode || '-' }}</div>
|
||
</div>
|
||
</div>
|
||
</td>
|
||
<td class="col-group" :title="row.groupName || ''">{{ row.groupName || '未分类' }}</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p v-else-if="productsLoading" class="pane-tip">加载中...</p>
|
||
<p v-else-if="!productsError" class="pane-tip">没有符合条件的商品</p>
|
||
</div>
|
||
|
||
<div v-if="canAssign" class="product-footer">
|
||
<span class="pick-summary">已勾选 {{ selectedCount }} 个商品</span>
|
||
<div class="footer-actions">
|
||
<button class="btn btn-small" type="button" :disabled="!canSubmitAssign" @click="assignToSelected">
|
||
{{ assigning ? '归类中...' : selectedGroup ? `归入「${selectedGroup.name}」` : '归入所选分类' }}
|
||
</button>
|
||
<button class="btn btn-danger btn-small" type="button" :disabled="!canRemove" @click="removeFromCategory">移出分类</button>
|
||
</div>
|
||
</div>
|
||
<OldPagination
|
||
:total="productTotal"
|
||
:page="productPage"
|
||
:page-size="PRODUCT_PAGE_SIZE"
|
||
:sizes="[PRODUCT_PAGE_SIZE]"
|
||
:jump="false"
|
||
@change="changeProductPage"
|
||
/>
|
||
</section>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.right-pane {
|
||
flex: 1;
|
||
min-width: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding-left: 14px;
|
||
}
|
||
.product-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
margin-bottom: 10px;
|
||
}
|
||
.assign-category {
|
||
flex: 0 0 190px;
|
||
}
|
||
.scope-tabs {
|
||
display: flex;
|
||
border: 1px solid #c7d7e5;
|
||
border-radius: 9px;
|
||
overflow: hidden;
|
||
flex-shrink: 0;
|
||
}
|
||
.scope-tabs button {
|
||
min-height: 34px;
|
||
padding: 5px 14px;
|
||
border: 0;
|
||
border-right: 1px solid #e7eef5;
|
||
background: #ffffff;
|
||
color: #5b6f83;
|
||
font-family: inherit;
|
||
font-size: 13px;
|
||
cursor: pointer;
|
||
}
|
||
.scope-tabs button:last-child {
|
||
border-right: 0;
|
||
}
|
||
.scope-tabs button:hover:not(:disabled):not(.on) {
|
||
background: #edf5fb;
|
||
color: #2f5d8b;
|
||
}
|
||
.scope-tabs button.on {
|
||
background: #4f78a5;
|
||
color: #ffffff;
|
||
}
|
||
.scope-tabs button:disabled {
|
||
color: #9baaba;
|
||
background: #eef3f7;
|
||
cursor: not-allowed;
|
||
}
|
||
.keyword-input {
|
||
flex: 1;
|
||
min-width: 0;
|
||
min-height: 36px;
|
||
padding: 6px 12px;
|
||
border: 1px solid #cbd9e6;
|
||
border-radius: 9px;
|
||
background: #f8fbfd;
|
||
color: #24384d;
|
||
font-size: 13.5px;
|
||
font-family: inherit;
|
||
outline: none;
|
||
}
|
||
.keyword-input:focus {
|
||
background: #ffffff;
|
||
border-color: #5f85ad;
|
||
}
|
||
.pane-error {
|
||
margin: 0 0 8px;
|
||
padding: 10px 12px;
|
||
border: 1px solid #f0c9c2;
|
||
border-radius: 10px;
|
||
background: #fdf1ef;
|
||
color: #a04432;
|
||
font-size: 13px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
/* 错误条右缘的重试入口:一条真能办成事的出口(重试绑页内 loadProducts,守卫 load-failure-visibility 钉)。 */
|
||
.pane-error .btn {
|
||
margin-left: auto;
|
||
flex-shrink: 0;
|
||
}
|
||
.pane-tip {
|
||
margin: 10px 2px;
|
||
color: #8293a5;
|
||
font-size: 13px;
|
||
}
|
||
.product-list {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow-y: auto;
|
||
border: 1px solid #dbe5ee;
|
||
border-radius: 10px;
|
||
background: #ffffff;
|
||
}
|
||
.product-list table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
}
|
||
.product-list th,
|
||
.product-list td {
|
||
padding: 8px 12px;
|
||
text-align: left;
|
||
font-size: 13px;
|
||
line-height: 1.45;
|
||
border-bottom: 1px solid #e7eef5;
|
||
vertical-align: middle;
|
||
}
|
||
.product-list th {
|
||
position: sticky;
|
||
top: 0;
|
||
background: #edf4fa;
|
||
color: #4e6479;
|
||
font-size: 12.5px;
|
||
font-weight: 600;
|
||
letter-spacing: 0.4px;
|
||
}
|
||
.product-list tbody tr:hover td {
|
||
background: #f1f7fb;
|
||
}
|
||
.product-list tbody tr:last-child td {
|
||
border-bottom: 0;
|
||
}
|
||
.col-check {
|
||
width: 42px;
|
||
}
|
||
.col-check input {
|
||
margin: 0;
|
||
}
|
||
.col-group {
|
||
width: 140px;
|
||
color: #7b8a99;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.product-cell {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 10px;
|
||
min-width: 0;
|
||
}
|
||
.product-thumb {
|
||
flex-shrink: 0;
|
||
width: 44px;
|
||
height: 44px;
|
||
object-fit: cover;
|
||
border: 1px solid #d8e3ee;
|
||
border-radius: 6px;
|
||
background: #f2f7fb;
|
||
}
|
||
.product-thumb-empty {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #8293a5;
|
||
font-size: 12px;
|
||
}
|
||
.product-body {
|
||
min-width: 0;
|
||
}
|
||
.product-title {
|
||
color: #24384d;
|
||
font-size: 13px;
|
||
line-height: 1.4;
|
||
display: -webkit-box;
|
||
-webkit-line-clamp: 2;
|
||
-webkit-box-orient: vertical;
|
||
overflow: hidden;
|
||
word-break: break-all;
|
||
}
|
||
.product-meta {
|
||
margin-top: 2px;
|
||
color: #7b8a99;
|
||
font-size: 12px;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
.product-footer {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-top: 10px;
|
||
}
|
||
.pick-summary {
|
||
color: #5b6f83;
|
||
font-size: 13px;
|
||
white-space: nowrap;
|
||
}
|
||
.footer-actions {
|
||
display: flex;
|
||
gap: 10px;
|
||
margin-left: auto;
|
||
}
|
||
.btn {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
min-height: 38px;
|
||
padding: 7px 16px;
|
||
border: 1px solid #4f78a5;
|
||
border-radius: 9px;
|
||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||
color: #ffffff;
|
||
font-family: inherit;
|
||
font-size: 13px;
|
||
cursor: pointer;
|
||
}
|
||
.btn:disabled {
|
||
cursor: not-allowed;
|
||
opacity: 0.6;
|
||
}
|
||
.btn-small {
|
||
min-height: 34px;
|
||
padding: 5px 13px;
|
||
font-size: 12.5px;
|
||
}
|
||
.btn-danger {
|
||
background: #ffffff;
|
||
color: #a04432;
|
||
border-color: #e4b3a8;
|
||
}
|
||
.btn-danger:hover:not(:disabled) {
|
||
background: #fdf1ef;
|
||
border-color: #d08a7b;
|
||
}
|
||
/* 弹窗里的分页贴右、收紧行高(页内版式在弹窗内偏大)。 */
|
||
:deep(.old-pagination) {
|
||
margin-top: 10px;
|
||
}
|
||
</style>
|