feat(phase-5): 后管京东数据库接口与页面+用户端采集入口——v1.4 Phase 5
This commit is contained in:
@@ -63,4 +63,7 @@ export const COMPANY_SCOPED_PAGES: readonly CompanyScopedPage[] = [
|
||||
// 外观专利无侵权数据(2026-11-10 v1.3):出表成功自动同步的只读明细,归属物化在行 company_id 列
|
||||
// (V189,同店铺密钥形状)⇒ 后端正门 readCompanyIdOrOwn(超管显式传才收窄,非超管强制本公司)。
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', apiFiles: ['src/pages/patent/appearance-patent-clean-api.ts'], pageFiles: ['src/pages/patent/AppearancePatentCleanItemsPage.vue'] },
|
||||
// 京东数据库(2026-11-14 v1.4):京麦店铺商品采集落库的只读镜像,归属物化在行 company_id 列
|
||||
// (V193,同外观专利 V189 形状)⇒ 后端正门 readCompanyIdOrOwn(超管显式传才收窄,非超管强制本公司)。
|
||||
{ menuKey: 'admin_jd_database', apiFiles: ['src/pages/jd/jd-product-api.ts'], pageFiles: ['src/pages/jd/JdDatabasePage.vue'] },
|
||||
]
|
||||
|
||||
@@ -125,6 +125,10 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
|
||||
text: '本页只读:出表成功后「结论=无侵权」的明细自动同步到这里,按分公司隔离分页展示;支持任务号/ASIN/国家/同步日期筛选,下载原表请到任务中心取结果文件。',
|
||||
steps: ['筛选记录', '核对结论明细', '到任务中心下载原表'],
|
||||
},
|
||||
admin_jd_database: {
|
||||
text: '本页只读:客户端采集的京东店铺商品自动同步到这里(同店铺同商品只保留最新一次),按分公司隔离分页展示;点行查看全部属性与图片,可用自定义分组归档商品。',
|
||||
steps: ['筛选商品记录', '查看属性与图片明细', '按分组归档管理'],
|
||||
},
|
||||
}
|
||||
|
||||
/** 全部有独立/兜底提示的后台业务菜单 key。 */
|
||||
|
||||
@@ -0,0 +1,498 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东数据库页(v1.4 Phase 5):公司隔离的京东商品库,筛选行(店铺/商品编码/标题关键字/商品状态/
|
||||
* 分组/同步起止 date 对)+查询/导出/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination。
|
||||
* 骨架像素复刻「外观专利数据库」页(panel-box + LoadFailureBar + 自绘 table + 旧式分页);
|
||||
* 公司 tab 切换=清筛选重取(watch 体照外观专利页逐字形状);日期对护栏:起侧 max=止侧、
|
||||
* 止侧 min=起侧、两侧 @change 用 orderedPair 把倒挂交换回来(clampJdSyncedRange 照 clampDatePair)。
|
||||
* 日期初值故意留空:同步数据是累计集,默认当天会让首屏只剩今天同步的行
|
||||
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import {
|
||||
exportJdProductList,
|
||||
fetchJdProductGroups,
|
||||
fetchJdProductList,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import type { JdProductItem } from './jd-product-model.ts'
|
||||
import { jdPriceRange } from './jd-product-model.ts'
|
||||
import { createJdProductFilterState, JD_SALE_STATUS_HINT } from './jd-product-filter.ts'
|
||||
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
|
||||
import JdProductGroupDialog from './JdProductGroupDialog.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
|
||||
const companyTab = useCompanyTabStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<JdProductItem[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
/** 导出在途锁:避免连点导出把同一份过滤面重复请求两遍。 */
|
||||
const exporting = ref(false)
|
||||
const filter = reactive(createJdProductFilterState())
|
||||
/** 分组下拉选项:公司 tab 切换时重取;选项失败不拦列表,只回空下拉(可见「全部分组」)。 */
|
||||
const groupOptions = ref<JdProductGroup[]>([])
|
||||
/** 分组管理弹窗与详情抽屉。 */
|
||||
const groupDialogVisible = ref(false)
|
||||
const detailItem = ref<JdProductItem | null>(null)
|
||||
const detailVisible = ref(false)
|
||||
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampJdSyncedRange(): void {
|
||||
const [s, e] = orderedPair(filter.syncedFrom, filter.syncedTo)
|
||||
filter.syncedFrom = s
|
||||
filter.syncedTo = e
|
||||
}
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
|
||||
/** 分组选项失败静默回空——分组只是筛选项,不该让它把首屏行集一起拖死。 */
|
||||
async function loadGroupOptions(): Promise<void> {
|
||||
try {
|
||||
groupOptions.value = await fetchJdProductGroups(companyTab.requestCompanyId)
|
||||
} catch {
|
||||
groupOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/** 分组管理弹窗里做过变更:分组下拉与列表都刷新(删除分组后行集的 groupName 会变)。 */
|
||||
async function onGroupChanged(): Promise<void> {
|
||||
await loadGroupOptions()
|
||||
page.value = 1
|
||||
await load()
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
const result = await fetchJdProductList({
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
shopName: filter.shopName,
|
||||
productCode: filter.productCode,
|
||||
titleKeyword: filter.titleKeyword,
|
||||
saleStatus: filter.saleStatus,
|
||||
groupId: filter.groupId,
|
||||
syncedFrom: filter.syncedFrom,
|
||||
syncedTo: filter.syncedTo,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
if (result.page >= 1) page.value = result.page
|
||||
} catch (error) {
|
||||
loadFailure.value = loadFailureMessage(error, '京东商品列表加载失败')
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出与页签同一过滤面(含公司 tab 与分组),服务端全量出 xlsx;成功后浏览器落盘,失败弹可读文案。 */
|
||||
async function exportAll(): Promise<void> {
|
||||
if (exporting.value) return
|
||||
exporting.value = true
|
||||
try {
|
||||
const result = await exportJdProductList({
|
||||
shopName: filter.shopName,
|
||||
productCode: filter.productCode,
|
||||
titleKeyword: filter.titleKeyword,
|
||||
saleStatus: filter.saleStatus,
|
||||
groupId: filter.groupId,
|
||||
syncedFrom: filter.syncedFrom,
|
||||
syncedTo: filter.syncedTo,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
const url = URL.createObjectURL(result.blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = result.filename
|
||||
document.body.appendChild(anchor)
|
||||
anchor.click()
|
||||
anchor.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
showAdminFeedback(`已导出 ${result.filename}`, 'success')
|
||||
} catch (error) {
|
||||
const message = error instanceof Error && error.message ? error.message : '导出失败,请稍后重试'
|
||||
showAdminFeedback(message, 'error')
|
||||
} finally {
|
||||
exporting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function apply(): void {
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
/** 重置:筛选面回出厂空态,回第一页重取。 */
|
||||
function reset(): void {
|
||||
Object.assign(filter, createJdProductFilterState())
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function changePage(next: number): void {
|
||||
if (next < 1 || next > totalPages.value) return
|
||||
page.value = next
|
||||
void load()
|
||||
}
|
||||
|
||||
function changeSize(size: number) {
|
||||
pageSize.value = size
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function openDetail(item: JdProductItem): void {
|
||||
detailItem.value = item
|
||||
detailVisible.value = true
|
||||
}
|
||||
|
||||
function closeDetail(): void {
|
||||
detailVisible.value = false
|
||||
detailItem.value = null
|
||||
}
|
||||
|
||||
// 切公司 = 重新取数:店铺/编码/关键字/状态/分组是上一家选中的值,在新一家的行集里筛不出东西,
|
||||
// 必须一起清,分组选项也按新公司重取(选项集是公司隔离的)。
|
||||
watch(() => companyTab.activeId, () => { filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.saleStatus = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void load() })
|
||||
|
||||
onMounted(() => {
|
||||
void loadGroupOptions()
|
||||
void load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="jd-database-view">
|
||||
<section class="panel-box">
|
||||
<div class="jd-panel-head">
|
||||
<h3>京东数据库</h3>
|
||||
<button class="btn btn-secondary" type="button" @click="groupDialogVisible = true">管理分组</button>
|
||||
</div>
|
||||
|
||||
<div class="jd-filter-row">
|
||||
<div class="form-group">
|
||||
<label>店铺</label>
|
||||
<input v-model="filter.shopName" type="text" placeholder="输入店铺名" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>商品编码</label>
|
||||
<input v-model="filter.productCode" type="text" placeholder="输入商品编码" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>标题关键字</label>
|
||||
<input v-model="filter.titleKeyword" type="text" placeholder="输入标题关键字" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>商品状态</label>
|
||||
<input v-model="filter.saleStatus" type="text" :placeholder="JD_SALE_STATUS_HINT" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<!-- 分组选中即查:选完立刻按该分组过滤刷新(回第一页),不必再点查询。 -->
|
||||
<select v-model="filter.groupId" @change="apply">
|
||||
<option value="">全部分组</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>同步开始日期</label>
|
||||
<input v-model="filter.syncedFrom" type="date" :max="filter.syncedTo" @change="clampJdSyncedRange" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>同步结束日期</label>
|
||||
<input v-model="filter.syncedTo" type="date" :min="filter.syncedFrom" @change="clampJdSyncedRange" />
|
||||
</div>
|
||||
<div class="jd-filter-actions">
|
||||
<button class="btn" type="button" @click="apply">查询</button>
|
||||
<button class="btn btn-export" type="button" :disabled="exporting" @click="exportAll">
|
||||
{{ exporting ? '导出中...' : '导出' }}
|
||||
</button>
|
||||
<button class="btn btn-secondary" type="button" @click="reset">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<div class="jd-toolbar">
|
||||
<span class="jd-summary">共 {{ total }} 条京东商品</span>
|
||||
</div>
|
||||
<div class="table-scroll jd-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 76px">主图</th>
|
||||
<th style="width: 120px">店铺</th>
|
||||
<th style="width: 110px">商品编码</th>
|
||||
<th>标题</th>
|
||||
<th style="width: 90px">品牌</th>
|
||||
<th style="width: 110px">价格区间</th>
|
||||
<th style="width: 64px">库存</th>
|
||||
<th style="width: 80px">状态</th>
|
||||
<th style="width: 100px">分组</th>
|
||||
<th style="width: 170px">京东更新时间</th>
|
||||
<th style="width: 170px">同步时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="row in rows" :key="row.id" class="jd-row" @click="openDetail(row)">
|
||||
<td>
|
||||
<img v-if="row.mainImageUrl" class="jd-thumb" :src="row.mainImageUrl" alt="" loading="lazy" />
|
||||
<span v-else class="empty-mini">无图</span>
|
||||
</td>
|
||||
<td :title="row.shopName || ''">{{ row.shopName || '-' }}</td>
|
||||
<td class="mono-cell">{{ row.productCode || '-' }}</td>
|
||||
<td class="title-cell" :title="row.title">{{ row.title || '-' }}</td>
|
||||
<td>{{ row.brand || '-' }}</td>
|
||||
<td>{{ jdPriceRange(row) || '-' }}</td>
|
||||
<td>{{ row.stockTotal ?? '-' }}</td>
|
||||
<td>{{ row.saleStatus || '-' }}</td>
|
||||
<td :title="row.groupName || ''">{{ row.groupName || '未分组' }}</td>
|
||||
<td>{{ formatDateTime(row.jdUpdatedAt || '') }}</td>
|
||||
<td>{{ formatDateTime(row.syncedAt || '') }}</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="11" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="11" class="empty-tip">暂无京东商品数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<OldPagination :total="total" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
|
||||
</section>
|
||||
|
||||
<JdProductDetailDrawer
|
||||
:item="detailItem"
|
||||
:visible="detailVisible"
|
||||
:company-id="companyTab.requestCompanyId"
|
||||
@close="closeDetail"
|
||||
/>
|
||||
<JdProductGroupDialog
|
||||
:visible="groupDialogVisible"
|
||||
:company-id="companyTab.requestCompanyId"
|
||||
@close="groupDialogVisible = false"
|
||||
@changed="onGroupChanged"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻「外观专利数据库」页样式(panel-box + 自绘表格 + 旧式分页),表头多一列「京东更新时间」。 */
|
||||
.jd-database-view {
|
||||
font-family: inherit;
|
||||
color: var(--c-text, #24384d);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 16px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.jd-panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.jd-panel-head h3 {
|
||||
margin: 0;
|
||||
}
|
||||
.jd-filter-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, minmax(140px, 1fr)) auto;
|
||||
gap: 12px;
|
||||
align-items: end;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.jd-filter-row .form-group {
|
||||
min-width: 0;
|
||||
}
|
||||
.jd-filter-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.form-group input[type="date"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.jd-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.jd-summary {
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.jd-table-scroll > table {
|
||||
min-width: 1260px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
/* 点行开详情抽屉:行级 hover 已有底色反馈,光标再点一下提示可点。 */
|
||||
.jd-row {
|
||||
cursor: pointer;
|
||||
}
|
||||
.jd-thumb {
|
||||
display: block;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 6px;
|
||||
background: #f2f7fb;
|
||||
}
|
||||
.empty-mini {
|
||||
color: #8293a5;
|
||||
font-size: 12px;
|
||||
}
|
||||
.mono-cell {
|
||||
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.title-cell {
|
||||
max-width: 260px;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,463 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品详情抽屉(v1.4 Phase 5):点行打开,展示基本信息 + attrGroups 分块表格 +
|
||||
* 图片网格(MAIN/ATTR/DETAIL 三区,attr 图按 attrName 归并)。
|
||||
* 图片点击放大预览用自绘 modal-mask(先例:RecordsHistoryPage 的 thumb + modal-mask +
|
||||
* 原图新标签;不用 element-plus)。数据由本组件按 (id, companyId) 自取,失败条内提示可重试。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { fetchJdProductDetail } from './jd-product-api.ts'
|
||||
import type { JdProductImage, JdProductItem, JdProductAttrGroup } from './jd-product-model.ts'
|
||||
import { jdPriceRange } from './jd-product-model.ts'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
item: JdProductItem | null
|
||||
visible: boolean
|
||||
companyId: number | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void }>()
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const attrGroups = ref<JdProductAttrGroup[]>([])
|
||||
const images = ref<JdProductImage[]>([])
|
||||
const attrJsonRaw = ref('')
|
||||
|
||||
/** 图片三区:MAIN / ATTR / DETAIL;未知类型归 DETAIL 之外的「其他」,不丢。 */
|
||||
const mainImages = computed(() => images.value.filter((image) => image.imageType === 'MAIN'))
|
||||
const attrImageGroups = computed(() => {
|
||||
const buckets = new Map<string, JdProductImage[]>()
|
||||
for (const image of images.value) {
|
||||
if (image.imageType !== 'ATTR') continue
|
||||
const key = image.attrName || '属性图'
|
||||
const bucket = buckets.get(key)
|
||||
if (bucket) bucket.push(image)
|
||||
else buckets.set(key, [image])
|
||||
}
|
||||
return [...buckets.entries()].map(([attrName, list]) => ({ attrName, list }))
|
||||
})
|
||||
const detailImages = computed(() => images.value.filter((image) => image.imageType === 'DETAIL'))
|
||||
const otherImages = computed(() =>
|
||||
images.value.filter((image) => image.imageType !== 'MAIN' && image.imageType !== 'ATTR' && image.imageType !== 'DETAIL'),
|
||||
)
|
||||
|
||||
/** 放大预览:点缩略图弹自绘 modal-mask,原图可新标签打开。 */
|
||||
const previewVisible = ref(false)
|
||||
const previewUrl = ref('')
|
||||
|
||||
function openPreview(url: string): void {
|
||||
previewUrl.value = url
|
||||
previewVisible.value = true
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
previewVisible.value = false
|
||||
emit('close')
|
||||
}
|
||||
|
||||
async function loadDetail(): Promise<void> {
|
||||
const item = props.item
|
||||
if (!item) return
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
attrGroups.value = []
|
||||
images.value = []
|
||||
attrJsonRaw.value = ''
|
||||
try {
|
||||
const detail = await fetchJdProductDetail(item.id, props.companyId)
|
||||
attrGroups.value = detail.attrGroups
|
||||
images.value = detail.images
|
||||
attrJsonRaw.value = detail.attrJsonRaw
|
||||
if (!detail.attrGroups.length && detail.attrJsonRaw) {
|
||||
// 结构化解析失败但原文在:兜底展示原文,不静默吞
|
||||
loadFailure.value = ''
|
||||
}
|
||||
} catch (error) {
|
||||
loadFailure.value = requestErrorMessage(error) || '商品详情加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [props.visible, props.item?.id] as const,
|
||||
([visible]) => {
|
||||
previewVisible.value = false
|
||||
previewUrl.value = ''
|
||||
if (visible && props.item) void loadDetail()
|
||||
},
|
||||
)
|
||||
|
||||
function dash(value: string | number | null | undefined): string {
|
||||
const text = value === null || value === undefined ? '' : String(value).trim()
|
||||
return text || '-'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="drawer-mask" @click.self="close">
|
||||
<aside class="drawer">
|
||||
<header class="drawer-head">
|
||||
<h3>商品详情{{ item?.productCode ? ` · ${item.productCode}` : '' }}</h3>
|
||||
<button class="drawer-close" type="button" aria-label="关闭" @click="close">×</button>
|
||||
</header>
|
||||
|
||||
<div class="drawer-body">
|
||||
<div v-if="loadFailure" class="drawer-failure">
|
||||
<span>{{ loadFailure }}</span>
|
||||
<button class="btn btn-secondary" type="button" @click="loadDetail">重试</button>
|
||||
</div>
|
||||
<p v-else-if="loading" class="drawer-tip">加载中...</p>
|
||||
|
||||
<template v-else>
|
||||
<section class="detail-block">
|
||||
<h4>基本信息</h4>
|
||||
<dl class="info-grid">
|
||||
<div class="info-item info-item-wide">
|
||||
<dt>标题</dt>
|
||||
<dd :title="item?.title || ''">{{ dash(item?.title) }}</dd>
|
||||
</div>
|
||||
<div class="info-item"><dt>品牌</dt><dd>{{ dash(item?.brand) }}</dd></div>
|
||||
<div class="info-item"><dt>类目</dt><dd :title="item?.categoryPath || ''">{{ dash(item?.categoryPath) }}</dd></div>
|
||||
<div class="info-item"><dt>货号</dt><dd>{{ dash(item?.productCode) }}</dd></div>
|
||||
<div class="info-item"><dt>价格区间</dt><dd>{{ dash(jdPriceRange(item ?? { priceMin: '', priceMax: '' })) }}</dd></div>
|
||||
<div class="info-item"><dt>库存</dt><dd>{{ dash(item?.stockTotal) }}</dd></div>
|
||||
<div class="info-item"><dt>状态</dt><dd>{{ dash(item?.saleStatus) }}</dd></div>
|
||||
<div class="info-item"><dt>京东创建时间</dt><dd>{{ formatDateTime(item?.jdUpdatedAt || '') }}</dd></div>
|
||||
<div class="info-item"><dt>同步时间</dt><dd>{{ formatDateTime(item?.syncedAt || '') }}</dd></div>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section v-if="attrGroups.length" class="detail-block">
|
||||
<h4>属性</h4>
|
||||
<div v-for="group in attrGroups" :key="group.groupName" class="attr-group">
|
||||
<h5>{{ group.groupName }}</h5>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr v-for="(attr, index) in group.attrs" :key="`${attr.key}-${index}`">
|
||||
<th>{{ attr.label || attr.key || '-' }}</th>
|
||||
<td>{{ attr.value || '-' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-else-if="attrJsonRaw" class="detail-block">
|
||||
<h4>属性(原始 JSON)</h4>
|
||||
<pre class="attr-raw">{{ attrJsonRaw }}</pre>
|
||||
</section>
|
||||
|
||||
<section class="detail-block">
|
||||
<h4>主图</h4>
|
||||
<div v-if="mainImages.length" class="image-grid">
|
||||
<img
|
||||
v-for="image in mainImages"
|
||||
:key="image.url"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(image.url)"
|
||||
/>
|
||||
</div>
|
||||
<p v-else class="drawer-tip">暂无主图</p>
|
||||
</section>
|
||||
|
||||
<section v-for="bucket in attrImageGroups" :key="bucket.attrName" class="detail-block">
|
||||
<h4>属性图 · {{ bucket.attrName }}</h4>
|
||||
<div class="image-grid">
|
||||
<img
|
||||
v-for="image in bucket.list"
|
||||
:key="image.url"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(image.url)"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="detail-block">
|
||||
<h4>详情图</h4>
|
||||
<div v-if="detailImages.length" class="image-grid">
|
||||
<img
|
||||
v-for="image in detailImages"
|
||||
:key="image.url"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(image.url)"
|
||||
/>
|
||||
</div>
|
||||
<p v-else class="drawer-tip">暂无详情图</p>
|
||||
</section>
|
||||
|
||||
<section v-if="otherImages.length" class="detail-block">
|
||||
<h4>其他图</h4>
|
||||
<div class="image-grid">
|
||||
<img
|
||||
v-for="image in otherImages"
|
||||
:key="image.url"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(image.url)"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div v-if="previewVisible" class="modal-mask" @click.self="previewVisible = false">
|
||||
<div class="preview-modal">
|
||||
<div class="preview-head">
|
||||
<h3>图片预览</h3>
|
||||
<button class="drawer-close" type="button" aria-label="关闭" @click="previewVisible = false">×</button>
|
||||
</div>
|
||||
<img class="preview-image" :src="previewUrl" alt="" />
|
||||
<div class="preview-foot">
|
||||
<a :href="previewUrl" target="_blank" rel="noopener">新标签打开原图</a>
|
||||
<button class="btn btn-secondary" type="button" @click="previewVisible = false">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.drawer-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2600;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
.drawer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(760px, 100%);
|
||||
height: 100%;
|
||||
background: #ffffff;
|
||||
box-shadow: -18px 0 40px rgba(39, 67, 94, 0.18);
|
||||
}
|
||||
.drawer-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid #dbe5ee;
|
||||
}
|
||||
.drawer-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
}
|
||||
.drawer-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.drawer-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
.drawer-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 16px 20px 28px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.drawer-tip {
|
||||
margin: 0;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.drawer-failure {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.detail-block h4 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 650;
|
||||
color: #4e6479;
|
||||
}
|
||||
.info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 10px 16px;
|
||||
margin: 0;
|
||||
}
|
||||
.info-item {
|
||||
min-width: 0;
|
||||
}
|
||||
.info-item-wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
.info-item dt {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.info-item dd {
|
||||
margin: 0;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.attr-group {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.attr-group h5 {
|
||||
margin: 0 0 6px;
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.attr-group table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.attr-group th,
|
||||
.attr-group td {
|
||||
padding: 7px 10px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
.attr-group th {
|
||||
width: 180px;
|
||||
background: #f2f7fb;
|
||||
color: #4e6479;
|
||||
font-weight: 600;
|
||||
}
|
||||
.attr-group tr:last-child th,
|
||||
.attr-group tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.attr-raw {
|
||||
margin: 0;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 12px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.image-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.image-grid img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 8px;
|
||||
background: #f2f7fb;
|
||||
cursor: zoom-in;
|
||||
}
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.preview-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(880px, 100%);
|
||||
max-height: 88vh;
|
||||
padding: 16px 20px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
}
|
||||
.preview-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.preview-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
color: #24384d;
|
||||
}
|
||||
.preview-image {
|
||||
display: block;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 68vh;
|
||||
margin: 12px 0;
|
||||
object-fit: contain;
|
||||
background: #f2f7fb;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.preview-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.preview-foot a {
|
||||
color: #2f5d8b;
|
||||
font-size: 13px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 38px;
|
||||
padding: 7px 16px;
|
||||
border-radius: 9px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border: 1px solid #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,352 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品分组管理弹窗(v1.4 Phase 5):新建/改名/删除,重名等业务失败把后端返回的中文文案
|
||||
* 原样展示在弹窗内(envelope code 非 0 → errorTextOf);删除前 openAdminConfirm 二次确认;
|
||||
* 变更成功后 emit('changed'),由页面刷新分组下拉与列表。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
fetchJdProductGroups,
|
||||
updateJdProductGroup,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
companyId: number | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void }>()
|
||||
|
||||
const loading = ref(false)
|
||||
const errorText = ref('')
|
||||
const groups = ref<JdProductGroup[]>([])
|
||||
/** 新建:名称 + 排序。 */
|
||||
const createName = ref('')
|
||||
const createSortOrder = ref(0)
|
||||
const creating = ref(false)
|
||||
/** 改名:正在编辑的分组 id 与草稿名。 */
|
||||
const editingId = ref(0)
|
||||
const editingName = ref('')
|
||||
const saving = ref(false)
|
||||
|
||||
const canCreate = computed(() => createName.value.trim().length > 0 && !creating.value && !saving.value)
|
||||
|
||||
async function loadGroups(): Promise<void> {
|
||||
loading.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
groups.value = await fetchJdProductGroups(props.companyId)
|
||||
} 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 submitCreate(): Promise<void> {
|
||||
const name = createName.value.trim()
|
||||
if (!name || creating.value) return
|
||||
creating.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: Math.floor(createSortOrder.value) || 0 }, props.companyId)
|
||||
createName.value = ''
|
||||
createSortOrder.value = 0
|
||||
groups.value = sortGroups(await fetchJdProductGroups(props.companyId))
|
||||
emit('changed')
|
||||
} 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 }, props.companyId)
|
||||
cancelRename()
|
||||
groups.value = sortGroups(await fetchJdProductGroups(props.companyId))
|
||||
emit('changed')
|
||||
} 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}」吗?删除后该组商品回到未分组。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await deleteJdProductGroup(group.id, props.companyId)
|
||||
groups.value = sortGroups(await fetchJdProductGroups(props.companyId))
|
||||
emit('changed')
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '删除分组失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
createSortOrder.value = 0
|
||||
void loadGroups()
|
||||
}
|
||||
},
|
||||
)
|
||||
</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>
|
||||
|
||||
<div class="group-create">
|
||||
<input
|
||||
v-model="createName"
|
||||
type="text"
|
||||
placeholder="输入新分组名称"
|
||||
@keyup.enter="submitCreate"
|
||||
/>
|
||||
<input v-model.number="createSortOrder" type="number" class="sort-input" aria-label="排序" />
|
||||
<button class="btn" type="button" :disabled="!canCreate" @click="submitCreate">
|
||||
{{ creating ? '新建中...' : '新建分组' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
<p v-else-if="loading" class="group-tip">加载中...</p>
|
||||
|
||||
<ul class="group-list">
|
||||
<li v-for="group in groups" :key="group.id" class="group-row">
|
||||
<template v-if="editingId === group.id">
|
||||
<input v-model="editingName" type="text" @keyup.enter="submitRename(group)" />
|
||||
<button class="btn btn-small" type="button" :disabled="saving" @click="submitRename(group)">保存</button>
|
||||
<button class="btn btn-secondary btn-small" type="button" @click="cancelRename">取消</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="group-name" :title="group.name">{{ group.name }}</span>
|
||||
<span class="group-meta">排序 {{ group.sortOrder }} · {{ group.productCount }} 个商品</span>
|
||||
<span class="group-actions">
|
||||
<button class="btn btn-secondary btn-small" type="button" @click="startRename(group)">改名</button>
|
||||
<button class="btn btn-danger btn-small" type="button" :disabled="saving" @click="removeGroup(group)">删除</button>
|
||||
</span>
|
||||
</template>
|
||||
</li>
|
||||
<li v-if="!loading && !groups.length && !errorText" class="group-tip">暂无分组,先新建一个</li>
|
||||
</ul>
|
||||
</div>
|
||||
</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(560px, 100%);
|
||||
max-height: 84vh;
|
||||
padding: 18px 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;
|
||||
}
|
||||
.group-create {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin: 14px 0 10px;
|
||||
}
|
||||
.group-create input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 38px;
|
||||
padding: 7px 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;
|
||||
}
|
||||
.sort-input {
|
||||
flex: 0 0 88px !important;
|
||||
}
|
||||
.group-error {
|
||||
margin: 0 0 8px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
}
|
||||
.group-tip {
|
||||
margin: 0 0 8px;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
}
|
||||
.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: 10px;
|
||||
padding: 9px 4px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.group-row input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 34px;
|
||||
padding: 5px 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;
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.group-actions {
|
||||
flex: none;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.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: 32px;
|
||||
padding: 4px 12px;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.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>
|
||||
@@ -0,0 +1,191 @@
|
||||
/** 京东数据库查询适配(v1.4 Phase 5):GET /api/admin/jd-products + 分组端点 /api/admin/jd-product-groups。
|
||||
* 只读列表+导出+分组管理:公司 tab 的值由本发送口从原始入参自己下传
|
||||
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。 */
|
||||
import { http } from '@/api/http'
|
||||
import { errorTextOf, unwrap } from '../../api/envelope.ts'
|
||||
import {
|
||||
toJdProductExportParams,
|
||||
toJdProductListParams,
|
||||
type JdProductExportParams,
|
||||
type JdProductExportQuery,
|
||||
type JdProductListParams,
|
||||
} from './jd-product-filter.ts'
|
||||
import {
|
||||
parseJdProductDetail,
|
||||
parseJdProductPage,
|
||||
type JdProductPageResult,
|
||||
} from './jd-product-model.ts'
|
||||
|
||||
export const JD_PRODUCT_ENDPOINT = '/api/admin/jd-products'
|
||||
export const JD_PRODUCT_GROUP_ENDPOINT = '/api/admin/jd-product-groups'
|
||||
|
||||
export async function fetchJdProductList(
|
||||
params: JdProductListParams,
|
||||
): Promise<JdProductPageResult> {
|
||||
const query = toJdProductListParams(
|
||||
{
|
||||
shopName: params.shopName ?? '',
|
||||
productCode: params.productCode ?? '',
|
||||
titleKeyword: params.titleKeyword ?? '',
|
||||
saleStatus: params.saleStatus ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
syncedFrom: params.syncedFrom ?? '',
|
||||
syncedTo: params.syncedTo ?? '',
|
||||
},
|
||||
params.page,
|
||||
params.pageSize,
|
||||
)
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_ENDPOINT, { params: query })
|
||||
return parseJdProductPage(data)
|
||||
}
|
||||
|
||||
/** 详情:GET /api/admin/jd-products/{id}(信封 data=主字段 + attrGroups + attrJsonRaw + images)。 */
|
||||
export async function fetchJdProductDetail(
|
||||
id: number,
|
||||
companyId: number | null,
|
||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, { params: query })
|
||||
return parseJdProductDetail(data)
|
||||
}
|
||||
|
||||
export interface JdProductExportResult {
|
||||
blob: Blob
|
||||
filename: string
|
||||
}
|
||||
|
||||
/** 从 Content-Disposition 取 filename*(UTF-8 轨,后端 DownloadHeaderUtil 双轨口径),取不到回退常量名。 */
|
||||
function exportFilenameOf(disposition: unknown): string {
|
||||
const raw = typeof disposition === 'string' ? disposition : ''
|
||||
const star = /filename\*=(?:UTF-8'')?([^;]+)/i.exec(raw)
|
||||
if (star?.[1]) {
|
||||
try {
|
||||
return decodeURIComponent(star[1].trim().replace(/^"|"$/g, '')) || '京东数据库.xlsx'
|
||||
} catch {
|
||||
// 编码坏的 filename* 当作没有,走 ASCII 轨或常量名
|
||||
}
|
||||
}
|
||||
const plain = /filename="([^"]+)"/i.exec(raw)
|
||||
return plain?.[1] || '京东数据库.xlsx'
|
||||
}
|
||||
|
||||
/** 导出当前过滤面全量明细:与列表共用同一过滤面取值口(含公司 tab),blob 下载交给页面触发保存。 */
|
||||
export async function exportJdProductList(
|
||||
params: JdProductExportParams,
|
||||
): Promise<JdProductExportResult> {
|
||||
const query: JdProductExportQuery = toJdProductExportParams({
|
||||
shopName: params.shopName ?? '',
|
||||
productCode: params.productCode ?? '',
|
||||
titleKeyword: params.titleKeyword ?? '',
|
||||
saleStatus: params.saleStatus ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
syncedFrom: params.syncedFrom ?? '',
|
||||
syncedTo: params.syncedTo ?? '',
|
||||
})
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
const response = await http.get<Blob>(`${JD_PRODUCT_ENDPOINT}/export`, {
|
||||
params: query,
|
||||
responseType: 'blob',
|
||||
timeout: 120_000,
|
||||
})
|
||||
const disposition = response.headers?.['content-disposition']
|
||||
if (!disposition) {
|
||||
// 没有附件头=服务端回了业务错误信封(HTTP 200 + JSON),把 blob 文本解回错误文案抛给页面
|
||||
const blob = response.data
|
||||
let payload: unknown = null
|
||||
if (blob && typeof blob.text === 'function') {
|
||||
const text = await blob.text()
|
||||
try {
|
||||
payload = JSON.parse(text)
|
||||
} catch {
|
||||
payload = text
|
||||
}
|
||||
}
|
||||
throw new Error(errorTextOf(payload))
|
||||
}
|
||||
return { blob: response.data, filename: exportFilenameOf(disposition) }
|
||||
}
|
||||
|
||||
/** 分组行(GET 列表返回:[{id,name,sortOrder,productCount}])。 */
|
||||
export interface JdProductGroup {
|
||||
id: number
|
||||
name: string
|
||||
sortOrder: number
|
||||
productCount: number
|
||||
}
|
||||
|
||||
/** 分组管理的写入负载(POST / PUT body:{name, sortOrder})。 */
|
||||
export interface JdProductGroupPayload {
|
||||
name: string
|
||||
sortOrder: number
|
||||
}
|
||||
|
||||
/** 分组信封是 `{code, message, data}` 三段式:code 非 0 =业务失败,message 是中文文案
|
||||
* (重名等),用 errorTextOf 取出来抛给界面展示(unwrap 只认 success=false,不认 code)。 */
|
||||
function groupDataOf<T>(payload: unknown): T {
|
||||
const record = payload && typeof payload === 'object' ? (payload as Record<string, unknown>) : null
|
||||
if (record && typeof record.code === 'number' && record.code !== 0) {
|
||||
throw new Error(errorTextOf(payload))
|
||||
}
|
||||
return unwrap<T>(payload)
|
||||
}
|
||||
|
||||
function numberOr(value: unknown, fallback: number): number {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : fallback
|
||||
}
|
||||
|
||||
/** 分组下拉/管理列表;失败由页面自己兜(分组只是筛选项,不拦首屏行集)。 */
|
||||
export async function fetchJdProductGroups(companyId: number | null): Promise<JdProductGroup[]> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_GROUP_ENDPOINT, { params: query })
|
||||
const core = unwrap<unknown>(data)
|
||||
if (!Array.isArray(core)) return []
|
||||
const out: JdProductGroup[] = []
|
||||
for (const raw of core) {
|
||||
if (!raw || typeof raw !== 'object') continue
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = numberOr(record.id, 0)
|
||||
if (id <= 0) continue
|
||||
out.push({
|
||||
id,
|
||||
name: typeof record.name === 'string' ? record.name.trim() : '',
|
||||
sortOrder: numberOr(record.sortOrder ?? record.sort_order, 0),
|
||||
productCount: numberOr(record.productCount ?? record.product_count, 0),
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 新建分组;重名等业务失败把后端中文文案抛回(页面直接展示)。 */
|
||||
export async function createJdProductGroup(
|
||||
payload: JdProductGroupPayload,
|
||||
companyId: number | null,
|
||||
): Promise<JdProductGroup | null> {
|
||||
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
||||
if (companyId != null) body.company_id = companyId
|
||||
const { data } = await http.post<unknown>(JD_PRODUCT_GROUP_ENDPOINT, body)
|
||||
return groupDataOf<JdProductGroup | null>(data)
|
||||
}
|
||||
|
||||
/** 改名/改排序;业务失败文案同上。 */
|
||||
export async function updateJdProductGroup(
|
||||
id: number,
|
||||
payload: JdProductGroupPayload,
|
||||
companyId: number | null,
|
||||
): Promise<JdProductGroup | null> {
|
||||
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
||||
if (companyId != null) body.company_id = companyId
|
||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`, body)
|
||||
return groupDataOf<JdProductGroup | null>(data)
|
||||
}
|
||||
|
||||
/** 删除分组;业务失败文案同上。 */
|
||||
export async function deleteJdProductGroup(id: number, companyId: number | null): Promise<void> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`, { params: query })
|
||||
groupDataOf<unknown>(data)
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/** 京东数据库页筛选纯函数(v1.4 Phase 5):店铺/商品编码/标题关键字/商品状态/分组/同步起止 + snake 分页参数。
|
||||
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 20、上限 100)、`shop_name`、
|
||||
* `product_code`、`title_keyword`、`sale_status`、`group_id`、`synced_from`/`synced_to`
|
||||
* (ISO yyyy-MM-dd;空白不下发)。
|
||||
* 分页钳制(铁律 15):page < 1 归 1、上限 10_000(后端 CR-18 同值),(page-1)*page_size
|
||||
* 最大 999_900,Number.MAX_SAFE_INTEGER 也不会把乘积顶出安全整数。纯逻辑,node --test 直测。
|
||||
* 公司维不在这里:归一化构造器不认识 company_id(同外观专利 filter 惯例),由 api 发送口从
|
||||
* 原始入参自己下传——取值口由 company-tab-wiring 护栏的发送行钉看守。
|
||||
* 日期默认空字符串:同步台账是累计数据,默认当天会让首屏只剩今天同步的行
|
||||
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
||||
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
|
||||
|
||||
/** 每页条数默认 20(v1.4 §3.4),上限 100。 */
|
||||
export const JD_PRODUCT_PAGE_SIZE = 20
|
||||
export const JD_PRODUCT_MAX_PAGE_SIZE = 100
|
||||
/** 页码上限:与后端 MAX_PAGE(CR-18 先例,外观专利同值)对齐,两侧不漂。 */
|
||||
export const JD_PRODUCT_MAX_PAGE = 10_000
|
||||
|
||||
/** 商品状态值域(契约口径):筛选为简单文本输入,placeholder 提示值域。 */
|
||||
export const JD_SALE_STATUS_HINT = '上架中/已下架/审核中/草稿'
|
||||
|
||||
export interface JdProductFilterState {
|
||||
/** 店铺名(模糊),空串不限。 */
|
||||
shopName: string
|
||||
/** 商品编码,空串不限。 */
|
||||
productCode: string
|
||||
/** 标题关键字,空串不限。 */
|
||||
titleKeyword: string
|
||||
/** 商品状态:上架中/已下架/审核中/草稿,空串=全部。 */
|
||||
saleStatus: string
|
||||
/** 分组 id 文本(分组管理里那一行),空串=全部分组。 */
|
||||
groupId: string
|
||||
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
syncedFrom: string
|
||||
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
syncedTo: string
|
||||
}
|
||||
|
||||
export function createJdProductFilterState(): JdProductFilterState {
|
||||
return { shopName: '', productCode: '', titleKeyword: '', saleStatus: '', groupId: '', syncedFrom: '', syncedTo: '' }
|
||||
}
|
||||
|
||||
/** 是否有任一激活筛选条件。 */
|
||||
export function jdProductFilterActive(state: JdProductFilterState): boolean {
|
||||
if ((state.shopName || '').trim()) return true
|
||||
if ((state.productCode || '').trim()) return true
|
||||
if ((state.titleKeyword || '').trim()) return true
|
||||
if ((state.saleStatus || '').trim()) return true
|
||||
if ((state.groupId || '').trim()) return true
|
||||
if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/** 序列化到后端的列表查询参数(snake_case,仅下发非空字段)。 */
|
||||
export interface JdProductQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
shop_name?: string
|
||||
product_code?: string
|
||||
title_keyword?: string
|
||||
sale_status?: string
|
||||
group_id?: number
|
||||
synced_from?: string
|
||||
synced_to?: string
|
||||
/** 公司 tab:白名单构造不点名它,字段只为 api 发送口的 `query.company_id = params.companyId` 存在。 */
|
||||
company_id?: number
|
||||
}
|
||||
|
||||
/** 导出查询参数:与列表同一过滤面、无分页(全量导出由服务侧上限兜住)。 */
|
||||
export interface JdProductExportQuery {
|
||||
shop_name?: string
|
||||
product_code?: string
|
||||
title_keyword?: string
|
||||
sale_status?: string
|
||||
group_id?: number
|
||||
synced_from?: string
|
||||
synced_to?: string
|
||||
/** 公司 tab 同列表口径:白名单构造不点名,由 api 发送口下传。 */
|
||||
company_id?: number
|
||||
}
|
||||
|
||||
/** api 模块的入参:筛选态 + 分页 + 公司值(camel)。 */
|
||||
export interface JdProductListParams {
|
||||
page: number
|
||||
pageSize: number
|
||||
shopName?: string
|
||||
productCode?: string
|
||||
titleKeyword?: string
|
||||
saleStatus?: string
|
||||
groupId?: string
|
||||
syncedFrom?: string
|
||||
syncedTo?: string
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
/** api 导出入口的入参:筛选态 + 公司值(camel,无分页)。 */
|
||||
export interface JdProductExportParams {
|
||||
shopName?: string
|
||||
productCode?: string
|
||||
titleKeyword?: string
|
||||
saleStatus?: string
|
||||
groupId?: string
|
||||
syncedFrom?: string
|
||||
syncedTo?: string
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
/** 过滤态 → 过滤面参数(snake_case,仅下发非空字段);列表与导出共用这一个取值口,
|
||||
* 「导出的过滤面和页签看到的永远同源」由这条单出口保证,不出现两处各算各的。 */
|
||||
function toJdProductFilterQuery(state: JdProductFilterState): JdProductExportQuery {
|
||||
const query: JdProductExportQuery = {}
|
||||
const shopName = (state.shopName || '').trim()
|
||||
if (shopName) query.shop_name = shopName
|
||||
const productCode = (state.productCode || '').trim()
|
||||
if (productCode) query.product_code = productCode
|
||||
const titleKeyword = (state.titleKeyword || '').trim()
|
||||
if (titleKeyword) query.title_keyword = titleKeyword
|
||||
const saleStatus = (state.saleStatus || '').trim()
|
||||
if (saleStatus) query.sale_status = saleStatus
|
||||
const groupId = Number.parseInt((state.groupId || '').trim(), 10)
|
||||
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
|
||||
const syncedFrom = validIsoDateOrUndefined(state.syncedFrom)
|
||||
if (syncedFrom) query.synced_from = syncedFrom
|
||||
const syncedTo = validIsoDateOrUndefined(state.syncedTo)
|
||||
if (syncedTo) query.synced_to = syncedTo
|
||||
return query
|
||||
}
|
||||
|
||||
/** 过滤态 + 分页 → 列表查询参数;空白/非法日期不下发,分页钳制在此单出口(不含公司维)。 */
|
||||
export function toJdProductListParams(
|
||||
state: JdProductFilterState,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
): JdProductQuery {
|
||||
const safePage = Math.min(Math.max(Math.floor(page) || 1, 1), JD_PRODUCT_MAX_PAGE)
|
||||
const rawSize = Math.floor(pageSize) || JD_PRODUCT_PAGE_SIZE
|
||||
const safeSize = Math.min(Math.max(rawSize, 1), JD_PRODUCT_MAX_PAGE_SIZE)
|
||||
return {
|
||||
page: safePage,
|
||||
page_size: safeSize,
|
||||
...toJdProductFilterQuery(state),
|
||||
}
|
||||
}
|
||||
|
||||
/** 过滤态 → 导出查询参数(无分页;归一规则与列表逐字同源)。 */
|
||||
export function toJdProductExportParams(state: JdProductFilterState): JdProductExportQuery {
|
||||
return toJdProductFilterQuery(state)
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/** 京东数据库列表查询模型(v1.4 Phase 5):解析 JdProductPageVo(camel),纯逻辑零依赖。
|
||||
* camel 为正、snake 容错(与外观专利/去重页模型同形),缺 id 弃行。
|
||||
* 纯函数、无框架依赖(envelope 只借纯 unwrap),node --test 可直测。 */
|
||||
import { unwrap } from '../../api/envelope.ts'
|
||||
|
||||
/** 京东商品列表行(后端 JdProductItemVo,camel 为正)。 */
|
||||
export interface JdProductItem {
|
||||
id: number
|
||||
shopId: number | null
|
||||
shopName: string
|
||||
productCode: string
|
||||
skuId: string
|
||||
title: string
|
||||
brand: string
|
||||
categoryPath: string
|
||||
priceMin: string
|
||||
priceMax: string
|
||||
stockTotal: number | null
|
||||
/** 上架中/已下架/审核中/草稿。 */
|
||||
saleStatus: string
|
||||
listTab: string
|
||||
jdUpdatedAt: string
|
||||
mainImageUrl: string
|
||||
attrCount: number | null
|
||||
imageCount: number | null
|
||||
groupId: number | null
|
||||
groupName: string
|
||||
syncedAt?: string
|
||||
}
|
||||
|
||||
export interface JdProductPageResult {
|
||||
items: JdProductItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
/** 前端首屏默认容量(与 filter 侧 JD_PRODUCT_PAGE_SIZE 同值 20)。 */
|
||||
export const JD_PRODUCT_DEFAULT_SIZE = 20
|
||||
|
||||
export function emptyJdProductPage(): JdProductPageResult {
|
||||
return { items: [], total: 0, page: 1, pageSize: JD_PRODUCT_DEFAULT_SIZE }
|
||||
}
|
||||
|
||||
function text(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function numberOrNull(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
|
||||
}
|
||||
|
||||
/** 价格区间展示:min/max 都空为 -,只空一侧给单值。 */
|
||||
export function jdPriceRange(item: Pick<JdProductItem, 'priceMin' | 'priceMax'>): string {
|
||||
const min = (item.priceMin || '').trim()
|
||||
const max = (item.priceMax || '').trim()
|
||||
if (min && max) return min === max ? min : `${min} ~ ${max}`
|
||||
return min || max || ''
|
||||
}
|
||||
|
||||
/** 解析单行;缺 id 视为无效。camel 为正、snake 容错。 */
|
||||
export function toJdProductItem(raw: unknown): JdProductItem | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = numberOrNull(record.id)
|
||||
if (id === null) return null
|
||||
return {
|
||||
id,
|
||||
shopId: numberOrNull(record.shopId ?? record.shop_id),
|
||||
shopName: text(record.shopName ?? record.shop_name),
|
||||
productCode: text(record.productCode ?? record.product_code),
|
||||
skuId: text(record.skuId ?? record.sku_id),
|
||||
title: text(record.title),
|
||||
brand: text(record.brand),
|
||||
categoryPath: text(record.categoryPath ?? record.category_path),
|
||||
priceMin: text(record.priceMin ?? record.price_min),
|
||||
priceMax: text(record.priceMax ?? record.price_max),
|
||||
stockTotal: numberOrNull(record.stockTotal ?? record.stock_total),
|
||||
saleStatus: text(record.saleStatus ?? record.sale_status),
|
||||
listTab: text(record.listTab ?? record.list_tab),
|
||||
jdUpdatedAt: text(record.jdUpdatedAt ?? record.jd_updated_at),
|
||||
mainImageUrl: text(record.mainImageUrl ?? record.main_image_url),
|
||||
attrCount: numberOrNull(record.attrCount ?? record.attr_count),
|
||||
imageCount: numberOrNull(record.imageCount ?? record.image_count),
|
||||
groupId: numberOrNull(record.groupId ?? record.group_id),
|
||||
groupName: text(record.groupName ?? record.group_name),
|
||||
syncedAt: text(record.syncedAt ?? record.synced_at) || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
/** 归一化分页负载(信封或已解包 VO)为前端结果;缺省字段回默认。 */
|
||||
export function parseJdProductPage(payload: unknown): JdProductPageResult {
|
||||
const out = emptyJdProductPage()
|
||||
const core = unwrap<unknown>(payload)
|
||||
if (!core || typeof core !== 'object') return out
|
||||
const record = core as Record<string, unknown>
|
||||
if (Array.isArray(record.items)) {
|
||||
out.items = record.items
|
||||
.map((raw) => toJdProductItem(raw))
|
||||
.filter((item): item is JdProductItem => item !== null)
|
||||
}
|
||||
if (typeof record.total === 'number') out.total = Math.floor(record.total)
|
||||
if (typeof record.page === 'number' && record.page >= 1) out.page = Math.floor(record.page)
|
||||
const rawSize = record.pageSize ?? record.page_size
|
||||
if (typeof rawSize === 'number' && rawSize >= 1) out.pageSize = Math.floor(rawSize)
|
||||
return out
|
||||
}
|
||||
|
||||
/** 详情属性块:attrGroups[{groupName, attrs:[{key,label,value}]}]。 */
|
||||
export interface JdProductAttrEntry {
|
||||
key: string
|
||||
label: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface JdProductAttrGroup {
|
||||
groupName: string
|
||||
attrs: JdProductAttrEntry[]
|
||||
}
|
||||
|
||||
/** 详情图片:images[{imageType, attrName, sortNo, url, byteSize, width, height}]。 */
|
||||
export interface JdProductImage {
|
||||
imageType: string
|
||||
attrName: string
|
||||
sortNo: number
|
||||
url: string
|
||||
byteSize: number | null
|
||||
width: number | null
|
||||
height: number | null
|
||||
}
|
||||
|
||||
export interface JdProductDetail {
|
||||
item: JdProductItem
|
||||
attrGroups: JdProductAttrGroup[]
|
||||
images: JdProductImage[]
|
||||
/** attrGroups 解析失败时的原始 JSON 兜底(界面原样展示,不静默吞)。 */
|
||||
attrJsonRaw: string
|
||||
}
|
||||
|
||||
/** 归一化 attrGroups(camel/snake 同级容错),非法项跳过、块名缺省归「属性」。 */
|
||||
function toAttrGroups(raw: unknown): JdProductAttrGroup[] {
|
||||
if (!Array.isArray(raw)) return []
|
||||
const out: JdProductAttrGroup[] = []
|
||||
for (const groupRaw of raw) {
|
||||
if (!groupRaw || typeof groupRaw !== 'object') continue
|
||||
const group = groupRaw as Record<string, unknown>
|
||||
const groupName = text(group.groupName ?? group.group_name) || '属性'
|
||||
const attrsRaw = group.attrs
|
||||
if (!Array.isArray(attrsRaw)) continue
|
||||
const attrs: JdProductAttrEntry[] = []
|
||||
for (const attrRaw of attrsRaw) {
|
||||
if (!attrRaw || typeof attrRaw !== 'object') continue
|
||||
const attr = attrRaw as Record<string, unknown>
|
||||
attrs.push({
|
||||
key: text(attr.key),
|
||||
label: text(attr.label),
|
||||
value: text(attr.value),
|
||||
})
|
||||
}
|
||||
out.push({ groupName, attrs })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 归一化 images;缺 url 弃行(界面没有可展示/可打开的目标),sortNo 缺省 0。 */
|
||||
function toImages(raw: unknown): JdProductImage[] {
|
||||
if (!Array.isArray(raw)) return []
|
||||
const out: JdProductImage[] = []
|
||||
for (const imageRaw of raw) {
|
||||
if (!imageRaw || typeof imageRaw !== 'object') continue
|
||||
const image = imageRaw as Record<string, unknown>
|
||||
const url = text(image.url)
|
||||
if (!url) continue
|
||||
out.push({
|
||||
imageType: text(image.imageType ?? image.image_type),
|
||||
attrName: text(image.attrName ?? image.attr_name),
|
||||
sortNo: numberOrNull(image.sortNo ?? image.sort_no) ?? 0,
|
||||
url,
|
||||
byteSize: numberOrNull(image.byteSize ?? image.byte_size),
|
||||
width: numberOrNull(image.width),
|
||||
height: numberOrNull(image.height),
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 解析详情负载(信封或已解包 VO);attrGroups 解析不出时回 attrJsonRaw 原文兜底。 */
|
||||
export function parseJdProductDetail(payload: unknown): JdProductDetail {
|
||||
const core = unwrap<unknown>(payload)
|
||||
const record = core && typeof core === 'object' ? (core as Record<string, unknown>) : {}
|
||||
const item = toJdProductItem(record) ?? {
|
||||
id: 0,
|
||||
shopId: null,
|
||||
shopName: '',
|
||||
productCode: '',
|
||||
skuId: '',
|
||||
title: '',
|
||||
brand: '',
|
||||
categoryPath: '',
|
||||
priceMin: '',
|
||||
priceMax: '',
|
||||
stockTotal: null,
|
||||
saleStatus: '',
|
||||
listTab: '',
|
||||
jdUpdatedAt: '',
|
||||
mainImageUrl: '',
|
||||
attrCount: null,
|
||||
imageCount: null,
|
||||
groupId: null,
|
||||
groupName: '',
|
||||
}
|
||||
const attrGroups = toAttrGroups(record.attrGroups ?? record.attr_groups)
|
||||
const attrJsonRaw = typeof record.attrJsonRaw === 'string'
|
||||
? record.attrJsonRaw
|
||||
: typeof record.attr_json_raw === 'string' ? record.attr_json_raw : ''
|
||||
return {
|
||||
item,
|
||||
attrGroups,
|
||||
images: toImages(record.images),
|
||||
attrJsonRaw,
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ export const adminPages: AdminPageDef[] = [
|
||||
{ path: 'asin-center/categories', menuKey: 'admin_product_categories', title: '商品类目', companyScoped: false, load: () => import('@/pages/asin/ProductCategoryPage.vue') },
|
||||
{ path: 'asin-center/skip-price', menuKey: 'admin_skip_price_asin', title: '最低价ASIN', companyScoped: true, load: () => import('@/pages/asin/SkipPricePage.vue') },
|
||||
{ path: 'patent-center/clean-items', menuKey: 'admin_appearance_patent_clean_items', title: '外观专利数据库', companyScoped: true, load: () => import('@/pages/patent/AppearancePatentCleanItemsPage.vue') },
|
||||
{ path: 'jd-center/database', menuKey: 'admin_jd_database', title: '京东数据库', companyScoped: true, load: () => import('@/pages/jd/JdDatabasePage.vue') },
|
||||
]
|
||||
|
||||
export function routeOf(page: AdminPageDef): RouteRecordRaw {
|
||||
|
||||
Reference in New Issue
Block a user