fix(jd): 恢复店铺分类管理与类目筛选
This commit is contained in:
@@ -29,6 +29,7 @@ const props = defineProps<{
|
||||
groupId?: string
|
||||
createVersion?: number
|
||||
busy?: boolean
|
||||
treeOnly?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -179,7 +180,7 @@ function clear(): void {
|
||||
<!-- 面板外点透明遮罩关闭(零 document 监听器,无泄漏面)。 -->
|
||||
<div v-if="open" class="cat-mask" @click="close"></div>
|
||||
<div v-if="open" ref="panelRef" class="cat-panel" :style="{ left: `${panelOffsetX}px` }">
|
||||
<div class="cat-custom cat-col-custom">
|
||||
<div v-if="!treeOnly" class="cat-custom cat-col-custom">
|
||||
<div class="cat-seg">自定义分类</div>
|
||||
<form class="cat-create" @submit.prevent="createGroup">
|
||||
<input v-model="newGroupName" class="cat-search" placeholder="新建分类" aria-label="新建分类名称" />
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东公共商品库:类目面板提供京麦树与自定义分类筛选、增删;
|
||||
* 商品支持勾选归入或移除分类,删除分类保留商品。列表、详情和编辑共用现有接口。 */
|
||||
/** 京东公共商品库:支持店铺分类和京麦类目组合筛选,分类管理在弹窗中完成。 */
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import {
|
||||
batchAssignJdProductGroup,
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
deleteJdProducts,
|
||||
fetchJdProductCategories,
|
||||
fetchJdProductGroups,
|
||||
@@ -16,10 +12,10 @@ import {
|
||||
import type { JdProductItem } from './jd-product-model.ts'
|
||||
import { jdPriceRange } from './jd-product-model.ts'
|
||||
import { createJdProductFilterState } from './jd-product-filter.ts'
|
||||
import { removableGroupPicks, removeGroupConfirmMessage } from './jd-group-remove.ts'
|
||||
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
|
||||
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
||||
import JdCategoryCascader from './JdCategoryCascader.vue'
|
||||
import JdProductGroupDialog from './JdProductGroupDialog.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
@@ -41,6 +37,7 @@ const groupOptions = ref<JdProductGroup[]>([])
|
||||
const categoryOptions = ref<JdProductCategoryOption[]>([])
|
||||
const detailItem = ref<JdProductItem | null>(null)
|
||||
const detailVisible = ref(false)
|
||||
const groupDialogVisible = ref(false)
|
||||
/** 行级编辑抽屉(2026-11-15 用户口径「每一条数据后面 需要编辑或者删除;编辑的话
|
||||
* 这里面都是可以编辑的」):删除走下面的 removeOne(同一条删除链),编辑走独立抽屉。 */
|
||||
const editItem = ref<JdProductItem | null>(null)
|
||||
@@ -89,7 +86,8 @@ async function loadCategoryOptions(): Promise<void> {
|
||||
}
|
||||
|
||||
/** 分组管理弹窗里做过变更:分组下拉与列表都刷新(删除分组后行集的 groupName 会变)。 */
|
||||
async function onGroupChanged(): Promise<void> {
|
||||
async function onGroupChanged(deletedGroupId?: number): Promise<void> {
|
||||
if (deletedGroupId && filter.groupId === String(deletedGroupId)) filter.groupId = ''
|
||||
await loadGroupOptions()
|
||||
page.value = 1
|
||||
await load()
|
||||
@@ -131,66 +129,9 @@ function apply(): void {
|
||||
* 点「全部类目」/触发框 × = 清选重查。 */
|
||||
function onCategoryPicked(name: string): void {
|
||||
filter.category = name
|
||||
filter.groupId = ''
|
||||
apply()
|
||||
}
|
||||
|
||||
function onGroupPicked(id: string): void {
|
||||
filter.groupId = id
|
||||
filter.category = ''
|
||||
apply()
|
||||
}
|
||||
|
||||
const groupBusy = ref(false)
|
||||
const groupCreateVersion = ref(0)
|
||||
async function createGroup(name: string): Promise<void> {
|
||||
if (groupBusy.value) return
|
||||
groupBusy.value = true
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: 0 })
|
||||
groupCreateVersion.value++
|
||||
await loadGroupOptions()
|
||||
showAdminFeedback('分类已添加', 'success')
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error && error.message ? error.message : '添加分类失败', 'error')
|
||||
} finally { groupBusy.value = false }
|
||||
}
|
||||
|
||||
async function deleteGroup(id: number): Promise<void> {
|
||||
const group = groupOptions.value.find(item => item.id === id)
|
||||
if (!group || groupBusy.value) return
|
||||
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${group.name}」吗?分类下 ${group.productCount} 个商品将保留并回到未分类。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok || groupBusy.value) return
|
||||
groupBusy.value = true
|
||||
try {
|
||||
await deleteJdProductGroup(id)
|
||||
if (filter.groupId === String(id)) filter.groupId = ''
|
||||
await onGroupChanged()
|
||||
showAdminFeedback('分类已删除,商品已保留', 'success')
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error && error.message ? error.message : '删除分类失败', 'error')
|
||||
} finally { groupBusy.value = false }
|
||||
}
|
||||
|
||||
const assignGroupId = ref('')
|
||||
async function assignSelectedGroup(): Promise<void> {
|
||||
const id = Number(assignGroupId.value)
|
||||
const picked = rows.value.filter(row => selectedIds.value.has(row.id))
|
||||
if (!id || !picked.length || groupBusy.value || removingGroup.value || deleting.value) return
|
||||
const group = groupOptions.value.find(item => item.id === id)
|
||||
if (!group) return
|
||||
const ok = await openAdminConfirm({ title: '归入分类', message: `确定将勾选的 ${picked.length} 个商品归入「${group.name}」吗?归类会设置人工编辑锁,商品不再被采集自动覆盖,价格和库存等字段也将停止自动更新。`, confirmText: '确认归类', danger: false })
|
||||
if (!ok || groupBusy.value || removingGroup.value || deleting.value) return
|
||||
groupBusy.value = true
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup(picked.map(row => row.id), id)
|
||||
showAdminFeedback(`已将 ${updated} 个商品归入分类`, 'success')
|
||||
await onGroupChanged()
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error && error.message ? error.message : '归入分类失败', 'error')
|
||||
} finally { groupBusy.value = false }
|
||||
}
|
||||
|
||||
/** 重置:筛选面回出厂空态,回第一页重取。 */
|
||||
function reset(): void {
|
||||
Object.assign(filter, createJdProductFilterState())
|
||||
@@ -265,7 +206,7 @@ async function removeSelected(): Promise<void> {
|
||||
|
||||
/** 删除主流程:二次确认 → 先删桶、全成功才删库行(后端保证)→ 刷新列表并清勾选。 */
|
||||
async function removeMany(picked: JdProductItem[], message: string): Promise<void> {
|
||||
if (!picked.length || deleting.value || removingGroup.value) return
|
||||
if (!picked.length || deleting.value) return
|
||||
const ok = await openAdminConfirm({ title: '删除京东商品', message: `${message}删除后该商品的 SKU、图片登记与 jd-products 桶内图片文件一并删除(被其他商品共用的图片会保留);此操作不可恢复。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok) return
|
||||
deleting.value = true
|
||||
@@ -284,30 +225,6 @@ async function removeMany(picked: JdProductItem[], message: string): Promise<voi
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- 批量移除分类(2026-11-16 用户截图反馈):batch-assign-group 的 groupId=null 口径(与店铺分类弹窗「移出分类」同一出口,后端同置人工编辑锁) ----------------
|
||||
const removingGroup = ref(false)
|
||||
const removablePicked = computed(() => removableGroupPicks(rows.value, selectedIds.value))
|
||||
/** 移除主流程:二次确认点名数量与人工锁后果 → (ids, null) → 刷新列表并清勾选。 */
|
||||
async function removeSelectedGroup(): Promise<void> {
|
||||
const picked = removablePicked.value
|
||||
if (!picked.length || removingGroup.value || deleting.value) return
|
||||
const ok = await openAdminConfirm({ title: '移除分类', message: removeGroupConfirmMessage(picked.length), confirmText: '确认移除', danger: false })
|
||||
if (!ok) return
|
||||
removingGroup.value = true
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup(picked.map((row) => row.id), null)
|
||||
showAdminFeedback(`已把 ${updated} 个商品移出分类`, 'success')
|
||||
selectedIds.value = new Set()
|
||||
await loadGroupOptions()
|
||||
await load()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '移除分类失败,请稍后重试'
|
||||
showAdminFeedback(text, 'error')
|
||||
} finally {
|
||||
removingGroup.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadGroupOptions()
|
||||
void loadCategoryOptions()
|
||||
@@ -338,14 +255,8 @@ onMounted(() => {
|
||||
<JdCategoryCascader
|
||||
:options="categoryOptions"
|
||||
:model-value="filter.category"
|
||||
:groups="groupOptions"
|
||||
:group-id="filter.groupId"
|
||||
:create-version="groupCreateVersion"
|
||||
:busy="groupBusy"
|
||||
tree-only
|
||||
@change="onCategoryPicked"
|
||||
@group="onGroupPicked"
|
||||
@create-group="createGroup"
|
||||
@delete-group="deleteGroup"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -365,21 +276,11 @@ onMounted(() => {
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<div class="jd-toolbar">
|
||||
<span class="jd-summary">共 {{ total }} 条京东商品</span>
|
||||
<select v-model="assignGroupId" aria-label="选择归入的分类">
|
||||
<option value="">选择分类</option>
|
||||
<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>
|
||||
</select>
|
||||
<button class="btn" type="button" :disabled="!selectedCount || !assignGroupId || groupBusy || removingGroup || deleting" @click="assignSelectedGroup">归入分类({{ selectedCount }})</button>
|
||||
<!-- 「移除分类」是次要批量动作:改用全站统一的次要按钮(白底灰蓝字),
|
||||
主蓝只留给「归入分类」,与打卡/分组等页的工具栏层级一致。 -->
|
||||
<button
|
||||
class="btn btn-secondary jd-remove-btn" type="button"
|
||||
:disabled="removingGroup || !removablePicked.length"
|
||||
:title="removablePicked.length ? `移出勾选的 ${removablePicked.length} 个已分类商品` : '勾选中没有已分类的商品'"
|
||||
@click="removeSelectedGroup"
|
||||
>
|
||||
{{ removingGroup ? '移除中...' : `移除分类(${removablePicked.length})` }}
|
||||
</button>
|
||||
<!-- 批量删除 2026-11-16 客户口径「不要勾选后才显示」:常显,勾选 0 时置灰。 -->
|
||||
<button
|
||||
class="btn btn-danger jd-delete-btn"
|
||||
@@ -456,6 +357,7 @@ 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" />
|
||||
<JdProductDetailDrawer
|
||||
:item="detailItem"
|
||||
:visible="detailVisible"
|
||||
|
||||
@@ -0,0 +1,444 @@
|
||||
<script setup lang="ts">
|
||||
/** 店铺分类弹窗右栏:按京麦类目和标题筛选商品,勾选后归入左侧目标或移出分类。
|
||||
* 两种操作都会设置人工编辑锁,弹窗提示采集不再覆盖以及价格、库存停更。 */
|
||||
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
|
||||
}>()
|
||||
|
||||
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))
|
||||
const canAssign = computed(() => !!props.selectedGroup && selectedCount.value > 0 && !assigning.value && !productsLoading.value)
|
||||
const canRemove = computed(() => 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,
|
||||
})
|
||||
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 || !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(removableIds.value, null)
|
||||
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 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 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 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;
|
||||
}
|
||||
.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>
|
||||
@@ -0,0 +1,459 @@
|
||||
<script setup lang="ts">
|
||||
/** 店铺分类弹窗:左侧管理分类和选择归类目标,右侧按京麦类目筛选商品并批量归类。
|
||||
* 人工归类会设置编辑锁,采集不再覆盖商品;变更后通知页面刷新。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
fetchJdProductGroups,
|
||||
updateJdProductGroup,
|
||||
type JdProductGroup,
|
||||
type JdProductCategoryOption,
|
||||
} from './jd-product-api.ts'
|
||||
import JdProductAssignPane from './JdProductAssignPane.vue'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
categoryOptions: JdProductCategoryOption[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed', deletedGroupId?: number): void }>()
|
||||
|
||||
// ---------------- 左栏:分类管理(分组全平台一份,界面措辞「分类」) ----------------
|
||||
|
||||
const loading = ref(false)
|
||||
const errorText = ref('')
|
||||
const groups = ref<JdProductGroup[]>([])
|
||||
/** 新建:只收名称(排序输入 2026-11-15 客户口径下线,sortOrder 恒 0,后端契约不变)。 */
|
||||
const createName = ref('')
|
||||
const creating = ref(false)
|
||||
/** 改名:正在编辑的分类 id 与草稿名。 */
|
||||
const editingId = ref(0)
|
||||
const editingName = ref('')
|
||||
const saving = ref(false)
|
||||
const paneRefreshVersion = ref(0)
|
||||
/** 左侧点亮的分类=右栏「归入所选分类」的归类目标;删除后自动清掉。 */
|
||||
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
|
||||
errorText.value = ''
|
||||
try {
|
||||
groups.value = await fetchJdProductGroups()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '分类列表加载失败'
|
||||
groups.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function sortGroups(list: JdProductGroup[]): JdProductGroup[] {
|
||||
return [...list].sort((a, b) => a.sortOrder - b.sortOrder || a.id - b.id)
|
||||
}
|
||||
|
||||
/** 变更后统一收口:刷新左栏商品数徽标+上抛页面(分组下拉与行集都依赖它)。 */
|
||||
async function refreshAfterChange(deletedGroupId?: number, refreshPane = false): Promise<void> {
|
||||
emit('changed', deletedGroupId)
|
||||
if (refreshPane) paneRefreshVersion.value++
|
||||
try {
|
||||
groups.value = sortGroups(await fetchJdProductGroups())
|
||||
} catch (error) {
|
||||
errorText.value = `操作已成功,分类列表刷新失败:${requestErrorMessage(error) || '请重试'}`
|
||||
}
|
||||
}
|
||||
|
||||
async function submitCreate(): Promise<void> {
|
||||
const name = createName.value.trim()
|
||||
if (!name || creating.value) return
|
||||
creating.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: 0 })
|
||||
createName.value = ''
|
||||
await refreshAfterChange()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '新建分类失败'
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function startRename(group: JdProductGroup): void {
|
||||
editingId.value = group.id
|
||||
editingName.value = group.name
|
||||
errorText.value = ''
|
||||
}
|
||||
|
||||
function cancelRename(): void {
|
||||
editingId.value = 0
|
||||
editingName.value = ''
|
||||
}
|
||||
|
||||
async function submitRename(group: JdProductGroup): Promise<void> {
|
||||
const name = editingName.value.trim()
|
||||
if (!name || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await updateJdProductGroup(group.id, { name, sortOrder: group.sortOrder })
|
||||
groups.value = groups.value.map(item => item.id === group.id ? { ...item, name } : item)
|
||||
cancelRename()
|
||||
await refreshAfterChange(undefined, true)
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '改名失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function removeGroup(group: JdProductGroup): Promise<void> {
|
||||
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)
|
||||
// 删掉当前归类目标时清除选中状态。
|
||||
if (selectedGroupId.value === group.id) {
|
||||
selectedGroupId.value = 0
|
||||
}
|
||||
groups.value = groups.value.filter(item => item.id !== group.id)
|
||||
await refreshAfterChange(group.id, true)
|
||||
} catch (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) => {
|
||||
if (visible) {
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
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>
|
||||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</div>
|
||||
<p class="modal-tip">
|
||||
左侧管理分类并点选目标分类;右侧勾选商品后「归入所选分类」或「移出分类」。
|
||||
人工归类过的商品不再被采集自动覆盖(价格/库存等字段停更)。
|
||||
</p>
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
|
||||
<div class="split-body">
|
||||
<!-- 左栏:分类管理 -->
|
||||
<aside class="left-pane">
|
||||
<div class="group-create">
|
||||
<input
|
||||
v-model="createName"
|
||||
type="text"
|
||||
placeholder="输入新分类名称"
|
||||
@keyup.enter="submitCreate"
|
||||
/>
|
||||
<!-- 新建=输入行尾「+」图标(2026-11-15 客户口径:原第二行文字按钮收成图标上移,
|
||||
排序数字输入下线——sortOrder 恒 0,后端契约不变)。 -->
|
||||
<button
|
||||
class="create-icon-btn"
|
||||
type="button"
|
||||
title="新建分类"
|
||||
aria-label="新建分类"
|
||||
:disabled="!canCreate"
|
||||
@click="submitCreate"
|
||||
>+</button>
|
||||
</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" :category-options="categoryOptions" :refresh-version="paneRefreshVersion" @changed="onPaneChanged" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.group-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(1080px, 100%);
|
||||
max-height: 86vh;
|
||||
padding: 18px 20px 20px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
}
|
||||
.modal-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.modal-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
}
|
||||
.modal-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.modal-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
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;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.group-create 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;
|
||||
}
|
||||
.group-create input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
/* 新建「+」图标按钮:与输入同行(原第二行文字按钮上移收成图标)。 */
|
||||
.create-icon-btn {
|
||||
flex: none;
|
||||
width: 36px;
|
||||
min-height: 36px;
|
||||
padding: 0;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.create-icon-btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.group-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
border-top: 1px solid #e7eef5;
|
||||
}
|
||||
.group-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
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: 32px;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.group-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #24384d;
|
||||
}
|
||||
.group-meta {
|
||||
flex: none;
|
||||
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: 6px;
|
||||
}
|
||||
.pane-tip {
|
||||
margin: 10px 2px;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
}
|
||||
.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-mini {
|
||||
min-height: 28px;
|
||||
padding: 3px 9px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: #ffffff;
|
||||
color: #a04432;
|
||||
border-color: #e4b3a8;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: #fdf1ef;
|
||||
border-color: #d08a7b;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user