feat(跟价勾选): 默认只勾在售、一个都不勾=按在售跑不再拦启动、续跑先选在跑的那份循环
用户 2026-10-17 定口径。三件事: 1) 默认只勾在售、另两项不默认勾——本来就是现状,没动,只在用例里钉住; 2) 取消「一个状态都没勾就拦住启动」:不勾的语义就是上线前的「只跑在售」,拦它只会让用户 以为跑不了。改为提交前经 withDefaultListingStatuses 兜底回在售,与客户端 price_match_new.resolve_listing_statuses 同一口径,两边不许分叉。顺手补掉一个 Vue 坑: 取消最后一格时 :checked 新旧值都是 true、Vue 不回写 DOM,不手动复位就会出现 「框看着没勾、实际按在售在跑」的错位,故在 onListingStatusToggle 里显式复位。 3) 「会先选在跑的」:setLoopRun 首次拿到在跑循环时用其落库 listingStatuses 预填勾选, 只在「之前没有循环在位」时填(免得轮询冲掉正在改的勾选),asin-only 循环与空清单不填。 orderListingStatuses/withDefaultListingStatuses 从组件里提到 listingFilters.ts 变成可直接 断言的纯函数,不再只靠源码正则。验证:price-track-listing-statuses 9/9、用户端整量 npm test 864 passed、vue-tsc --noEmit 干净。 本提交只含上述改动:同文件里另一路「移除清除勾选记忆入口」的在飞 diff 按 §1 铁律 4 留在工作区,没卷进来。
This commit is contained in:
@@ -242,6 +242,8 @@ import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.v
|
||||
import {
|
||||
PRICE_TRACK_DEFAULT_LISTING_STATUSES,
|
||||
PRICE_TRACK_LISTING_STATUSES,
|
||||
orderListingStatuses,
|
||||
withDefaultListingStatuses,
|
||||
} from './listingFilters'
|
||||
import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.vue'
|
||||
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
|
||||
@@ -367,24 +369,27 @@ const asinModeEnabled = ref(false) // 按指定ASIN文档(自定义)
|
||||
const listingStatusRows = PRICE_TRACK_LISTING_STATUSES
|
||||
const selectedListingStatuses = ref<string[]>([...PRICE_TRACK_DEFAULT_LISTING_STATUSES])
|
||||
|
||||
// 一个状态都没勾=兜底回在售(与客户端 resolve_listing_statuses 的空清单兜底同一口径)
|
||||
const effectiveListingStatuses = computed(() => withDefaultListingStatuses(selectedListingStatuses.value))
|
||||
|
||||
function isListingStatusSelected(value: string) {
|
||||
return selectedListingStatuses.value.includes(value)
|
||||
return effectiveListingStatuses.value.includes(value)
|
||||
}
|
||||
|
||||
function onListingStatusToggle(value: string, event: Event) {
|
||||
const checked = (event.target as HTMLInputElement).checked
|
||||
const input = event.target as HTMLInputElement
|
||||
const next = new Set(selectedListingStatuses.value)
|
||||
if (checked) next.add(value)
|
||||
if (input.checked) next.add(value)
|
||||
else next.delete(value)
|
||||
// 按目录顺序回写:这个顺序就是客户端逐状态筛选、逐页跑的顺序,不能跟着点击次序漂
|
||||
selectedListingStatuses.value = listingStatusRows.filter((row) => next.has(row.value)).map((row) => row.value)
|
||||
selectedListingStatuses.value = orderListingStatuses([...next])
|
||||
// 取消最后一个勾选时,:checked 的新旧值都是 true,Vue 不回写 DOM,
|
||||
// 不手动复位就会出现「框看着没勾、实际按在售在跑」的错位
|
||||
input.checked = effectiveListingStatuses.value.includes(value)
|
||||
}
|
||||
|
||||
const hasValidListingStatuses = computed(() => selectedListingStatuses.value.length > 0)
|
||||
|
||||
const listingStatusSummaryText = computed(() => {
|
||||
const labels = listingStatusRows.filter((row) => isListingStatusSelected(row.value)).map((row) => row.label)
|
||||
return labels.length ? `「${labels.join(' / ')}」的` : '(一个状态都没勾,无法启动)'
|
||||
return `「${labels.join(' / ')}」的`
|
||||
})
|
||||
|
||||
// 上传文件
|
||||
@@ -969,7 +974,7 @@ function listingStatusesForPayload(child?: PriceTrackCreateTaskRequest | null) {
|
||||
const fromDispatch = (child?.listingStatuses || []).filter((item) => !!item)
|
||||
// 派发值优先(循环建单时勾的那几个状态要一路跑到最后一轮,不随界面中途改勾选而变);
|
||||
// 老循环没存这个字段(后端加列前的记录)时退回本地勾选。
|
||||
return fromDispatch.length ? fromDispatch : [...selectedListingStatuses.value]
|
||||
return fromDispatch.length ? fromDispatch : effectiveListingStatuses.value
|
||||
}
|
||||
|
||||
function buildMinimumPriceByCountryAndAsin(rowsByCountry: Record<string, PriceTrackAsinParsedRow[]>) {
|
||||
@@ -1227,9 +1232,16 @@ async function waitForTaskTerminal(taskId: number) {
|
||||
}
|
||||
|
||||
function setLoopRun(next: PriceTrackLoopRunVo | null) {
|
||||
const hadLoop = !!activeLoopRun.value
|
||||
activeLoopRun.value = next
|
||||
activeLoopRunId.value = next?.id ?? null
|
||||
saveActiveLoopRunId()
|
||||
// 刷新/重开页面自动续跑时,勾选态跟着「在跑的那份循环」走:它每一轮真正跑的就是落库的这几个
|
||||
// 状态,界面停在默认值会让人误判在跑的范围。已有循环在位时不覆盖,免得轮询冲掉正在改的勾选。
|
||||
if (next && !hadLoop && next.statusMode !== false) {
|
||||
const running = orderListingStatuses((next.listingStatuses || []).filter(Boolean))
|
||||
if (running.length) selectedListingStatuses.value = running
|
||||
}
|
||||
}
|
||||
|
||||
function clearLoopRunIfTerminal() {
|
||||
@@ -1416,11 +1428,6 @@ async function pushToPythonLoopQueue() {
|
||||
ElMessage.warning('请至少选择一个跟价模式')
|
||||
return
|
||||
}
|
||||
if (statusModeEnabled.value && !hasValidListingStatuses.value) {
|
||||
// 空清单投出去会被客户端退回"在售",用户勾的其它状态就静默不跑,所以在这里就拦住
|
||||
ElMessage.warning('按商品状态跟价时请至少勾选一个商品状态')
|
||||
return
|
||||
}
|
||||
if (asinModeEnabled.value && !asinFiles.value.length) {
|
||||
ElMessage.warning('请先选择 ASIN 文件')
|
||||
return
|
||||
@@ -1437,7 +1444,7 @@ async function pushToPythonLoopQueue() {
|
||||
userId: 0,
|
||||
statusMode: statusModeEnabled.value,
|
||||
// 勾了哪些状态随循环落库:每一轮子任务都从这里回读,界面中途改勾选不影响已启动的循环
|
||||
listingStatuses: statusModeEnabled.value ? [...selectedListingStatuses.value] : [],
|
||||
listingStatuses: statusModeEnabled.value ? effectiveListingStatuses.value : [],
|
||||
asinMode: asinModeEnabled.value,
|
||||
items: matchedRows,
|
||||
asinFiles: resolveAsinRequestPaths(),
|
||||
|
||||
@@ -28,3 +28,22 @@ export type PriceTrackListingStatusValue = (typeof PRICE_TRACK_LISTING_STATUSES)
|
||||
|
||||
/** 默认只勾在售=本功能上线前的行为,存量用户不勾也不会多跑状态。 */
|
||||
export const PRICE_TRACK_DEFAULT_LISTING_STATUSES: PriceTrackListingStatusValue[] = ['Active']
|
||||
|
||||
/**
|
||||
* 按目录顺序回写勾选。这个顺序就是客户端逐状态筛选、逐页跑的顺序,不能跟着点击次序漂;
|
||||
* 目录外的取值(脏数据/老版本存的键)在这里被摘掉,不投给客户端。
|
||||
* 返回 string[] 而不是联合类型:调用方拿到的清单本来就来自后端载荷(string[]),
|
||||
* 在这里假装严格没有意义,目录一致性由测试钉。
|
||||
*/
|
||||
export function orderListingStatuses(values: readonly string[]): string[] {
|
||||
const picked = new Set(values)
|
||||
return PRICE_TRACK_LISTING_STATUSES.filter((row) => picked.has(row.value)).map((row) => row.value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个状态都没勾=兜底回在售。与客户端 price_match_new.resolve_listing_statuses
|
||||
* 的空清单兜底同一口径,两边都得是「不勾=只跑在售」,否则界面显示的范围和真跑的范围会分叉。
|
||||
*/
|
||||
export function withDefaultListingStatuses(values: readonly string[]): string[] {
|
||||
return orderListingStatuses(values.length ? values : PRICE_TRACK_DEFAULT_LISTING_STATUSES)
|
||||
}
|
||||
|
||||
@@ -6,16 +6,19 @@ import { dirname, join } from 'node:path'
|
||||
import {
|
||||
PRICE_TRACK_DEFAULT_LISTING_STATUSES,
|
||||
PRICE_TRACK_LISTING_STATUSES,
|
||||
orderListingStatuses,
|
||||
withDefaultListingStatuses,
|
||||
} from '../src/pages/brand/components/listingFilters.ts'
|
||||
|
||||
/**
|
||||
* 跟价「按商品状态(全量)」多状态(2026-10-16 立项)。
|
||||
* 跟价「按商品状态(全量)」多状态(2026-10-16 立项;2026-10-17 改默认与兜底口径)。
|
||||
*
|
||||
* 钉三件事:
|
||||
* 钉四件事:
|
||||
* 1. 状态目录本身——取值必须与客户端 amazon_base_v2.LISTING_STATUS_CATALOG 的键逐字一致,
|
||||
* 顺序就是客户端逐状态跑的顺序,默认只勾在售(=本功能上线前的行为);
|
||||
* 2. 载荷接线——listing_statuses 只在状态模式下发、以派发值为准、空清单不入队;
|
||||
* 3. mode 不再单吃本地勾选态(页面刷新后本地态回默认=全量,会把指定ASIN循环跑成全量改价)。
|
||||
* 2. 空勾选的语义=只跑在售(不拦启动),且回写顺序不随点击次序漂;
|
||||
* 3. 载荷接线——listing_statuses 只在状态模式下发、以派发值为准、空清单不入队;
|
||||
* 4. mode 不再单吃本地勾选态(页面刷新后本地态回默认=全量,会把指定ASIN循环跑成全量改价)。
|
||||
*/
|
||||
|
||||
const PAGE = join(
|
||||
@@ -45,6 +48,23 @@ test('默认只勾在售=上线前行为,且必须是目录里的项', () =>
|
||||
}
|
||||
})
|
||||
|
||||
test('一个状态都没勾=兜底回在售,不拦启动', () => {
|
||||
assert.deepEqual(withDefaultListingStatuses([]), ['Active'],
|
||||
'空勾选必须落到在售——客户端 resolve_listing_statuses 也是这个兜底,两边不能分叉')
|
||||
assert.deepEqual(withDefaultListingStatuses(['PricingIssue', 'Active']), ['Active', 'PricingIssue'],
|
||||
'有勾选时按目录顺序原样保留,只补空')
|
||||
assert.doesNotMatch(source, /请至少勾选一个商品状态/,
|
||||
'又恢复了"空勾选拦启动":不勾的语义就是只跑在售,拦它只会让用户以为跑不了')
|
||||
})
|
||||
|
||||
test('回写按目录顺序、目录外的值被摘掉', () => {
|
||||
assert.deepEqual(orderListingStatuses(['PricingIssue', 'Active', 'SearchSuppressed', '']),
|
||||
['Active', 'PricingIssue'],
|
||||
'逐状态执行顺序变成了点击顺序或带进脏值:同一份勾选两次跑出的任务形状不同')
|
||||
assert.match(source, /selectedListingStatuses\.value = orderListingStatuses\(\[\.\.\.next\]\)/,
|
||||
'勾选回写不再走目录排序')
|
||||
})
|
||||
|
||||
test('载荷只在状态模式下带 listing_statuses', () => {
|
||||
assert.match(
|
||||
source,
|
||||
@@ -53,26 +73,30 @@ test('载荷只在状态模式下带 listing_statuses', () => {
|
||||
)
|
||||
})
|
||||
|
||||
test('listing_statuses 为空不许入队', () => {
|
||||
test('listing_statuses 为空不许入队(兜底后本就不该出现空清单)', () => {
|
||||
assert.match(source, /\['country_codes', 'listing_statuses'\]/,
|
||||
'队列闸没把 listing_statuses 圈进非空数组——空清单会被客户端静默退回在售')
|
||||
assert.match(source, /请至少勾选一个商品状态/, '启动前没有"至少勾一个"的拦截')
|
||||
})
|
||||
|
||||
test('mode 与状态清单都以派发回来的子任务为准,本地勾选只作兜底', () => {
|
||||
assert.match(source, /if \(child\) return child\.statusMode \? 'status' : 'asin'/,
|
||||
'mode 又变成只读本地勾选态:刷新页面后指定ASIN循环会被拼成全量跟价(对整店真实改价)')
|
||||
assert.match(source, /fromDispatch\.length \? fromDispatch : \[\.\.\.selectedListingStatuses\.value\]/,
|
||||
assert.match(source, /fromDispatch\.length \? fromDispatch : effectiveListingStatuses\.value/,
|
||||
'状态清单不再优先取派发值:INFINITE 循环的后续轮会随界面改勾选而漂')
|
||||
assert.match(source, /buildQueuePayload\(taskVo, row, childTaskRequest\)/,
|
||||
'派发链路没把 childTaskRequest 传进载荷')
|
||||
})
|
||||
|
||||
test('勾选回写按目录顺序,不随点击次序漂', () => {
|
||||
assert.match(source, /listingStatusRows\.filter\(\(row\) => next\.has\(row\.value\)\)\.map\(\(row\) => row\.value\)/,
|
||||
'逐状态执行顺序变成了点击顺序,同一份勾选两次跑出的任务形状不同')
|
||||
test('循环建单把兜底后的清单一起提交(后端逐轮回读的就是它)', () => {
|
||||
assert.match(source, /listingStatuses: statusModeEnabled\.value \? effectiveListingStatuses\.value : \[\]/,
|
||||
'建单提交了未兜底的原始勾选:空勾选会落库成空清单,下一轮才被发现')
|
||||
})
|
||||
|
||||
test('循环建单把勾选清单一起提交(后端逐轮回读的就是它)', () => {
|
||||
assert.match(source, /listingStatuses: statusModeEnabled\.value \? \[\.\.\.selectedListingStatuses\.value\] : \[\]/)
|
||||
test('续跑时勾选态跟着在跑的那份循环走', () => {
|
||||
assert.match(source, /if \(next && !hadLoop && next\.statusMode !== false\) \{/,
|
||||
'续跑预填没判"在跑的循环":asin-only 循环会把状态勾选也带出来')
|
||||
assert.match(source, /const running = orderListingStatuses\(\(next\.listingStatuses \|\| \[\]\)\.filter\(Boolean\)\)/,
|
||||
'预填不再按目录顺序回写')
|
||||
assert.match(source, /if \(running\.length\) selectedListingStatuses\.value = running/,
|
||||
'预填开始覆盖空清单:老循环没存过这个字段,会把默认在售冲成不勾')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user