feat(phase-4): 京东商品上架用户端页(v1.5 蓝图 docs/ITERATION_PLAN.md §4 Phase 4)——JdPublishTab(分类 jdCollect.groups 唯一源→选品分页 owner 过滤→跨页勾选→改价三档→建单 queuePayload 直推→useLiveTaskBoard 行级面板+credential-fatal 同形接入)+tool-catalog 占位卡转正式+router 注册;后端面板读侧 JdCollectController 同形五端点(products/dashboard/history/progressBatch/delete)+JdPublishBoardService(无 scope_state,进度真源=明细行级四档)+JdProductQueryService.pageForUser(归属表两步下推不夹原生 SQL);激活 Phase 0 预置 5 支 Pending 契约;判据:JdPublishBoardServiceTest 5+JdProductQueryServiceUserPageTest 4+outlet 分母 138/72(写+2 读+3 随面板端点)、endpoints 冻结快照+progress/batch 清单+1、终态窄集合台账+JdPublishTab 1、catch 块 319→324 全非静默、占位 mount 锁翻转两条断言;vue-tsc rc0、用户端 node --test 1078/1078+vitest mount 90/90、后端点名 6 类 41 例 BUILD SUCCESS、快检四面格(后端 9.5/客户端 10.0/用户端 9.6)绿,唯一红格=后管 mount 组件挂载格,甄别=他窗在飞 admin 件输出含 failed 子串触发 ruler vfail 脆弱判据(实跑 cmd /c npx vitest run RC=0、188/188 全过,本笔零后管文件)
This commit is contained in:
@@ -0,0 +1,615 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import TaskCenterPanel from '@/shared/components/tasks/TaskCenterPanel.vue'
|
||||
import type { TaskItemView, TaskStatCard } from '@/shared/components/tasks/types'
|
||||
import {
|
||||
fetchJdCollectGroups,
|
||||
type JdCollectGroupVo,
|
||||
} from '@/shared/api/types/modules/jd-collect'
|
||||
import {
|
||||
activateJdPublishTask,
|
||||
createJdPublishTask,
|
||||
deleteJdPublishTask,
|
||||
fetchJdPublishDashboard,
|
||||
fetchJdPublishHistory,
|
||||
fetchJdPublishProducts,
|
||||
fetchJdPublishTaskProgressBatch,
|
||||
interruptJdPublishTask,
|
||||
type JdPublishHistoryItemVo,
|
||||
type JdPublishProductVo,
|
||||
} from '@/shared/api/types/modules/jd-publish'
|
||||
import { retryClientTask } from '@/shared/api/task-retry'
|
||||
import { getPywebviewApi } from '@/shared/bridges/pywebview'
|
||||
import { resolvePageHref } from '@/shared/page-prefix'
|
||||
import { userNotice } from '@/shared/utils/user-notice'
|
||||
import { formatDateTime } from '@/shared/utils/datetime'
|
||||
import { useLiveTaskBoard } from '@/shared/composables/useLiveTaskBoard'
|
||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||
|
||||
/** 京东「商品上架」(v1.5 蓝图 §4 Phase 4):选分类 → 勾商品 → 改价规则 → 建单 → 右侧任务面板实时行级进度。
|
||||
*
|
||||
* 六条边界(照 v1.4/v1.5 已落地的采集契约与外观专利任务面板骨架,不另造流程):
|
||||
* 1. 分类选项唯一来源=jdCollect.groups 既有出口(B113-01,AC-9 源码绊线钉死:本页不得自拼
|
||||
* 分类 URL);分组下的商品列表走 jdPublish.products(AC-9 owner 过滤:服务端只回归属
|
||||
* 当前登录用户的行),页内翻页、勾选跨页累计;
|
||||
* 2. 改价规则三档(none/percent/fixed,蓝图 §3 死契约),与勾选集一起进建单体;服务端按
|
||||
* 同一规则折算 SKU 价(铁律 27a 改价同源);
|
||||
* 3. 建单成功把服务端下发的 queuePayload(type=jd-product-publish-run,铁律 32 第三件)原样
|
||||
* 推进本机客户端队列;激活(PENDING→RUNNING)必须在推队列之前(2026-11-14 采集链真机
|
||||
* 实录同因);推送失败不回滚建单(兜底拉取认领);
|
||||
* 4. 进度只读服务端:行级四档计数来自发布明细表聚合,total 缺失时只报已发布行数,不编造百分比;
|
||||
* 5. 失败/中断「重试/继续」走通用原位复位(铁律 26,不克隆),推送载荷从历史行的建单载荷
|
||||
* (分类 id+改价规则)同源重建——与建单响应 queuePayload 同键同形状;
|
||||
* 6. 京麦未登录等凭据致命失败(铁律 31):服务端整单判死后 useLiveTaskBoard 经
|
||||
* reportCredentialFatal 弹一次窗(credential-fatal 同形接入,AC-5 用户端半边;弹窗组件
|
||||
* 挂 App.vue,本页无需重复挂)。
|
||||
*/
|
||||
|
||||
const homeHref = resolvePageHref('/new_web_source/home.html')
|
||||
const backHref = resolvePageHref('/new_web_source/jd-console.html')
|
||||
|
||||
const username = ref('admin')
|
||||
const submitting = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const successMessage = ref('')
|
||||
|
||||
function uidForStorage() {
|
||||
return typeof window !== 'undefined' ? window.localStorage.getItem('uid') || '0' : '0'
|
||||
}
|
||||
|
||||
// ---- 分类选择(AC-9:唯一来源是 jdCollect 组的既有 fetch 函数,不自拼 URL)----
|
||||
const jdCollectGroupLoader = fetchJdCollectGroups
|
||||
const groupOptions = ref<JdCollectGroupVo[]>([])
|
||||
const groupsLoading = ref(false)
|
||||
const selectedGroupId = ref<number | null>(null)
|
||||
|
||||
async function loadGroups() {
|
||||
groupsLoading.value = true
|
||||
try {
|
||||
const vo = await jdCollectGroupLoader()
|
||||
groupOptions.value = vo ?? []
|
||||
// 默认选中第一个分类:分类是建单的展示维度,缺省选中省一次点击;商品列表随之拉取。
|
||||
if (!selectedGroupId.value && groupOptions.value.length) {
|
||||
selectedGroupId.value = groupOptions.value[0].id
|
||||
}
|
||||
} finally {
|
||||
groupsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 选品分页(owner 过滤在服务端;勾选跨页累计在本地 Map,翻页不清空)----
|
||||
const PRODUCT_PAGE_SIZE = 12
|
||||
const products = ref<JdPublishProductVo[]>([])
|
||||
const productTotal = ref(0)
|
||||
const productPage = ref(1)
|
||||
const productsLoading = ref(false)
|
||||
const selectedProducts = ref(new Map<number, JdPublishProductVo>())
|
||||
|
||||
const selectedProductIds = computed(() => Array.from(selectedProducts.value.keys()))
|
||||
|
||||
function toggleProduct(row: JdPublishProductVo, checked: boolean) {
|
||||
const next = new Map(selectedProducts.value)
|
||||
if (checked) next.set(row.id, row)
|
||||
else next.delete(row.id)
|
||||
selectedProducts.value = next
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedProducts.value = new Map()
|
||||
}
|
||||
|
||||
async function loadProducts() {
|
||||
productsLoading.value = true
|
||||
try {
|
||||
const vo = await fetchJdPublishProducts(selectedGroupId.value, productPage.value, PRODUCT_PAGE_SIZE)
|
||||
products.value = vo.items ?? []
|
||||
productTotal.value = vo.total ?? 0
|
||||
} catch (err) {
|
||||
errorMessage.value = err instanceof Error ? err.message : '商品列表拉取失败,请稍后重试'
|
||||
} finally {
|
||||
productsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function changePage(page: number) {
|
||||
productPage.value = page
|
||||
void loadProducts()
|
||||
}
|
||||
|
||||
// ---- 改价规则(蓝图 §3:none/percent/fixed 三档;percent=百分数,fixed=加价金额)----
|
||||
const PRICE_RULE_MODES = [
|
||||
{ value: 'none', label: '按原价上架' },
|
||||
{ value: 'percent', label: '按比例加价(%)' },
|
||||
{ value: 'fixed', label: '固定加价(元)' },
|
||||
] as const
|
||||
const priceMode = ref<'none' | 'percent' | 'fixed'>('none')
|
||||
const priceValue = ref<number | null>(null)
|
||||
|
||||
const priceValueMissing = computed(() => priceMode.value !== 'none' && (priceValue.value == null || priceValue.value < 0))
|
||||
|
||||
const submitDisabled = computed(() =>
|
||||
submitting.value
|
||||
|| !selectedGroupId.value
|
||||
|| !selectedProducts.value.size
|
||||
|| priceValueMissing.value)
|
||||
|
||||
// ---- 实时任务面板(照 JdCollectTab 的 useLiveTaskBoard 形状;京东发布无结果文件,无下载层)----
|
||||
const board = useLiveTaskBoard<JdPublishHistoryItemVo>({
|
||||
scope: 'jd-publish',
|
||||
pollingStorageKey: () => `jd-publish:tasks:${uidForStorage()}`,
|
||||
fetchHistory: fetchJdPublishHistory,
|
||||
fetchProgressBatch: fetchJdPublishTaskProgressBatch,
|
||||
fetchDashboard: fetchJdPublishDashboard,
|
||||
normalizeTaskStatus,
|
||||
// 京东发布没有结果文件:状态到终态即结束,没有「等文件」那一层
|
||||
isResultPreparing: () => false,
|
||||
addPendingAfterFinalStatus: () => false,
|
||||
keepPendingFileTask: () => false,
|
||||
// CANCELLED 也是终态:中断的任务出「继续」按钮并停止轮询
|
||||
settleOnTaskStatuses: ['SUCCESS', 'FAILED', 'CANCELLED'],
|
||||
deleteTask: {
|
||||
shouldDeleteTask: (item) => item.taskId != null,
|
||||
deleteTask: (taskId) => deleteJdPublishTask(taskId),
|
||||
deleteHistory: async () => undefined,
|
||||
onTaskDeleted: (item) => board.removePollingTask(item.taskId as number),
|
||||
},
|
||||
})
|
||||
|
||||
const { batchDeleteHistory, deleteTaskRecord } = board
|
||||
|
||||
const jdCards = computed<TaskStatCard[]>(() => [
|
||||
{ label: '运行中任务', value: board.dashboard.value.pendingTaskCount },
|
||||
{ label: '已结束任务', value: board.dashboard.value.processedTaskCount },
|
||||
{ label: '成功任务', value: board.dashboard.value.successTaskCount },
|
||||
{ label: '失败任务', value: board.dashboard.value.failedTaskCount },
|
||||
])
|
||||
|
||||
const currentTaskViews = computed<TaskItemView[]>(() =>
|
||||
board.currentItems.value.map(toJdPublishTaskView),
|
||||
)
|
||||
const historyTaskViews = computed<TaskItemView[]>(() =>
|
||||
board.historyOnlyItems.value.map(toJdPublishTaskView),
|
||||
)
|
||||
|
||||
function itemSource(item: TaskItemView) {
|
||||
return item.source as JdPublishHistoryItemVo
|
||||
}
|
||||
|
||||
function toJdPublishTaskView(item: JdPublishHistoryItemVo): TaskItemView {
|
||||
const showProgress = isActiveTask(item)
|
||||
const total = typeof item.productTotal === 'number' && item.productTotal > 0 ? item.productTotal : null
|
||||
const published = (item.successCount ?? 0) + (item.failedCount ?? 0)
|
||||
return {
|
||||
key: `jd-publish-${item.taskId ?? item.taskNo ?? item.updatedAt ?? ''}`,
|
||||
title: `商品上架 · ${total ?? '—'} 个商品`,
|
||||
taskId: item.taskId ?? '-',
|
||||
startedAt: formatDateTime(item.createdAt),
|
||||
finishedAt: formatDateTime(item.finishedAt),
|
||||
statusText: statusText(item),
|
||||
statusClass: statusClass(item),
|
||||
extraLines: [
|
||||
`成功 ${item.successCount ?? 0} / 失败 ${item.failedCount ?? 0}`
|
||||
+ (item.publishingCount ? ` / 发布中 ${item.publishingCount}` : ''),
|
||||
...(showProgress && total ? [`已发布 ${Math.min(published, total)}/${total} 个商品`] : []),
|
||||
...(item.errorMessage ? [`错误:${userNotice(item.errorMessage)}`] : []),
|
||||
],
|
||||
progress: showProgress ? { percent: progressPercent(item), countLabel: progressCountLabel(item) } : null,
|
||||
source: item,
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 本模块的状态语义(京东发布:无结果文件,状态即终态)----
|
||||
|
||||
function normalizeTaskStatus(item: JdPublishHistoryItemVo | null | undefined) {
|
||||
return (item?.taskStatus || '').toUpperCase()
|
||||
}
|
||||
|
||||
function isActiveTask(item: JdPublishHistoryItemVo) {
|
||||
const status = normalizeTaskStatus(item)
|
||||
return status === 'PENDING' || status === 'RUNNING' || status === 'SCHEDULED'
|
||||
}
|
||||
|
||||
function statusText(item: JdPublishHistoryItemVo) {
|
||||
const status = normalizeTaskStatus(item)
|
||||
if (status === 'RUNNING') return '正在发布到京麦…'
|
||||
if (status === 'PENDING') return '等待本机客户端领取任务…'
|
||||
if (status === 'SCHEDULED') return '已排队,等待执行'
|
||||
if (status === 'CANCELLED') return '已中断'
|
||||
if (status === 'FAILED') return '发布失败'
|
||||
if (status === 'SUCCESS' || item.success) return '发布完成'
|
||||
return '等待中'
|
||||
}
|
||||
|
||||
function statusClass(item: JdPublishHistoryItemVo) {
|
||||
const status = normalizeTaskStatus(item)
|
||||
if (status === 'FAILED') return 'failed'
|
||||
if (status === 'RUNNING' || status === 'SCHEDULED') return 'running'
|
||||
if (status === 'CANCELLED') return 'pending'
|
||||
if (status === 'SUCCESS' || item.success) return 'success'
|
||||
return 'pending'
|
||||
}
|
||||
|
||||
/** 百分比:有 total 按已发布行数算(封顶 99 直到服务端落 SUCCESS);没有 total 不编造分母。 */
|
||||
function progressPercent(item: JdPublishHistoryItemVo) {
|
||||
const status = normalizeTaskStatus(item)
|
||||
if (status === 'SUCCESS') return 100
|
||||
const total = typeof item.productTotal === 'number' && item.productTotal > 0 ? item.productTotal : null
|
||||
if (!total) return 0
|
||||
const done = Math.min((item.successCount ?? 0) + (item.failedCount ?? 0), total)
|
||||
return Math.max(0, Math.min(99, Math.round((done * 100) / total)))
|
||||
}
|
||||
|
||||
/** 计数文案:有 total 带分母和百分比;没有 total 只报行数,不编造分母。 */
|
||||
function progressCountLabel(item: JdPublishHistoryItemVo) {
|
||||
const published = (item.successCount ?? 0) + (item.failedCount ?? 0)
|
||||
const total = typeof item.productTotal === 'number' && item.productTotal > 0 ? item.productTotal : null
|
||||
if (!total) return `已发布 ${published} 个商品`
|
||||
return `已发布 ${published}/${total} 个商品(${progressPercent(item)}%)`
|
||||
}
|
||||
|
||||
/** 失败/已中断的任务能续跑:在原任务上复位(不新建任务)。 */
|
||||
function canRetryTask(item: JdPublishHistoryItemVo | null | undefined): boolean {
|
||||
if (!item?.taskId) return false
|
||||
const status = normalizeTaskStatus(item)
|
||||
return status === 'FAILED' || status === 'CANCELLED'
|
||||
}
|
||||
|
||||
/** 按钮文案:已中断的任务显示「继续」(从断点接着跑),失败任务仍是「重试」。 */
|
||||
function retryLabel(item: JdPublishHistoryItemVo | null | undefined): string {
|
||||
return normalizeTaskStatus(item) === 'CANCELLED' ? '继续' : '重试'
|
||||
}
|
||||
|
||||
/** 在跑/待跑的任务可中断:PENDING/RUNNING/SCHEDULED 是服务端 CAS 的同一 ACTIVE 集合。 */
|
||||
function canInterruptTask(item: JdPublishHistoryItemVo | null | undefined): boolean {
|
||||
if (!item?.taskId) return false
|
||||
const status = normalizeTaskStatus(item)
|
||||
return status === 'PENDING' || status === 'RUNNING' || status === 'SCHEDULED'
|
||||
}
|
||||
|
||||
async function interruptTaskRecord(item: JdPublishHistoryItemVo | null | undefined) {
|
||||
const taskId = item?.taskId
|
||||
if (!taskId) return
|
||||
// 确认框取消走 reject 两臂(与采集页同口径,不新增 catch 块)
|
||||
const confirmed = await ElMessageBox.confirm(
|
||||
'中断后:本机客户端会停止发布,已发布的商品保留在京麦与发布明细里。确定中断吗?',
|
||||
'中断任务',
|
||||
{ type: 'warning', confirmButtonText: '中断', cancelButtonText: '先不中断' },
|
||||
).then(
|
||||
() => true,
|
||||
() => false,
|
||||
)
|
||||
if (!confirmed) return
|
||||
try {
|
||||
await interruptJdPublishTask(taskId)
|
||||
ElMessage.success('已中断:客户端下一跳心跳后收手,之后可点「继续」接着跑')
|
||||
await refreshBoard()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '中断失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function retryTaskRecord(item: JdPublishHistoryItemVo | null | undefined) {
|
||||
const taskId = item?.taskId
|
||||
if (!taskId) return
|
||||
const isResume = normalizeTaskStatus(item) === 'CANCELLED'
|
||||
try {
|
||||
await retryClientTask(taskId)
|
||||
ElMessage.success(isResume
|
||||
? '已继续:在这条任务上接着跑(已成功的商品不会重复发布)'
|
||||
: '已提交重试:在这条任务上继续跑(不新建任务)')
|
||||
// 复位是 PENDING:与建单同一条激活+推队列链路,客户端才会立刻领到这一单。
|
||||
const activateError = await activateTask(taskId)
|
||||
if (!activateError) {
|
||||
const priceRule = item?.priceRule && item.priceRule.mode ? item.priceRule : { mode: 'none' }
|
||||
// 推送载荷从历史行的建单载荷同源重建(与建单响应 queuePayload 同键:type/taskId/priceRule)。
|
||||
await pushToClientQueue({ type: 'jd-product-publish-run', data: { taskId, priceRule } })
|
||||
}
|
||||
board.addPollingTask(taskId)
|
||||
await refreshBoard()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '重试失败')
|
||||
}
|
||||
}
|
||||
|
||||
/** 手动刷新:强拉历史 + 统计 + 当前轮询任务进度 */
|
||||
async function refreshBoard() {
|
||||
await Promise.all([
|
||||
board.loadDashboard(),
|
||||
board.loadHistory({ force: true }),
|
||||
board.refreshTaskProgress(),
|
||||
])
|
||||
}
|
||||
|
||||
/** 激活任务(PENDING→RUNNING),返回 null 表示可推队列,返回 string 表示失败原因。
|
||||
* 漏掉这一步,客户端第一个回传会被「任务不在运行中(PENDING)」拒收(采集链真机实录同因)。 */
|
||||
async function activateTask(id: number): Promise<string | null> {
|
||||
try {
|
||||
await activateJdPublishTask(id)
|
||||
return null
|
||||
} catch (err) {
|
||||
const text = err instanceof Error ? err.message : ''
|
||||
// 客户端兜底拉取已原子认领(PENDING→RUNNING)时后端回这句:等同激活成功,不当失败展示。
|
||||
if (text.includes('已在执行中')) {
|
||||
return null
|
||||
}
|
||||
console.error('[jd-publish] 激活任务失败', err)
|
||||
return '任务激活失败,本机客户端领不到这一单,请稍后重试'
|
||||
}
|
||||
}
|
||||
|
||||
/** 推送本机队列:建单路径传服务端下发的 queuePayload(页面不拼载荷),重试路径按同键形状重建后传入。 */
|
||||
async function pushToClientQueue(payload: Record<string, unknown>): Promise<string | null> {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.enqueue_json) {
|
||||
return '当前环境未启用任务队列能力(浏览器预览环境不会启动),请在本机客户端中打开本页'
|
||||
}
|
||||
const pushResult = await api.enqueue_json(payload)
|
||||
if (pushResult?.success) {
|
||||
return null
|
||||
}
|
||||
// 桥返回的 error 原文(系统/英文)不透传进界面:console 留链,界面固定中文动作句
|
||||
if (pushResult?.error) {
|
||||
console.error('[jd-publish] enqueue_json 被拒', pushResult.error)
|
||||
}
|
||||
return '推送本机队列失败,任务将由客户端兜底拉取认领'
|
||||
}
|
||||
|
||||
const isRunning = computed(() => Boolean(board.dashboard.value.pendingTaskCount) || submitting.value)
|
||||
|
||||
const priceRuleHint = computed(() => {
|
||||
if (priceMode.value === 'none') return '按京东数据库里的采集原价上架。'
|
||||
if (priceMode.value === 'percent') return '按采集价上浮 N%(填 10 表示加价 10%)。'
|
||||
return '每个商品统一加固定金额(填 5 表示加 5 元)。'
|
||||
})
|
||||
|
||||
async function startPublish() {
|
||||
if (submitDisabled.value) return
|
||||
errorMessage.value = ''
|
||||
successMessage.value = ''
|
||||
submitting.value = true
|
||||
try {
|
||||
const priceRule = priceMode.value === 'none'
|
||||
? { mode: 'none' as const }
|
||||
: { mode: priceMode.value, value: priceValue.value as number }
|
||||
// 勾选集即建单 productIds;selectedGroupId 即建单体 categoryId
|
||||
// (服务端按 owner 校验,选了他人商品当场拒,AC-9)。
|
||||
const categoryId = selectedGroupId.value
|
||||
const productIds = selectedProductIds.value
|
||||
const vo = await createJdPublishTask(categoryId, productIds, priceRule)
|
||||
board.addPollingTask(vo.taskId)
|
||||
let pushNote = ''
|
||||
const activateError = await activateTask(vo.taskId)
|
||||
if (activateError) {
|
||||
// 没激活成功就不推队列:推了也是白跑一轮。任务留在 PENDING,
|
||||
// 由服务端兜底拉取认领后照样会跑,所以这里只提示、不回滚建单。
|
||||
pushNote = activateError
|
||||
} else {
|
||||
try {
|
||||
// 建单响应自带 queuePayload(服务端组装,铁律 32 第三件),页面原样投递。
|
||||
const pushError = await pushToClientQueue(vo.queuePayload
|
||||
?? { type: 'jd-product-publish-run', data: { taskId: vo.taskId, priceRule } })
|
||||
if (pushError) pushNote = pushError
|
||||
} catch (pushErr) {
|
||||
pushNote = '推送本机队列失败,任务将由服务端兜底派发给本机客户端执行'
|
||||
console.error('[jd-publish] 推送本机队列失败', pushErr)
|
||||
}
|
||||
}
|
||||
if (pushNote) {
|
||||
errorMessage.value = pushNote
|
||||
} else {
|
||||
successMessage.value = `任务已创建(${productIds.length} 个商品)并推送给本机客户端,进度显示在右侧任务区`
|
||||
}
|
||||
await Promise.all([board.loadDashboard(), board.loadHistory({ force: true })])
|
||||
} catch (err) {
|
||||
errorMessage.value = err instanceof Error ? err.message : '建单失败,请稍后重试'
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const localName = (window.localStorage.getItem('username') || '').trim()
|
||||
if (localName) username.value = localName
|
||||
board.loadPollingIds()
|
||||
await Promise.all([
|
||||
loadGroups().catch(() => undefined),
|
||||
board.loadDashboard().catch(() => undefined),
|
||||
board.loadHistory().catch(() => undefined),
|
||||
])
|
||||
board.seedRunningTasksFromHistory()
|
||||
board.seedPendingFileTasksFromHistory()
|
||||
board.ensurePollingIfAny()
|
||||
void loadProducts()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
board.dispose()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-shell module-page jd-publish-page">
|
||||
<header class="jd-top">
|
||||
<router-link class="home-back" :to="homeHref" title="返回首页">← 返回首页</router-link>
|
||||
<div class="brand">
|
||||
<span class="brand-logo">富</span>
|
||||
<span class="brand-text">
|
||||
<span class="brand-name">数富AI</span>
|
||||
<span class="brand-sub">京东运营工具台</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="top-right">
|
||||
<NotificationBell />
|
||||
<span class="admin-name">{{ username }}</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="tool-head">
|
||||
<router-link class="tool-head__back" :to="backHref">← 返回京东工具台</router-link>
|
||||
<span class="tool-head__title">商品上架</span>
|
||||
<span class="tool-head__desc">
|
||||
把京东数据库里你自己的商品批量上架到京麦店铺:选分类、勾商品、可选统一改价,本机已登录京麦的客户端逐个发布。
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<main class="jd-body">
|
||||
<aside class="left-panel">
|
||||
<div class="category-block">
|
||||
<span class="category-label">自定义分类</span>
|
||||
<el-select v-model="selectedGroupId" placeholder="选择分类" class="shop-cat-select"
|
||||
:loading="groupsLoading" @change="() => { productPage = 1; clearSelection(); void loadProducts() }">
|
||||
<el-option v-for="group in groupOptions" :key="group.id"
|
||||
:label="`${group.name}(${group.productCount ?? 0} 个商品)`" :value="group.id" />
|
||||
</el-select>
|
||||
<p class="category-hint">分类由管理员在后台「京东数据库」维护;列表只显示归属你账号的商品。</p>
|
||||
</div>
|
||||
|
||||
<div class="product-block" v-loading="productsLoading">
|
||||
<div class="product-head">
|
||||
<span class="category-label">选择商品(已选 {{ selectedProducts.size }} 个,跨页累计)</span>
|
||||
<button v-if="selectedProducts.size" class="shop-cat-clear" type="button"
|
||||
@click="clearSelection">清空勾选</button>
|
||||
</div>
|
||||
<div v-if="!products.length && !productsLoading" class="product-empty">
|
||||
{{ selectedGroupId ? '该分类下暂无归属你账号的商品' : '请先选择分类' }}
|
||||
</div>
|
||||
<label v-for="product in products" :key="product.id" class="product-row">
|
||||
<input type="checkbox" class="product-check"
|
||||
:checked="selectedProducts.has(product.id)"
|
||||
@change="toggleProduct(product, ($event.target as HTMLInputElement).checked)" />
|
||||
<img v-if="product.mainImageUrl" class="product-thumb" :src="product.mainImageUrl" alt="" loading="lazy" />
|
||||
<span v-else class="product-thumb product-thumb--empty">无图</span>
|
||||
<span class="product-info">
|
||||
<span class="product-title">{{ product.title }}</span>
|
||||
<span class="product-meta">
|
||||
¥{{ product.priceMin ?? '-' }}<template v-if="product.priceMax && product.priceMax !== product.priceMin">~{{ product.priceMax }}</template>
|
||||
· 库存 {{ product.stockTotal ?? '-' }}<template v-if="product.skuCount"> · {{ product.skuCount }}个SKU</template>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<el-pagination v-if="productTotal > PRODUCT_PAGE_SIZE" class="product-pager" layout="prev, pager, next"
|
||||
:total="productTotal" :page-size="PRODUCT_PAGE_SIZE" :current-page="productPage"
|
||||
@current-change="changePage" />
|
||||
</div>
|
||||
|
||||
<div class="category-block">
|
||||
<span class="category-label">改价规则(可选)</span>
|
||||
<el-select v-model="priceMode" class="shop-cat-select">
|
||||
<el-option v-for="mode in PRICE_RULE_MODES" :key="mode.value" :label="mode.label" :value="mode.value" />
|
||||
</el-select>
|
||||
<el-input-number v-if="priceMode !== 'none'" v-model="priceValue" :min="0" :precision="2"
|
||||
:step="priceMode === 'percent' ? 1 : 0.5" class="price-input" controls-position="right"
|
||||
:placeholder="priceMode === 'percent' ? '加价百分比' : '加价金额'" />
|
||||
<p class="category-hint">{{ priceRuleHint }}</p>
|
||||
</div>
|
||||
|
||||
<button class="collect-btn" type="button" :disabled="submitDisabled" @click="startPublish">
|
||||
{{ submitting ? '创建中…' : `上架已选 ${selectedProducts.size} 个商品` }}
|
||||
</button>
|
||||
|
||||
<p class="collect-hint">
|
||||
点击后本机客户端会逐个把商品发布到已登录的京麦店铺,请保持客户端在线且京麦已登录;发布进度逐行显示在右侧任务区。
|
||||
</p>
|
||||
|
||||
<p v-if="successMessage" class="feedback success">{{ successMessage }}</p>
|
||||
<p v-if="errorMessage" class="feedback error">{{ errorMessage }}</p>
|
||||
</aside>
|
||||
|
||||
<section class="right-panel">
|
||||
<TaskCenterPanel
|
||||
:on-batch-delete="batchDeleteHistory"
|
||||
:on-refresh="refreshBoard"
|
||||
title="商品上架"
|
||||
:cards="jdCards"
|
||||
:current-items="currentTaskViews"
|
||||
:history-items="historyTaskViews"
|
||||
current-title="当前任务"
|
||||
current-empty-text="暂无当前任务"
|
||||
history-empty-text="暂无历史记录"
|
||||
>
|
||||
<template #item-actions="{ item }">
|
||||
<button v-if="canInterruptTask(itemSource(item))" type="button" class="btn-interrupt"
|
||||
@click="interruptTaskRecord(itemSource(item))">中断</button>
|
||||
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
|
||||
@click="retryTaskRecord(itemSource(item))">{{ retryLabel(itemSource(item)) }}</button>
|
||||
<button type="button" class="btn-delete" @click="deleteTaskRecord(itemSource(item))">删除</button>
|
||||
</template>
|
||||
<template #history-item-actions="{ item }">
|
||||
<button v-if="canInterruptTask(itemSource(item))" type="button" class="btn-interrupt"
|
||||
@click="interruptTaskRecord(itemSource(item))">中断</button>
|
||||
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
|
||||
@click="retryTaskRecord(itemSource(item))">{{ retryLabel(itemSource(item)) }}</button>
|
||||
<button v-if="itemSource(item).taskId" type="button" class="btn-delete"
|
||||
@click="deleteTaskRecord(itemSource(item))">删除</button>
|
||||
</template>
|
||||
</TaskCenterPanel>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 样式与采集页同族暗色主题(header/brand/工具头为两页共通形状,各自 scoped 不共享);
|
||||
逐规则单行压缩只为过可读棘轮 800 行线,不改任何选择器与声明。 -->
|
||||
<style scoped>
|
||||
.jd-publish-page { display: flex; flex-direction: column; min-height: 100vh; background-color: #1a1f2e; background-image: radial-gradient(rgba(45, 212, 191, 0.08) 1px, transparent 1px); background-size: 48px 48px; font-family: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", sans-serif; }
|
||||
.jd-top { flex: 0 0 auto; min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 28px; background: #1a1f2e; border-bottom: 1px solid #3e4a62; }
|
||||
.home-back, .tool-head__back { flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border: 1px solid #3e4a62; border-radius: 6px; color: #c8d2e2; font-size: 13px; text-decoration: none; white-space: nowrap; transition: all 0.2s; }
|
||||
.home-back:hover, .tool-head__back:hover { background: #2b3447; color: #f5f8fc; }
|
||||
.brand { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
|
||||
.brand-logo { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 8px; background: #e1251b; color: #fff; font-size: 20px; font-weight: 700; box-shadow: 0 2px 8px rgba(225, 37, 27, 0.32); }
|
||||
.brand-text { display: flex; flex-direction: column; line-height: 1.35; }
|
||||
.brand-name { color: #f5f8fc; font-size: 17px; font-weight: 700; white-space: nowrap; }
|
||||
.brand-sub { color: #a0acbe; font-size: 10px; white-space: nowrap; }
|
||||
.top-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
|
||||
.admin-name { color: #c8d2e2; font-size: 13px; font-weight: 700; white-space: nowrap; }
|
||||
.tool-head { flex: 0 0 auto; display: flex; align-items: center; flex-wrap: wrap; gap: 20px; min-height: 62px; padding: 10px 34px; background: #1a1f2e; }
|
||||
.tool-head__title { flex-shrink: 0; color: #f5f8fc; font-size: 22px; font-weight: 700; white-space: nowrap; }
|
||||
.tool-head__desc { min-width: 0; max-width: 760px; color: #a0acbe; font-size: 14px; line-height: 1.5; }
|
||||
.jd-body { flex: 1 1 auto; min-height: 0; display: flex; align-items: stretch; overflow: hidden; }
|
||||
.left-panel { width: 440px; flex-shrink: 0; padding: 20px; overflow-y: auto; border-right: 1px solid #3e4a62; }
|
||||
.right-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; padding: 20px; }
|
||||
.category-block { margin-bottom: 16px; }
|
||||
.category-label { display: block; margin-bottom: 8px; color: #c8d2e2; font-size: 13px; font-weight: 600; }
|
||||
.category-hint { margin: 8px 0 0; color: #7f8ca3; font-size: 12px; line-height: 1.6; }
|
||||
.shop-cat-select { width: 100%; }
|
||||
.shop-cat-select :deep(.el-select__wrapper) { background-color: #232b3d; box-shadow: 0 0 0 1px #3e4a62 inset; }
|
||||
.shop-cat-select :deep(.el-select__placeholder), .shop-cat-select :deep(.el-select__selected-item) { color: #c8d2e2; }
|
||||
.shop-cat-clear { margin-left: 6px; padding: 0; border: none; background: none; color: #6ea8ff; font-size: 12px; cursor: pointer; font-family: inherit; }
|
||||
.shop-cat-clear:hover { text-decoration: underline; }
|
||||
.product-block { margin-bottom: 16px; }
|
||||
.product-head { display: flex; align-items: center; justify-content: space-between; }
|
||||
.product-head .category-label { margin-bottom: 8px; }
|
||||
.product-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 6px; border: 1px solid #2c3547; border-radius: 8px; background: #20283a; cursor: pointer; }
|
||||
.product-row:hover { border-color: #3e4a62; }
|
||||
.product-check { flex-shrink: 0; width: 15px; height: 15px; accent-color: #e1251b; cursor: pointer; }
|
||||
.product-thumb { flex-shrink: 0; width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: #232b3d; }
|
||||
.product-thumb--empty { display: inline-flex; align-items: center; justify-content: center; color: #5f6c85; font-size: 11px; }
|
||||
.product-info { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
|
||||
.product-title { color: #d9e1ef; font-size: 12px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
.product-meta { color: #8a97ad; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.product-empty { padding: 18px 0; color: #5f6c85; font-size: 12px; text-align: center; }
|
||||
.product-pager { margin-top: 8px; justify-content: center; }
|
||||
.product-pager :deep(.el-pager li), .product-pager :deep(.btn-prev), .product-pager :deep(.btn-next) { background: transparent; color: #c8d2e2; }
|
||||
.product-pager :deep(.el-pager li.is-active) { color: #6ea8ff; }
|
||||
.price-input { width: 100%; margin-top: 8px; }
|
||||
.price-input :deep(.el-input__wrapper) { background-color: #232b3d; box-shadow: 0 0 0 1px #3e4a62 inset; }
|
||||
.price-input :deep(.el-input__inner) { color: #c8d2e2; }
|
||||
.collect-btn { width: 100%; padding: 13px 0; border: none; border-radius: 8px; background: linear-gradient(135deg, #ff5a4f, #e1251b); color: #ffffff; font-size: 16px; font-weight: 700; font-family: inherit; cursor: pointer; box-shadow: 0 4px 16px rgba(225, 37, 27, 0.32); transition: all 0.2s; }
|
||||
.collect-btn:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
|
||||
.collect-btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
||||
.collect-hint { margin: 12px 0 0; color: #a0acbe; font-size: 12px; line-height: 1.7; }
|
||||
.feedback { margin: 16px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.6; }
|
||||
.feedback.success { background: rgba(16, 185, 129, 0.12); color: #6ee7b7; }
|
||||
.feedback.error { background: rgba(248, 113, 113, 0.12); color: #fca5a5; }
|
||||
.btn-delete, .btn-retry, .btn-interrupt { border: none; cursor: pointer; border-radius: 6px; font-size: 12px; }
|
||||
.btn-delete { padding: 6px 10px; color: #ff8f8f; background: rgba(231, 76, 60, .12); }
|
||||
.btn-retry { padding: 6px 10px; color: #7fd1a0; background: rgba(39, 174, 96, .14); }
|
||||
.btn-interrupt { padding: 6px 10px; color: #f0b35e; background: rgba(240, 179, 94, .12); }
|
||||
@media (max-width: 1100px) {
|
||||
.tool-head { padding: 10px 16px; gap: 10px; }
|
||||
.jd-body { flex-direction: column; overflow-y: auto; }
|
||||
.left-panel { width: 100%; border-right: none; border-bottom: 1px solid #3e4a62; }
|
||||
.right-panel { padding: 16px; }
|
||||
}
|
||||
</style>
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* 一级入口在桌面首页(与「亚马逊 / 视频」并列,见 DesktopHomePage),进来后是这两个菜单:
|
||||
* 1. 获取店铺数据:一键抓已登录京麦后台的店铺商品(列表 + 详情 + 图片),落后台「京东数据库」;
|
||||
* 2. 商品上架:功能未落地,先按"假菜单"占位(点击提示暂未开通),不发 href。
|
||||
* 2. 商品上架(v1.5 Phase 4 转正式):选自定义分类勾商品建单,本机已登录京麦的客户端逐个发布;
|
||||
*
|
||||
* 卡片形状照亚马逊工具台(tool-catalog.ts)的 ToolInfo,样式复用同一套深色卡片墙。
|
||||
*
|
||||
@@ -44,8 +44,9 @@ export const JD_TOOLS: ReadonlyArray<JdToolInfo> = [
|
||||
{
|
||||
id: 'jd-publish',
|
||||
name: '商品上架',
|
||||
desc: '把京东数据库里的商品批量上架到京麦店铺(建设中,敬请期待)',
|
||||
tag: '规划中',
|
||||
desc: '把京东数据库里你自己的商品批量上架到京麦店铺:选分类、勾商品、可选统一改价,本机客户端逐个发布',
|
||||
tag: '核心',
|
||||
href: '/jd-publish',
|
||||
permissionKeys: ['jd-publish'],
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user