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>
|
||||
@@ -16,6 +16,7 @@ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
|
||||
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
|
||||
@@ -92,6 +93,176 @@ async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('店铺分类弹窗', () => {
|
||||
it('外层店铺分类与京麦类目独立组合,选全部立即清除分组', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const select = wrapper.get('[aria-label="筛选店铺分类"]')
|
||||
await select.setValue('7')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
||||
await wrapper.get('.cat-trigger').trigger('click')
|
||||
expect(wrapper.find('.cat-custom').exists()).toBe(false)
|
||||
await wrapper.get('.cat-search').setValue('艺考')
|
||||
await wrapper.get('.cat-col-search .cat-row').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', category: '艺考形体服', page: 1 })
|
||||
await select.setValue('')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '', category: '艺考形体服', page: 1 })
|
||||
expect(wrapper.get('.jd-toolbar').text()).not.toMatch(/归入分类|移除分类/)
|
||||
wrapper.unmount()
|
||||
})
|
||||
it('入口恢复,按京麦类目筛选并将商品归入或移出左侧目标', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([{ name: '历史京麦类目', productCount: 1 }])
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
expect(modal.text()).toContain('价格/库存等字段停更')
|
||||
expect(modal.find('.scope-tabs').exists()).toBe(false)
|
||||
await modal.get('.group-row').trigger('click')
|
||||
await modal.get('.cat-trigger').trigger('click')
|
||||
expect(modal.find('.cat-custom').exists()).toBe(false)
|
||||
await modal.get('.cat-search').setValue('历史京麦类目')
|
||||
await modal.findAll('.cat-row').find(row => row.text().includes('历史京麦类目'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '历史京麦类目', page: 1 })
|
||||
await modal.get('tbody input[type="checkbox"]').setValue(true)
|
||||
await modal.findAll('button').find(b => b.text().includes('归入「甲组」'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7)
|
||||
await modal.get('tbody input[type="checkbox"]').setValue(true)
|
||||
await modal.findAll('button').find(b => b.text() === '移出分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null)
|
||||
await modal.get('.modal-close').trigger('click')
|
||||
expect(wrapper.find('.group-modal').exists()).toBe(false)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('加载期间立即清除勾选并阻止操作,旧请求不能覆盖新结果', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
await modal.get('.group-row').trigger('click')
|
||||
await modal.get('tbody input').setValue(true)
|
||||
let resolveOld!: (value: unknown) => void
|
||||
let resolveNew!: (value: unknown) => void
|
||||
jdApi.fetchJdProductList.mockImplementationOnce(() => new Promise(resolve => { resolveOld = resolve }))
|
||||
.mockImplementationOnce(() => new Promise(resolve => { resolveNew = resolve }))
|
||||
await modal.get('.keyword-input').setValue('旧')
|
||||
await modal.get('.keyword-input').trigger('keyup.enter')
|
||||
expect(modal.text()).toContain('已勾选 0 个商品')
|
||||
expect(modal.findAll('button').find(b => b.text().includes('归入「甲组」'))!.attributes('disabled')).toBeDefined()
|
||||
expect(modal.findAll('button').find(b => b.text() === '移出分类')!.attributes('disabled')).toBeDefined()
|
||||
await modal.get('.keyword-input').setValue('新')
|
||||
await modal.get('.keyword-input').trigger('keyup.enter')
|
||||
resolveNew({ items: [item(2, { title: '新结果' })], total: 1, page: 1, pageSize: 20 })
|
||||
await flushPromises()
|
||||
resolveOld({ items: [item(1, { title: '旧结果' })], total: 1, page: 1, pageSize: 20 })
|
||||
await flushPromises()
|
||||
expect(modal.text()).toContain('新结果')
|
||||
expect(modal.text()).not.toContain('旧结果')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('翻页开始时清除勾选且禁止批量操作', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 40, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
await modal.get('.group-row').trigger('click')
|
||||
await modal.get('tbody input').setValue(true)
|
||||
let resolvePage!: (value: unknown) => void
|
||||
jdApi.fetchJdProductList.mockImplementationOnce(() => new Promise(resolve => { resolvePage = resolve }))
|
||||
modal.getComponent(OldPagination).vm.$emit('change', 2)
|
||||
await wrapper.vm.$nextTick()
|
||||
expect(modal.text()).toContain('已勾选 0 个商品')
|
||||
expect(modal.findAll('button').find(b => b.text().includes('归入「甲组」'))!.attributes('disabled')).toBeDefined()
|
||||
resolvePage({ items: [item(2)], total: 40, page: 2, pageSize: 20 })
|
||||
await flushPromises()
|
||||
expect(modal.text()).toContain('JD-1002')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('移出只提交已分类商品,未分类商品不会被锁', async () => {
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||||
const wrapper = await mountWith({ items: [item(1), item(2, { groupId: null, groupName: '' })], total: 2, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
await modal.get('thead input').setValue(true)
|
||||
await modal.findAll('button').find(b => b.text() === '移出分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('删除当前筛选分类后刷新两侧并清除主页面筛选,即使分类列表刷新失败', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.get('[aria-label="筛选店铺分类"]').setValue('7')
|
||||
await flushPromises()
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||
jdApi.fetchJdProductGroups.mockRejectedValue(new Error('网络中断'))
|
||||
await modal.findAll('button').find(b => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(modal.text()).toContain('操作已成功,分类列表刷新失败')
|
||||
expect(modal.text()).not.toContain('删除分类失败')
|
||||
const calls = jdApi.fetchJdProductList.mock.calls.slice(callsBefore).map(call => call[0])
|
||||
expect(calls.some(call => call.groupId === '')).toBe(true)
|
||||
expect(calls.some(call => call.category === '' && !('groupId' in call))).toBe(true)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('改名后重新加载弹窗商品行', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
const before = jdApi.fetchJdProductList.mock.calls.length
|
||||
await modal.findAll('button').find(b => b.text() === '改名')!.trigger('click')
|
||||
await modal.get('.group-row input').setValue('新名称')
|
||||
await modal.findAll('button').find(b => b.text() === '保存')!.trigger('click')
|
||||
await flushPromises()
|
||||
const calls = jdApi.fetchJdProductList.mock.calls.slice(before).map(call => call[0])
|
||||
expect(calls.some(call => call.category === '' && !('groupId' in call))).toBe(true)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('左侧支持新增、改名和确认删除', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find(b => b.text() === '店铺分类')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.group-modal')
|
||||
await modal.get('.group-create input').setValue('新分类')
|
||||
await modal.get('.create-icon-btn').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '新分类', sortOrder: 0 })
|
||||
await modal.findAll('button').find(b => b.text() === '改名')!.trigger('click')
|
||||
await modal.get('.group-row input').setValue('改名后')
|
||||
await modal.findAll('button').find(b => b.text() === '保存')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.updateJdProductGroup).toHaveBeenCalledWith(7, { name: '改名后', sortOrder: 0 })
|
||||
await modal.findAll('button').find(b => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmMock).toHaveBeenCalled()
|
||||
expect(jdApi.deleteJdProductGroup).toHaveBeenCalledWith(7)
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
it('挂载后按首屏分页参数取列表(pageSize 默认 20、不带公司维度),行数=本页条数', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1), item(2), item(3)], total: 42, page: 1, pageSize: 20 })
|
||||
@@ -227,8 +398,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(textInputs).toHaveLength(2, '商品编码+标题关键字两个文本筛选框(店铺/商品状态已下线)')
|
||||
await textInputs[0].setValue('JD-1001')
|
||||
await textInputs[1].setValue('保温杯')
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.find('.cat-group-pick').trigger('click')
|
||||
await wrapper.get('[aria-label="筛选店铺分类"]').setValue('7')
|
||||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||||
await dateInputs[0].setValue('2026-11-01')
|
||||
await dateInputs[1].setValue('2026-11-09')
|
||||
@@ -251,22 +421,6 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(last).not.toHaveProperty('companyId')
|
||||
})
|
||||
|
||||
it('分组下拉选中即查', async () => { jdApi.fetchJdProductGroups.mockResolvedValue([
|
||||
{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 },
|
||||
{ id: 8, name: '乙组', sortOrder: 1, productCount: 1 },
|
||||
])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith()
|
||||
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
expect(wrapper.find('.cat-custom').text()).toContain('甲组')
|
||||
const callsBeforeSelect = jdApi.fetchJdProductList.mock.calls.length
|
||||
await wrapper.find('.cat-group-pick').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeSelect + 1, '选中分组必须立刻重查')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
||||
})
|
||||
|
||||
it('类目京麦同款级联面板(2026-11-16 真树重做):授权一级 3 个逐级下钻,点末级即查回第一页', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||
{ name: '艺考形体服', productCount: 120 },
|
||||
@@ -360,11 +514,18 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
expect(wrapper.find('.jd-filter-row').text()).not.toContain('分类状态')
|
||||
expect(wrapper.find('.jd-filter-row select').exists()).toBe(false)
|
||||
expect(wrapper.findAll('button').some(button => button.text() === '店铺分类')).toBe(false)
|
||||
expect(wrapper.findAll('button').some(button => button.text() === '店铺分类')).toBe(true)
|
||||
})
|
||||
|
||||
it('重置把筛选面回空并回第一页重取', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const select = wrapper.get('[aria-label="筛选店铺分类"]')
|
||||
expect(select.text()).toContain('全部分类')
|
||||
await select.setValue('7')
|
||||
await wrapper.get('.cat-trigger').trigger('click')
|
||||
await wrapper.get('.cat-search').setValue('艺考')
|
||||
await wrapper.get('.cat-col-search .cat-row').trigger('click')
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||
await textInputs[0].setValue('JD-1001')
|
||||
await textInputs[1].setValue('保温杯')
|
||||
@@ -375,7 +536,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore)
|
||||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(last).toMatchObject({ productCode: '', titleKeyword: '', page: 1 }, '重置后筛选全空、回第一页')
|
||||
expect(last).toMatchObject({ productCode: '', titleKeyword: '', groupId: '', category: '', page: 1 }, '重置后筛选全空、回第一页')
|
||||
expect((select.element as HTMLSelectElement).value).toBe('')
|
||||
})
|
||||
|
||||
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
|
||||
@@ -551,133 +713,6 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('移除分类(2026-11-16 页工具栏):计数只算勾选中已分类的行(未分类行不参与=不白吃人工锁)→ 确认点名数量与人工锁后果 → (ids, null) 调批量归类,成功后刷新并清勾选', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValueOnce([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
.mockResolvedValueOnce([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({
|
||||
items: [item(1), item(2, { groupId: null, groupName: '' }), item(3)],
|
||||
total: 3, page: 1, pageSize: 20,
|
||||
})
|
||||
|
||||
// 常显(同删除口径);未勾选时置灰。
|
||||
const removeBtn = () => wrapper.find('.jd-remove-btn')
|
||||
expect(removeBtn().exists()).toBe(true)
|
||||
expect(removeBtn().attributes('disabled')).toBeDefined()
|
||||
|
||||
// 只勾未分类行:没有分类可移,按钮仍置灰(标题给原因,不靠猜)。
|
||||
const boxes = wrapper.findAll('tbody input[type="checkbox"]')
|
||||
await boxes[1].setValue(true)
|
||||
expect(removeBtn().attributes('disabled')).toBeDefined()
|
||||
expect(removeBtn().attributes('title')).toBe('勾选中没有已分类的商品')
|
||||
|
||||
// 勾选 1、3 两行已分类 → 计数=2 且可点(未分类的 2 号行不在发送名单里)。
|
||||
await boxes[0].setValue(true)
|
||||
await boxes[2].setValue(true)
|
||||
expect(removeBtn().attributes('disabled')).toBeUndefined()
|
||||
expect(removeBtn().text()).toContain('移除分类(2)')
|
||||
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(2)
|
||||
await removeBtn().trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||||
const options = confirmMock.mock.calls[0][0]
|
||||
expect(options.title).toBe('移除分类')
|
||||
expect(options.message).toContain('确定把勾选的 2 个商品移出分类吗')
|
||||
expect(options.message).toContain('人工编辑锁', '确认弹窗必须点名人工编辑锁后果(价格/库存随锁停更)')
|
||||
expect(options.danger).toBe(false, '移除分类是可恢复动作,非 danger 形态(danger-exit-ledger 口径)')
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledTimes(1)
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1, 3], null)
|
||||
expect(document.body.textContent).toContain('已把 2 个商品移出分类')
|
||||
// 成功后重取列表并清勾选:按钮回到置灰。
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(1)
|
||||
expect(removeBtn().attributes('disabled')).toBeDefined()
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2)
|
||||
expect(wrapper.find('.cat-custom').text()).toContain('甲组(1)')
|
||||
})
|
||||
|
||||
it('移除分类:确认弹窗点取消就不发请求(防误操作的第一道闸)', async () => {
|
||||
confirmMock.mockResolvedValue(false)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
await wrapper.find('.jd-remove-btn').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('移除分类失败把后端中文文案弹出来(勾选保留可重试)', async () => {
|
||||
jdApi.batchAssignJdProductGroup.mockRejectedValue(new Error('分类不存在,请刷新分类后重试'))
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
await wrapper.find('.jd-remove-btn').trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(document.body.textContent).toContain('分类不存在,请刷新分类后重试')
|
||||
})
|
||||
|
||||
it('归类先提示人工锁,取消不发送请求', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
confirmMock.mockResolvedValue(false)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.find('tbody input[type="checkbox"]').setValue(true)
|
||||
await wrapper.find('[aria-label="选择归入的分类"]').setValue('7')
|
||||
await wrapper.findAll('button').find(b => b.text().includes('归入分类'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||||
expect(confirmMock.mock.calls[0][0].message).toContain('人工编辑锁')
|
||||
expect(confirmMock.mock.calls[0][0].message).toContain('不再被采集自动覆盖')
|
||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('分类增删、筛选切换和勾选归类', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
jdApi.createJdProductGroup.mockRejectedValueOnce(new Error('分类已存在')).mockResolvedValueOnce({})
|
||||
jdApi.deleteJdProductGroup.mockResolvedValue(undefined)
|
||||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.find('[aria-label="新建分类名称"]').setValue('新分类')
|
||||
await wrapper.find('.cat-create').trigger('submit')
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('分类已存在')
|
||||
expect((wrapper.find('[aria-label="新建分类名称"]').element as HTMLInputElement).value).toBe('新分类')
|
||||
await wrapper.find('.cat-create').trigger('submit')
|
||||
await flushPromises()
|
||||
expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '新分类', sortOrder: 0 })
|
||||
confirmMock.mockResolvedValueOnce(false)
|
||||
await wrapper.find('[aria-label="删除分类 甲组"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.deleteJdProductGroup).not.toHaveBeenCalled()
|
||||
await wrapper.find('.cat-group-pick').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', category: '' })
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.findAll('.cat-col')[0].find('.cat-search').setValue('艺考')
|
||||
await wrapper.find('.cat-col-search .cat-row').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '', category: '艺考形体服' })
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.find('.cat-group-pick').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', category: '' })
|
||||
await wrapper.find('tbody input[type="checkbox"]').setValue(true)
|
||||
await wrapper.find('[aria-label="选择归入的分类"]').setValue('7')
|
||||
await wrapper.findAll('button').find(b => b.text().includes('归入分类'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7)
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
await wrapper.find('[aria-label="删除分类 甲组"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(confirmMock.mock.calls.at(-1)![0].message).toContain('商品将保留')
|
||||
expect(jdApi.deleteJdProductGroup).toHaveBeenCalledWith(7)
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].groupId).toBe('')
|
||||
})
|
||||
|
||||
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
||||
const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const tip = empty.find('.empty-tip')
|
||||
|
||||
Reference in New Issue
Block a user