feat(jd): 京东数据库分组改店铺分类+左右分栏弹窗人工归类
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东数据库页(v1.4 Phase 5):公共的京东商品库(2026-11-15 用户定案「不区分公司、属于
|
||||
* 公共的」,分组同亚马逊口径全平台一份),筛选行(店铺/商品编码/标题关键字/分组/类目/
|
||||
* 同步起止 date 对)+查询/重置/管理分组 + 自绘明细表(勾选列+点行开详情抽屉)
|
||||
* 公共的」,分类同亚马逊口径全平台一份),筛选行(店铺/商品编码/标题关键字/分类/类目/
|
||||
* 同步起止 date 对)+查询/重置/店铺分类 + 自绘明细表(勾选列+点行开详情抽屉)
|
||||
* + 删除(单行/批量,先删桶对象、全成功才删库行,确认弹窗点名数量)+ OldPagination。
|
||||
* 公司维度只剩超管的公司 tab(=筛选管理员,非超管没有这个筛选、看到同一份公共全量);
|
||||
* 列表按京麦商品列表样式(2026-11-15 用户口径):店铺/分组前置为第 1/2 列;商品信息列=京麦同款
|
||||
* 列表按京麦商品列表样式(2026-11-15 用户口径):店铺/分类前置为第 1/2 列;商品信息列=京麦同款
|
||||
* 合并布局(主图+图下信息分+标题两行+商品编码/货号+SKU 数标签,编码带一键复制);类目/上架
|
||||
* 时间/京东创建/修改时间仍收详情抽屉基本信息(B104「详情显示全部属性」口径不变)。
|
||||
* 商品状态筛选框/列与导出按钮随 2026-11-15 客户口径「这两个不要/导出也不用」从前端下线
|
||||
@@ -254,7 +254,7 @@ onMounted(() => {
|
||||
<section class="panel-box">
|
||||
<div class="jd-panel-head">
|
||||
<h3>京东数据库</h3>
|
||||
<button class="btn btn-secondary" type="button" @click="groupDialogVisible = true">管理分组</button>
|
||||
<button class="btn btn-secondary" type="button" @click="groupDialogVisible = true">店铺分类</button>
|
||||
</div>
|
||||
|
||||
<div class="jd-filter-row">
|
||||
@@ -271,10 +271,11 @@ onMounted(() => {
|
||||
<input v-model="filter.titleKeyword" type="text" placeholder="输入标题关键字" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<!-- 分组选中即查:选完立刻按该分组过滤刷新(回第一页),不必再点查询。 -->
|
||||
<label>分类</label>
|
||||
<!-- 分类选中即查:选完立刻按该分类过滤刷新(回第一页),不必再点查询。
|
||||
(2026-11-15「分组管理」改「店铺分类」:同一 group 实体,只改界面措辞。) -->
|
||||
<select v-model="filter.groupId" @change="apply">
|
||||
<option value="">全部分组</option>
|
||||
<option value="">全部分类</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -321,7 +322,7 @@ onMounted(() => {
|
||||
<tr>
|
||||
<th style="width: 42px"><input type="checkbox" :checked="allSelected" @change="toggleSelectAll(($event.target as HTMLInputElement).checked)" /></th>
|
||||
<th style="width: 130px">店铺</th>
|
||||
<th style="width: 96px">分组</th>
|
||||
<th style="width: 96px">分类</th>
|
||||
<th>商品信息</th>
|
||||
<th style="width: 76px">总库存</th>
|
||||
<th style="width: 120px">价格</th>
|
||||
@@ -337,7 +338,7 @@ onMounted(() => {
|
||||
<tr v-for="row in rows" :key="row.id" class="jd-row" @click="openDetail(row)">
|
||||
<td @click.stop><input type="checkbox" :checked="selectedIds.has(row.id)" @change="toggleSelect(row, ($event.target as HTMLInputElement).checked)" /></td>
|
||||
<td :title="row.shopName || ''">{{ row.shopName || '-' }}</td>
|
||||
<td :title="row.groupName || ''">{{ row.groupName || '未分组' }}</td>
|
||||
<td :title="row.groupName || ''">{{ row.groupName || '未分类' }}</td>
|
||||
<td class="jd-info-cell">
|
||||
<div class="jd-info-wrap">
|
||||
<div class="jd-info-figure">
|
||||
|
||||
@@ -0,0 +1,469 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东店铺分类弹窗右栏:商品人工归类面板(2026-11-15 从 JdProductGroupDialog 拆出,
|
||||
* 独立件也守可读棘轮的 800 行报警线)。范围切换(全部/未分类/当前分类)+标题关键字搜索
|
||||
* +勾选行 →「归入所选分类」/「移出分类」。归类走批量端点
|
||||
* POST /api/admin/jd-products/batch-assign-group:后端与单行编辑同口径置 manual_locked=1
|
||||
* (归类即人工干预,采集 upsert/覆盖清理不再碰该行,分类永不丢;代价是该行价格/库存随锁
|
||||
* 停更——弹窗提示语点名这个后果)。取数复用 fetchJdProductList(不带公司维度,
|
||||
* company-tab-wiring 只认两个公司维度发送口);「未分类」走 ungrouped 参数。
|
||||
* 归类目标(selectedGroup)由左栏(父件)点亮下发;弹窗壳 v-if 整树重建 ⇒ 每次打开即本件
|
||||
* 重挂载、onMounted 自取首屏行集。成功后 emit('changed') 让父件刷新分类商品数并上抛页面;
|
||||
* 业务失败把后端中文文案展示在本面板红条内。 */
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { batchAssignJdProductGroup, fetchJdProductList } from './jd-product-api.ts'
|
||||
import type { 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
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'changed'): void }>()
|
||||
|
||||
type Scope = 'all' | 'ungrouped' | 'current'
|
||||
const scope = ref<Scope>('all')
|
||||
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 canAssign = computed(() => !!props.selectedGroup && selectedCount.value > 0 && !assigning.value)
|
||||
const canRemove = computed(() => selectedCount.value > 0 && !assigning.value)
|
||||
const allSelected = computed(() =>
|
||||
products.value.length > 0 && products.value.every((row) => selectedProductIds.value.has(row.id)))
|
||||
|
||||
async function loadProducts(): Promise<void> {
|
||||
productsLoading.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const result = await fetchJdProductList({
|
||||
page: productPage.value,
|
||||
pageSize: PRODUCT_PAGE_SIZE,
|
||||
titleKeyword: keyword.value.trim(),
|
||||
groupId: scope.value === 'current' && props.selectedGroup ? String(props.selectedGroup.id) : '',
|
||||
ungrouped: scope.value === 'ungrouped',
|
||||
companyId: null,
|
||||
})
|
||||
products.value = result.items
|
||||
productTotal.value = result.total
|
||||
if (result.page >= 1) productPage.value = result.page
|
||||
selectedProductIds.value = new Set()
|
||||
} catch (error) {
|
||||
productsError.value = requestErrorMessage(error) || '商品列表加载失败'
|
||||
products.value = []
|
||||
productTotal.value = 0
|
||||
selectedProductIds.value = new Set()
|
||||
} finally {
|
||||
productsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function pickScope(next: Scope): void {
|
||||
if (next === 'current' && !props.selectedGroup) return
|
||||
if (scope.value === next) return
|
||||
scope.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 || !canAssign.value) return
|
||||
assigning.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup([...selectedProductIds.value], target.id)
|
||||
showAdminFeedback(`已把 ${updated} 个商品归入「${target.name}」`, 'success')
|
||||
emit('changed')
|
||||
await loadProducts()
|
||||
} catch (error) {
|
||||
productsError.value = requestErrorMessage(error) || '归类失败,请稍后重试'
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 勾选行 → 移出分类(group_id 置 NULL,回到未分类)。 */
|
||||
async function removeFromCategory(): Promise<void> {
|
||||
if (!canRemove.value) return
|
||||
assigning.value = true
|
||||
productsError.value = ''
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup([...selectedProductIds.value], null)
|
||||
showAdminFeedback(`已把 ${updated} 个商品移出分类`, 'success')
|
||||
emit('changed')
|
||||
await loadProducts()
|
||||
} catch (error) {
|
||||
productsError.value = requestErrorMessage(error) || '移出分类失败,请稍后重试'
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 目标分类变化(左栏点亮/删除):右栏停在「当前分类」页签时随点亮对象换行集;
|
||||
// 目标被删(null)=「当前分类」没了,拉回全量页签,不留在空集页签里。
|
||||
watch(
|
||||
() => props.selectedGroup,
|
||||
(group) => {
|
||||
if (scope.value !== 'current') return
|
||||
if (group && group.id > 0) {
|
||||
productPage.value = 1
|
||||
void loadProducts()
|
||||
} else {
|
||||
scope.value = 'all'
|
||||
productPage.value = 1
|
||||
void loadProducts()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
void loadProducts()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="right-pane">
|
||||
<div class="product-toolbar">
|
||||
<div class="scope-tabs">
|
||||
<button type="button" :class="{ on: scope === 'all' }" @click="pickScope('all')">全部</button>
|
||||
<button type="button" :class="{ on: scope === 'ungrouped' }" @click="pickScope('ungrouped')">未分类</button>
|
||||
<button
|
||||
type="button"
|
||||
:class="{ on: scope === 'current' }"
|
||||
:disabled="!selectedGroup"
|
||||
:title="selectedGroup ? `只看「${selectedGroup.name}」下的商品` : '先在左侧点选一个分类'"
|
||||
@click="pickScope('current')"
|
||||
>当前分类</button>
|
||||
</div>
|
||||
<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 class="col-check"><input type="checkbox" :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 class="col-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
: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 class="product-footer">
|
||||
<span class="pick-summary">已勾选 {{ selectedCount }} 个商品</span>
|
||||
<div class="footer-actions">
|
||||
<button class="btn btn-small" type="button" :disabled="!canAssign" @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;
|
||||
}
|
||||
.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>
|
||||
@@ -146,7 +146,7 @@ function dash(value: string | number | null | undefined): string {
|
||||
<div class="info-item"><dt>总库存</dt><dd>{{ dash(item?.stockTotal) }}</dd></div>
|
||||
<div class="info-item"><dt>状态</dt><dd>{{ dash(item?.saleStatus) }}</dd></div>
|
||||
<div class="info-item"><dt>店铺</dt><dd :title="item?.shopName || ''">{{ dash(item?.shopName) }}</dd></div>
|
||||
<div class="info-item"><dt>分组</dt><dd>{{ dash(item?.groupName || '未分组') }}</dd></div>
|
||||
<div class="info-item"><dt>分类</dt><dd>{{ dash(item?.groupName || '未分类') }}</dd></div>
|
||||
<div class="info-item"><dt>上架时间</dt><dd>{{ item?.jdOnlineAt ? formatDateTime(item.jdOnlineAt) : '-' }}</dd></div>
|
||||
<div class="info-item"><dt>京东创建时间</dt><dd>{{ item?.jdCreatedAt ? formatDateTime(item.jdCreatedAt) : '-' }}</dd></div>
|
||||
<div class="info-item"><dt>京东修改时间</dt><dd>{{ item?.jdUpdatedAt ? formatDateTime(item.jdUpdatedAt) : '-' }}</dd></div>
|
||||
|
||||
@@ -263,9 +263,9 @@ function dash(value: string | number | null | undefined): string {
|
||||
<input v-model="form.stockTotal" type="text" inputmode="numeric" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>分组</label>
|
||||
<label>分类</label>
|
||||
<select v-model="form.groupId">
|
||||
<option value="">未分组</option>
|
||||
<option value="">未分类</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">
|
||||
{{ group.name }}
|
||||
</option>
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品分组管理弹窗(v1.4 Phase 5):新建/改名/删除,重名等业务失败把后端返回的中文文案
|
||||
* 原样展示在弹窗内(envelope code 非 0 → errorTextOf);删除前 openAdminConfirm 二次确认;
|
||||
* 变更成功后 emit('changed'),由页面刷新分组下拉与列表。 */
|
||||
/** 京东商品「店铺分类」弹窗(2026-11-15 由「分组管理」小弹窗重做):左右分栏——左栏分类管理
|
||||
* (新建/改名/删除;分组全平台一份、措辞「分类」),右栏商品人工归类(独立件
|
||||
* JdProductAssignPane:范围切换+搜索+勾选 →「归入所选分类」/「移出分类」,批量端点
|
||||
* batch-assign-group 与单行编辑同口径置 manual_locked=1——归类即人工干预,采集不再覆盖/
|
||||
* 清理该行)。左栏点亮的分类=右栏归类目标;目标被删时右栏自动拉回全量页签。
|
||||
* 重名等业务失败把后端返回的中文文案原样展示在弹窗内(envelope code 非 0 → errorTextOf);
|
||||
* 删除分类前 openAdminConfirm 二次确认;变更成功后 emit('changed'),由页面刷新分组下拉与
|
||||
* 列表。弹窗壳 v-if 整树重建 ⇒ 每次打开即两个面板都重新拉数据,无需手动重置。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
createJdProductGroup,
|
||||
@@ -10,6 +15,7 @@ import {
|
||||
updateJdProductGroup,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import JdProductAssignPane from './JdProductAssignPane.vue'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
@@ -19,6 +25,8 @@ const props = defineProps<{
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void }>()
|
||||
|
||||
// ---------------- 左栏:分类管理(分组全平台一份,界面措辞「分类」) ----------------
|
||||
|
||||
const loading = ref(false)
|
||||
const errorText = ref('')
|
||||
const groups = ref<JdProductGroup[]>([])
|
||||
@@ -26,12 +34,15 @@ const groups = ref<JdProductGroup[]>([])
|
||||
const createName = ref('')
|
||||
const createSortOrder = ref(0)
|
||||
const creating = ref(false)
|
||||
/** 改名:正在编辑的分组 id 与草稿名。 */
|
||||
/** 改名:正在编辑的分类 id 与草稿名。 */
|
||||
const editingId = ref(0)
|
||||
const editingName = ref('')
|
||||
const saving = ref(false)
|
||||
/** 左侧点亮的分类=右栏「归入所选分类」的归类目标;删除后自动清掉。 */
|
||||
const selectedGroupId = ref(0)
|
||||
|
||||
const canCreate = computed(() => createName.value.trim().length > 0 && !creating.value && !saving.value)
|
||||
const selectedGroup = computed(() => groups.value.find((group) => group.id === selectedGroupId.value) || null)
|
||||
|
||||
async function loadGroups(): Promise<void> {
|
||||
loading.value = true
|
||||
@@ -39,7 +50,7 @@ async function loadGroups(): Promise<void> {
|
||||
try {
|
||||
groups.value = await fetchJdProductGroups()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '分组列表加载失败'
|
||||
errorText.value = requestErrorMessage(error) || '分类列表加载失败'
|
||||
groups.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
@@ -50,6 +61,12 @@ function sortGroups(list: JdProductGroup[]): JdProductGroup[] {
|
||||
return [...list].sort((a, b) => a.sortOrder - b.sortOrder || a.id - b.id)
|
||||
}
|
||||
|
||||
/** 变更后统一收口:刷新左栏商品数徽标+上抛页面(分组下拉与行集都依赖它)。 */
|
||||
async function refreshAfterChange(): Promise<void> {
|
||||
groups.value = sortGroups(await fetchJdProductGroups())
|
||||
emit('changed')
|
||||
}
|
||||
|
||||
async function submitCreate(): Promise<void> {
|
||||
const name = createName.value.trim()
|
||||
if (!name || creating.value) return
|
||||
@@ -59,10 +76,9 @@ async function submitCreate(): Promise<void> {
|
||||
await createJdProductGroup({ name, sortOrder: Math.floor(createSortOrder.value) || 0 })
|
||||
createName.value = ''
|
||||
createSortOrder.value = 0
|
||||
groups.value = sortGroups(await fetchJdProductGroups())
|
||||
emit('changed')
|
||||
await refreshAfterChange()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '新建分组失败'
|
||||
errorText.value = requestErrorMessage(error) || '新建分类失败'
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
@@ -87,8 +103,7 @@ async function submitRename(group: JdProductGroup): Promise<void> {
|
||||
try {
|
||||
await updateJdProductGroup(group.id, { name, sortOrder: group.sortOrder })
|
||||
cancelRename()
|
||||
groups.value = sortGroups(await fetchJdProductGroups())
|
||||
emit('changed')
|
||||
await refreshAfterChange()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '改名失败'
|
||||
} finally {
|
||||
@@ -97,21 +112,31 @@ async function submitRename(group: JdProductGroup): Promise<void> {
|
||||
}
|
||||
|
||||
async function removeGroup(group: JdProductGroup): Promise<void> {
|
||||
const ok = await openAdminConfirm({ title: '删除分组', message: `确定删除分组「${group.name}」吗?删除后该组商品回到未分组。`, confirmText: '确认删除', danger: true })
|
||||
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${group.name}」吗?删除后该分类下 ${group.productCount} 个商品回到未分类。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await deleteJdProductGroup(group.id)
|
||||
groups.value = sortGroups(await fetchJdProductGroups())
|
||||
emit('changed')
|
||||
// 删掉的是当前归类目标:清点亮,右栏自己会拉回全量页签(watch selectedGroup)。
|
||||
if (selectedGroupId.value === group.id) {
|
||||
selectedGroupId.value = 0
|
||||
}
|
||||
await refreshAfterChange()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '删除分组失败'
|
||||
errorText.value = requestErrorMessage(error) || '删除分类失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 左侧点亮分类=归类目标(右栏「当前分类」页签随点亮对象换行集)。 */
|
||||
function pickGroup(group: JdProductGroup): void {
|
||||
if (saving.value) return
|
||||
selectedGroupId.value = group.id
|
||||
}
|
||||
|
||||
// 打开即拉一次分类列表;右栏行集由 JdProductAssignPane 挂载时自取。
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
@@ -119,54 +144,81 @@ watch(
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
createSortOrder.value = 0
|
||||
errorText.value = ''
|
||||
selectedGroupId.value = 0
|
||||
void loadGroups()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
/** 右栏归类成功:分类商品数变化+页面行集的 groupName 都要刷。 */
|
||||
function onPaneChanged(): void {
|
||||
void refreshAfterChange()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
|
||||
<div class="group-modal">
|
||||
<div class="modal-head">
|
||||
<h3>分组管理</h3>
|
||||
<h3>店铺分类</h3>
|
||||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</div>
|
||||
|
||||
<div class="group-create">
|
||||
<input
|
||||
v-model="createName"
|
||||
type="text"
|
||||
placeholder="输入新分组名称"
|
||||
@keyup.enter="submitCreate"
|
||||
/>
|
||||
<input v-model.number="createSortOrder" type="number" class="sort-input" aria-label="排序" />
|
||||
<button class="btn" type="button" :disabled="!canCreate" @click="submitCreate">
|
||||
{{ creating ? '新建中...' : '新建分组' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p class="modal-tip">
|
||||
左侧管理分类并点选目标分类;右侧勾选商品后「归入所选分类」或「移出分类」。
|
||||
人工归类过的商品不再被采集自动覆盖(价格/库存等字段停更)。
|
||||
</p>
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
<p v-else-if="loading" class="group-tip">加载中...</p>
|
||||
|
||||
<ul class="group-list">
|
||||
<li v-for="group in groups" :key="group.id" class="group-row">
|
||||
<template v-if="editingId === group.id">
|
||||
<input v-model="editingName" type="text" @keyup.enter="submitRename(group)" />
|
||||
<button class="btn btn-small" type="button" :disabled="saving" @click="submitRename(group)">保存</button>
|
||||
<button class="btn btn-secondary btn-small" type="button" @click="cancelRename">取消</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="group-name" :title="group.name">{{ group.name }}</span>
|
||||
<span class="group-meta">排序 {{ group.sortOrder }} · {{ group.productCount }} 个商品</span>
|
||||
<span class="group-actions">
|
||||
<button class="btn btn-secondary btn-small" type="button" @click="startRename(group)">改名</button>
|
||||
<button class="btn btn-danger btn-small" type="button" :disabled="saving" @click="removeGroup(group)">删除</button>
|
||||
</span>
|
||||
</template>
|
||||
</li>
|
||||
<li v-if="!loading && !groups.length && !errorText" class="group-tip">暂无分组,先新建一个</li>
|
||||
</ul>
|
||||
<div class="split-body">
|
||||
<!-- 左栏:分类管理 -->
|
||||
<aside class="left-pane">
|
||||
<div class="group-create">
|
||||
<input
|
||||
v-model="createName"
|
||||
type="text"
|
||||
placeholder="输入新分类名称"
|
||||
@keyup.enter="submitCreate"
|
||||
/>
|
||||
<div class="group-create-row">
|
||||
<input v-model.number="createSortOrder" type="number" class="sort-input" aria-label="排序" />
|
||||
<button class="btn" type="button" :disabled="!canCreate" @click="submitCreate">
|
||||
{{ creating ? '新建中...' : '新建分类' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="loading" class="pane-tip">加载中...</p>
|
||||
<ul class="group-list">
|
||||
<li
|
||||
v-for="group in groups"
|
||||
:key="group.id"
|
||||
class="group-row"
|
||||
:class="{ active: selectedGroupId === group.id }"
|
||||
@click="pickGroup(group)"
|
||||
>
|
||||
<template v-if="editingId === group.id">
|
||||
<input v-model="editingName" type="text" @keyup.enter="submitRename(group)" />
|
||||
<span class="group-actions" @click.stop>
|
||||
<button class="btn btn-mini" type="button" :disabled="saving" @click="submitRename(group)">保存</button>
|
||||
<button class="btn btn-secondary btn-mini" type="button" @click="cancelRename">取消</button>
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="group-name" :title="group.name">{{ group.name }}</span>
|
||||
<span class="group-meta">{{ group.productCount }}</span>
|
||||
<span class="group-actions" @click.stop>
|
||||
<button class="btn btn-secondary btn-mini" type="button" @click="startRename(group)">改名</button>
|
||||
<button class="btn btn-danger btn-mini" type="button" :disabled="saving" @click="removeGroup(group)">删除</button>
|
||||
</span>
|
||||
</template>
|
||||
</li>
|
||||
<li v-if="!loading && !groups.length && !errorText" class="pane-tip">暂无分类,先新建一个</li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
<!-- 右栏:商品人工归类(独立件,行集/勾选/批量归类都在那里) -->
|
||||
<JdProductAssignPane :selected-group="selectedGroup" @changed="onPaneChanged" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -186,9 +238,9 @@ watch(
|
||||
.group-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(560px, 100%);
|
||||
max-height: 84vh;
|
||||
padding: 18px 20px;
|
||||
width: min(1080px, 100%);
|
||||
max-height: 86vh;
|
||||
padding: 18px 20px 20px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
@@ -221,16 +273,46 @@ watch(
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
.modal-tip {
|
||||
margin: 8px 0 10px;
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.group-error {
|
||||
margin: 0 0 8px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
}
|
||||
.split-body {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
/* 左栏(分类管理):固定宽,独立滚动。 */
|
||||
.left-pane {
|
||||
flex: 0 0 248px;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-right: 1px solid #e7eef5;
|
||||
padding-right: 14px;
|
||||
}
|
||||
.group-create {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin: 14px 0 10px;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.group-create input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 38px;
|
||||
padding: 7px 12px;
|
||||
min-height: 36px;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
@@ -243,22 +325,12 @@ watch(
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
.group-create-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.sort-input {
|
||||
flex: 0 0 88px !important;
|
||||
}
|
||||
.group-error {
|
||||
margin: 0 0 8px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
}
|
||||
.group-tip {
|
||||
margin: 0 0 8px;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
flex: 0 0 72px !important;
|
||||
}
|
||||
.group-list {
|
||||
flex: 1;
|
||||
@@ -272,16 +344,25 @@ watch(
|
||||
.group-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 9px 4px;
|
||||
gap: 8px;
|
||||
padding: 8px 6px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.group-row:hover {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
/* 左侧点亮=归类目标:右侧「归入所选分类」就落在这一行。 */
|
||||
.group-row.active {
|
||||
background: #e8f1fa;
|
||||
box-shadow: inset 3px 0 0 #4f78a5;
|
||||
}
|
||||
.group-row input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 34px;
|
||||
padding: 5px 10px;
|
||||
min-height: 32px;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
font-size: 13.5px;
|
||||
@@ -297,14 +378,24 @@ watch(
|
||||
}
|
||||
.group-meta {
|
||||
flex: none;
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
min-width: 22px;
|
||||
padding: 1px 7px;
|
||||
border-radius: 9px;
|
||||
background: #eef4fa;
|
||||
color: #4e6479;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.group-actions {
|
||||
flex: none;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
gap: 6px;
|
||||
}
|
||||
.pane-tip {
|
||||
margin: 10px 2px;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
@@ -324,10 +415,10 @@ watch(
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-small {
|
||||
min-height: 32px;
|
||||
padding: 4px 12px;
|
||||
font-size: 12.5px;
|
||||
.btn-mini {
|
||||
min-height: 28px;
|
||||
padding: 3px 9px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
|
||||
@@ -37,6 +37,8 @@ export async function fetchJdProductList(
|
||||
params.pageSize,
|
||||
)
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
// 未分类范围(店铺分类弹窗「未分类」页签):与 company_id 一样由发送口直传,构造器不认识它。
|
||||
if (params.ungrouped) query.ungrouped = true
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_ENDPOINT, { params: query })
|
||||
return parseJdProductPage(data)
|
||||
}
|
||||
@@ -200,3 +202,16 @@ export async function deleteJdProductGroup(id: number): Promise<void> {
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`)
|
||||
groupDataOf<unknown>(data)
|
||||
}
|
||||
|
||||
/** 批量人工归类(店铺分类弹窗,2026-11-15):勾选商品行 → 归入指定分类或移出分类。
|
||||
* groupId 传 null=移出分类(后端把 group_id 置 NULL);返回实际更新的行数。
|
||||
* 后端与单行编辑同口径置 manual_locked=1(归类即人工干预,采集不再覆盖/清理该行)。
|
||||
* 业务失败(分类不存在等)把中文文案抛回,弹窗红条原样展示。公共库写侧无公司维度。 */
|
||||
export async function batchAssignJdProductGroup(
|
||||
ids: number[],
|
||||
groupId: number | null,
|
||||
): Promise<number> {
|
||||
const body: Record<string, unknown> = { ids, groupId }
|
||||
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/batch-assign-group`, body)
|
||||
return groupDataOf<number>(data)
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ export interface JdProductQuery {
|
||||
/** 京麦末级类目等值过滤(后端 JdProductQueryService.Filter.category)。 */
|
||||
category?: string
|
||||
group_id?: number
|
||||
/** 未分类过滤(店铺分类弹窗「未分类」范围):true=只看 group_id 为空的行。
|
||||
* 同 group_id 一样由 api 发送口下传——构造器不认识它(弹窗的取数不走筛选态)。 */
|
||||
ungrouped?: boolean
|
||||
synced_from?: string
|
||||
synced_to?: string
|
||||
/** 公司 tab:白名单构造不点名它,字段只为 api 发送口的 `query.company_id = params.companyId` 存在。 */
|
||||
@@ -75,6 +78,8 @@ export interface JdProductListParams {
|
||||
titleKeyword?: string
|
||||
category?: string
|
||||
groupId?: string
|
||||
/** 未分类范围(true=只看未分类行);仅店铺分类弹窗右栏传,页面筛选行不用。 */
|
||||
ungrouped?: boolean
|
||||
syncedFrom?: string
|
||||
syncedTo?: string
|
||||
companyId?: number | null
|
||||
|
||||
Reference in New Issue
Block a user