收口(时间控件): 后管 8 对起止加 min/max 禁选 + 倒挂交换,并落全项目尺子
指令是"项目所有的前端时间控件 开始日期不能晚于结束日期"。普查(ops 仓 scripts/_census_time_controls.py)数出 55 个控件实例、21 个成对区间,裸奔的是 后管 8 对与麦象控制台 2 对:起止能选到倒挂,查询恒定返回空表且页面没有任何提示。 - utils/datetime.ts 新增 orderedPair;8 页两头各绑 :max/:min,并在 @change 把 倒挂的两端交换回状态——min/max 只灰掉日历面板里的非法日,手输、粘贴仍能越界。 - tests/date-range-order.test.ts(10 例):分母硬钉 19/2/30/4 实例与 8/0/11/2 对, 含真文件反例自证(裸对、只一头、只有 min/max、换成没登记的写法都要露出来); 同时钉住财务系统与麦象的分母,那两面回归也会在这支判红。 - tests/mount/date-range-order.mount.test.ts(3 例):真组件填倒挂值 → 两头落回 有序,且发出去的 startDate/endDate 同一条。 - 摘掉 DedupeRegistryPage 导出与 DuplicateCheckPage 查询里的两条 "开始日期不能晚于结束日期"拦截(交换接管后够不着,属死分支), task-254 那条"导出需做日期区间校验"的钉子改指 min/max + clampDatePair。 验证:npm test 1792 passed / 0 failed、vitest mount 10 passed、vue-tsc rc=0。
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { todayDateInput } from '@/utils/datetime'
|
||||
import { orderedPair, todayDateInput } from '@/utils/datetime'
|
||||
import {
|
||||
fetchUserSecretUsage,
|
||||
type AdminUserSecretUsageRow,
|
||||
@@ -24,6 +24,13 @@ const pageSize = ref(15)
|
||||
const keyword = ref('')
|
||||
const startDate = ref(todayDateInput())
|
||||
const endDate = ref(todayDateInput())
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(startDate.value, endDate.value)
|
||||
startDate.value = s
|
||||
endDate.value = e
|
||||
}
|
||||
|
||||
const groupFilter = ref<number | null>(null)
|
||||
const groupOptions = ref<GroupOption[]>([])
|
||||
|
||||
@@ -127,11 +134,11 @@ onMounted(load)
|
||||
<div class="form-row usage-filter-row">
|
||||
<div class="form-group" style="min-width: 160px">
|
||||
<label>开始日期</label>
|
||||
<input v-model="startDate" type="date" />
|
||||
<input v-model="startDate" type="date" :max="endDate" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 160px">
|
||||
<label>结束日期</label>
|
||||
<input v-model="endDate" type="date" />
|
||||
<input v-model="endDate" type="date" :min="startDate" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 200px">
|
||||
<label>用户名</label>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
/** 数据去重总数据(registry) · 像素复刻旧版 admin.html panel-dedupe-total-data(自绘:分组摘要 + 双行筛选 + 旧式表格/分页 + 编辑/导入弹窗 + 导出等待遮罩)。
|
||||
* script 逻辑沿用现有 Vue 实现(查询/编辑/删除/导入轮询/导出秒表)。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
@@ -39,6 +39,13 @@ const page = ref(1)
|
||||
const pageSize = ref(10)
|
||||
/** 本页是累计台账,日期初值故意留空(默认当天会让首屏只剩今天新增的 ASIN);见 date-filter-default-today 护栏的 EXEMPT。 */
|
||||
const filter = reactive(createDedupeTotalFilterState())
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(filter.startDate, filter.endDate)
|
||||
filter.startDate = s
|
||||
filter.endDate = e
|
||||
}
|
||||
|
||||
const groups = ref<DedupeGroupOption[]>([])
|
||||
/** 非超管仅有一个可访问分组时,编辑/导入弹窗分组选择锁定为该组(保留展示、不可改)。 */
|
||||
const lockedGroupId = computed<number | null>(() => {
|
||||
@@ -271,11 +278,6 @@ async function submitImport(): Promise<void> {
|
||||
}
|
||||
|
||||
async function doExport(): Promise<void> {
|
||||
const { startDate, endDate } = filter
|
||||
if (startDate && endDate && startDate > endDate) {
|
||||
ElMessage.warning('开始日期不能晚于结束日期')
|
||||
return
|
||||
}
|
||||
if (exporting.value) return
|
||||
exporting.value = true
|
||||
startExportWait()
|
||||
@@ -368,11 +370,11 @@ onMounted(() => {
|
||||
<div class="dedupe-filter-date-row">
|
||||
<div class="form-group">
|
||||
<label>开始日期</label>
|
||||
<input v-model="filter.startDate" type="date" />
|
||||
<input v-model="filter.startDate" type="date" :max="filter.endDate" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>结束日期</label>
|
||||
<input v-model="filter.endDate" type="date" />
|
||||
<input v-model="filter.endDate" type="date" :min="filter.startDate" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="dedupe-filter-actions">
|
||||
<button class="btn btn-secondary" type="button" :disabled="exporting" @click="doExport">
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { formatDateTime, todayDateInput } from '@/utils/datetime'
|
||||
import { formatDateTime, orderedPair, todayDateInput } from '@/utils/datetime'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { fetchHistoryUserOptions } from './history-api.ts'
|
||||
import type { HistoryUserOption } from './history-user-option.ts'
|
||||
@@ -63,6 +63,13 @@ const userOptions = ref<HistoryUserOption[]>([])
|
||||
const usersLoading = ref(false)
|
||||
const startDate = ref(todayDateInput())
|
||||
const endDate = ref(todayDateInput())
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(startDate.value, endDate.value)
|
||||
startDate.value = s
|
||||
endDate.value = e
|
||||
}
|
||||
|
||||
const retentionDays = ref(7)
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
@@ -294,11 +301,11 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>日志日期(起)</label>
|
||||
<input v-model="startDate" type="date" />
|
||||
<input v-model="startDate" type="date" :max="endDate" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>日志日期(止)</label>
|
||||
<input v-model="endDate" type="date" />
|
||||
<input v-model="endDate" type="date" :min="startDate" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label> </label>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
/** 生成记录页 · 像素复刻旧版 admin.html panel-history(自绘:form-box 筛选 + panel-box 表格 + 旧式分页 + thumb 缩略图)。
|
||||
* script 逻辑沿用现有 Vue 实现(查询/翻页/跳页/点击缩略图放大预览)。 */
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { fetchHistoryList, fetchHistoryUserOptions } from './history-api.ts'
|
||||
import type { HistoryUserOption } from './history-user-option.ts'
|
||||
@@ -23,6 +23,13 @@ const userOptions = ref<HistoryUserOption[]>([])
|
||||
const errorText = ref('')
|
||||
/** 起止时间初值故意留空:默认锁当天会让首屏只剩今天的生成记录(用户 2026-10-04 定案),见 date-filter-default-today 护栏的 EXEMPT。 */
|
||||
const filter = reactive({ userId: '', timeStart: '', timeEnd: '' })
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(filter.timeStart, filter.timeEnd)
|
||||
filter.timeStart = s
|
||||
filter.timeEnd = e
|
||||
}
|
||||
|
||||
|
||||
const previewVisible = ref(false)
|
||||
const previewItem = ref<HistoryRecordItem | null>(null)
|
||||
@@ -146,11 +153,11 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>开始时间</label>
|
||||
<input v-model="filter.timeStart" type="datetime-local" />
|
||||
<input v-model="filter.timeStart" type="datetime-local" :max="filter.timeEnd" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>结束时间</label>
|
||||
<input v-model="filter.timeEnd" type="datetime-local" />
|
||||
<input v-model="filter.timeEnd" type="datetime-local" :min="filter.timeStart" @change="clampDatePair" />
|
||||
</div>
|
||||
<button class="btn" type="button" @click="apply">查询</button>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { userNotice } from '@/api/user-notice'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
import {
|
||||
fetchTaskCenterOverview,
|
||||
fetchTaskCenterShopOptions,
|
||||
@@ -65,6 +65,13 @@ function defaultTaskFilter(): TaskCenterTaskFilter {
|
||||
}
|
||||
|
||||
const filter = reactive<TaskCenterTaskFilter>(defaultTaskFilter())
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(filter.startTime, filter.endTime)
|
||||
filter.startTime = s
|
||||
filter.endTime = e
|
||||
}
|
||||
|
||||
const tasks = ref<TaskCenterTaskRow[]>([])
|
||||
const taskTotal = ref(0)
|
||||
const taskPage = ref(1)
|
||||
@@ -385,11 +392,11 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 190px">
|
||||
<label>创建时间(起)</label>
|
||||
<input v-model="filter.startTime" type="datetime-local" />
|
||||
<input v-model="filter.startTime" type="datetime-local" :max="filter.endTime" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 190px">
|
||||
<label>创建时间(止)</label>
|
||||
<input v-model="filter.endTime" type="datetime-local" />
|
||||
<input v-model="filter.endTime" type="datetime-local" :min="filter.startTime" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label> </label>
|
||||
|
||||
@@ -12,6 +12,7 @@ import { fetchDuplicateConsole, fetchDuplicateLedger, requestDuplicateExportBlob
|
||||
import { aggregateDrawerRows, drawerSummaryOf, dupWithinGroup, indexShopGroups, type DrawerAggRow, type DrawerSummary, type ShopGroups } from './duplicate-console-logic.ts'
|
||||
import type { DuplicateConsole, LedgerRow } from './duplicate-console-model.ts'
|
||||
import { ASIN_COUNTRY_CODES, asinCountryLabel } from '../asin/asin-country.ts'
|
||||
import { orderedPair } from '@/utils/datetime'
|
||||
|
||||
type Tab = 'dup' | 'ledger'
|
||||
type Scope = 'global' | 'group'
|
||||
@@ -22,6 +23,13 @@ const loadError = ref('')
|
||||
const reanalyzing = ref(false)
|
||||
|
||||
const filter = reactive({ asin: '', shop: '', group: '', country: '', dateFrom: '', dateTo: '' })
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(filter.dateFrom, filter.dateTo)
|
||||
filter.dateFrom = s
|
||||
filter.dateTo = e
|
||||
}
|
||||
|
||||
|
||||
/** 角色范围:超管可看全部分组店铺并可跨分组筛选;管理员数据已由后端裁剪到自己分组,无需分组筛选。 */
|
||||
const session = useAdminSessionStore()
|
||||
@@ -248,10 +256,6 @@ async function loadLedger(page: number, resetSort = false) {
|
||||
}
|
||||
|
||||
function applyQuery() {
|
||||
if (filter.dateFrom && filter.dateTo && filter.dateFrom > filter.dateTo) {
|
||||
toast('开始日期不能晚于结束日期')
|
||||
return
|
||||
}
|
||||
loadConsole()
|
||||
if (activeTab.value === 'ledger') loadLedger(1)
|
||||
}
|
||||
@@ -462,11 +466,11 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label>上架时间开始</label>
|
||||
<input type="date" v-model="filter.dateFrom" />
|
||||
<input type="date" v-model="filter.dateFrom" :max="filter.dateTo" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label>上架时间结束</label>
|
||||
<input type="date" v-model="filter.dateTo" />
|
||||
<input type="date" v-model="filter.dateTo" :min="filter.dateFrom" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label> </label>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
import { userNotice } from '@/api/user-notice'
|
||||
/** 视频任务记录页 · 像素复刻旧版 admin.html panel-image-video-tasks(自绘:form-box 筛选[用户名/提交起止+查询/重置] + panel-box toolbar[全选/批量下载/权限配置/汇总] + 任务卡片网格 + 旧式分页)。
|
||||
* script 逻辑沿用现有 Vue 实现(批量打包/明细抽屉/权限授权)。 */
|
||||
@@ -32,6 +32,12 @@ const pageSize = ref(10)
|
||||
const jumpPage = ref('')
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(totalTasks.value / pageSize.value)))
|
||||
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(filter.dateRange[0], filter.dateRange[1])
|
||||
filter.dateRange = [s, e]
|
||||
}
|
||||
|
||||
/** 提交时间初值故意留空:默认锁当天会让首屏只剩今天提交的任务(用户 2026-10-04 定案),见 date-filter-default-today 护栏的 EXEMPT。 */
|
||||
const filter = reactive<ImageVideoFilter & { dateRange: string[] }>({
|
||||
...createImageVideoFilter(),
|
||||
@@ -310,11 +316,11 @@ onMounted(load)
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>提交开始</label>
|
||||
<input v-model="filter.dateRange[0]" type="datetime-local" />
|
||||
<input v-model="filter.dateRange[0]" type="datetime-local" :max="filter.dateRange[1]" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>提交结束</label>
|
||||
<input v-model="filter.dateRange[1]" type="datetime-local" />
|
||||
<input v-model="filter.dateRange[1]" type="datetime-local" :min="filter.dateRange[0]" @change="clampDatePair" />
|
||||
</div>
|
||||
<button class="btn" type="button" @click="apply">查询</button>
|
||||
<button class="btn btn-secondary" type="button" @click="reset">重置</button>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
/** 店铺数据记录页 · 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(自绘:form-box 筛选[h4 筛选条件] + panel-box toolbar[全选/批量下载/权限配置/汇总] + 每店卡片网格 + 旧式分页(店铺级+卡片级 9/页))。
|
||||
* script 逻辑沿用现有 Vue 实现(批量打包/删除结果文件[保留]/权限授权)。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
@@ -42,6 +42,12 @@ const cardPageSize = ref(10)
|
||||
const cardJump = ref('')
|
||||
const cardTotalPages = computed(() => Math.max(1, Math.ceil(allResultRows.value.length / cardPageSize.value)))
|
||||
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(filter.dateRange[0], filter.dateRange[1])
|
||||
filter.dateRange = [s, e]
|
||||
}
|
||||
|
||||
/** 创建时间初值故意留空:默认锁当天会让首屏只剩今天新建的任务(用户 2026-10-04 定案),见 date-filter-default-today 护栏的 EXEMPT。 */
|
||||
const filter = reactive<ShopDataFilter & { dateRange: string[] }>({
|
||||
...createShopDataFilter(),
|
||||
@@ -329,11 +335,11 @@ onMounted(load)
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>创建开始</label>
|
||||
<input v-model="filter.dateRange[0]" type="datetime-local" />
|
||||
<input v-model="filter.dateRange[0]" type="datetime-local" :max="filter.dateRange[1]" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>创建结束</label>
|
||||
<input v-model="filter.dateRange[1]" type="datetime-local" />
|
||||
<input v-model="filter.dateRange[1]" type="datetime-local" :min="filter.dateRange[0]" @change="clampDatePair" />
|
||||
</div>
|
||||
<button class="btn" type="button" @click="apply">查询</button>
|
||||
<button class="btn btn-secondary" type="button" @click="reset">重置</button>
|
||||
|
||||
@@ -45,6 +45,15 @@ export function todayDateTimeRange(now: Date = new Date()): [string, string] {
|
||||
return [`${day}T00:00`, `${day}T23:59`]
|
||||
}
|
||||
|
||||
/**
|
||||
* 起止成对筛选的统一钳制:input 上的 min/max 只灰掉日历面板里的非法日,
|
||||
* 手输、粘贴、清空再填仍能越界,所以落值后把倒挂的两端交换——
|
||||
* 输入框显示与发出去的查询区间始终是同一条。
|
||||
*/
|
||||
export function orderedPair(start: string, end: string): [string, string] {
|
||||
return start && end && start > end ? [end, start] : [start, end]
|
||||
}
|
||||
|
||||
function padDate(d: Date): string {
|
||||
const y = d.getFullYear()
|
||||
const mo = pad(d.getMonth() + 1)
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { resolve, dirname, join } from 'node:path'
|
||||
import { orderedPair } from '../src/utils/datetime.ts'
|
||||
|
||||
/**
|
||||
* 全项目时间控件顺序尺子(2026-10-09)。
|
||||
*
|
||||
* 起因:用户指令"项目所有的前端时间控件 开始日期不能晚于结束日期"。普查
|
||||
* (ops 仓 scripts/_census_time_controls.py)在四棵活树里数出 55 个日期/时间控件实例、
|
||||
* 21 个成对区间,其中后管 8 对与麦象控制台 2 对两头裸奔——起止能选到倒挂,查询恒定
|
||||
* 返回空表,页面上却没有任何提示。
|
||||
*
|
||||
* 每一对成对控件判两条,缺一即红:
|
||||
* ① 日历面板禁选:起侧 max 指向止、止侧 min 指向起;
|
||||
* ② 手输兜底:值落回状态时把倒挂的两端交换(本树 @change="clampDatePair",
|
||||
* 财务系统走 useDateRange 的 setter)。
|
||||
* 只做 ① 不够:原生 input 手输、粘贴仍能越界,浏览器只把控件标成 :invalid,
|
||||
* 状态里留下的还是倒挂值。
|
||||
*
|
||||
* 分母硬钉(实例数/对数):扫描器一旦失明(改写法、挪目录、文件名换了),
|
||||
* 当场判红,而不是拿着"0 违规"报绿。
|
||||
*/
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const WS = resolve(here, '../../..')
|
||||
|
||||
const DATE_TYPES = new Set(['date', 'datetime-local', 'month', 'week', 'time'])
|
||||
const RANGE_TYPES = new Set(['daterange', 'datetimerange', 'monthrange', 'yearsrange', 'dates', 'times'])
|
||||
const PICKERS = new Set(['el-date-picker', 'el-time-picker', 'el-time-select', 'datepicker', 'rangepicker'])
|
||||
const SKIP_DIRS = new Set(['node_modules', 'dist', 'build', '.venv', '__pycache__', 'target', 'app_resource', 'app_client_baseline', 'crawler_cache'])
|
||||
const EXTS = new Set(['.vue', '.tsx', '.jsx', '.ts', '.js', '.html'])
|
||||
|
||||
interface Control {
|
||||
file: string
|
||||
line: number
|
||||
type: string
|
||||
model: string
|
||||
role: 'start' | 'end' | 'single' | 'range'
|
||||
family: string
|
||||
minToPartner: boolean
|
||||
maxToPartner: boolean
|
||||
clamp: boolean
|
||||
}
|
||||
|
||||
function walk(base: string): string[] {
|
||||
const out: string[] = []
|
||||
for (const name of readdirSync(base)) {
|
||||
const p = join(base, name)
|
||||
const st = statSync(p)
|
||||
if (st.isDirectory()) {
|
||||
if (!SKIP_DIRS.has(name)) out.push(...walk(p))
|
||||
} else if (EXTS.has(name.slice(name.lastIndexOf('.'))) && !/\.(test|spec)\.[tj]sx?$/.test(name)) {
|
||||
out.push(p)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 注释区涂成等长空格(保住行号);引号里的 // 不当注释。 */
|
||||
function blankComments(src: string): string {
|
||||
const out = src.split('')
|
||||
let i = 0
|
||||
let q: string | null = null
|
||||
while (i < src.length) {
|
||||
const c = src[i]
|
||||
if (q) {
|
||||
if (c === '\\') i += 2
|
||||
else if (c === q) { q = null; i += 1 }
|
||||
else i += 1
|
||||
continue
|
||||
}
|
||||
if (c === '"' || c === "'" || c === '`') { q = c; i += 1; continue }
|
||||
let end = -1
|
||||
if (src.startsWith('<!--', i)) { const j = src.indexOf('-->', i); end = j < 0 ? src.length : j + 3 }
|
||||
else if (src.startsWith('/*', i)) { const j = src.indexOf('*/', i); end = j < 0 ? src.length : j + 2 }
|
||||
else if (src.startsWith('//', i)) { const j = src.indexOf('\n', i); end = j < 0 ? src.length : j }
|
||||
if (end > i) {
|
||||
for (let k = i; k < end; k++) if (out[k] !== '\n') out[k] = ' '
|
||||
i = end
|
||||
continue
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
return out.join('')
|
||||
}
|
||||
|
||||
/** 从 '<' 取到配平的 '>':跳过引号与 JSX 花括号里的 '>'。 */
|
||||
function tagSlice(src: string, from: number): string {
|
||||
let depth = 0
|
||||
let q: string | null = null
|
||||
for (let i = from; i < src.length; i++) {
|
||||
const c = src[i]
|
||||
if (q) { if (c === '\\') i++; else if (c === q) q = null; continue }
|
||||
if (c === '"' || c === "'" || c === '`') { q = c; continue }
|
||||
if (c === '{' || c === '(' || c === '[') depth++
|
||||
else if (c === '}' || c === ')' || c === ']') depth--
|
||||
else if (c === '>' && depth === 0) return src.slice(from, i + 1)
|
||||
}
|
||||
return src.slice(from)
|
||||
}
|
||||
|
||||
function quotedAttr(tag: string, name: string): string {
|
||||
const m = new RegExp('[\\s:]' + name + '\\s*=\\s*"([^"]*)"', 'i').exec(tag)
|
||||
return m ? m[1] : ''
|
||||
}
|
||||
|
||||
function bracedAttr(tag: string, name: string): string {
|
||||
const m = new RegExp('[\\s:]' + name + '\\s*=\\{([^}]*)\\}', 'i').exec(tag)
|
||||
return m ? m[1].trim() : ''
|
||||
}
|
||||
|
||||
function modelOf(tag: string): string {
|
||||
const vue = /[\s]v-model(?::[\w-]+)?(?:\.\w+)*="([^"]*)"/.exec(tag)
|
||||
if (vue) return vue[1]
|
||||
const bound = /[\s]:model-value="([^"]*)"/.exec(tag)
|
||||
if (bound) return bound[1]
|
||||
const jsx = /\bvalue=\{([^}]*)\}/.exec(tag)
|
||||
if (jsx) return jsx[1].replace(/^String\(/, '').replace(/\|\|.*$/, '').replace(/[()'\s"]/g, '')
|
||||
return quotedAttr(tag, 'name') || quotedAttr(tag, 'id')
|
||||
}
|
||||
|
||||
const isStartWord = /start|begin|first|from|\[0\]/i
|
||||
// to(?![a-z]) 认 dateTo 为止,又不把 total/auto 这类词误判成止
|
||||
const isEndWord = /end|finish|last|to(?![a-z])|\[1\]/i
|
||||
|
||||
function roleOf(type: string, model: string): Control['role'] {
|
||||
if (RANGE_TYPES.has(type) || type === 'range') return 'range'
|
||||
const norm = model.replace(/]/g, '')
|
||||
if (/\[0$/.test(norm)) return 'start'
|
||||
if (/\[1$/.test(norm)) return 'end'
|
||||
const tail = norm.split('.').pop() || ''
|
||||
const s = isStartWord.test(tail)
|
||||
const e = isEndWord.test(tail)
|
||||
if (s && !e) return 'start'
|
||||
if (e && !s) return 'end'
|
||||
return 'single'
|
||||
}
|
||||
|
||||
function familyOf(model: string): string {
|
||||
const dot = model.lastIndexOf('.')
|
||||
const head = dot < 0 ? '' : model.slice(0, dot + 1)
|
||||
const tail = (dot < 0 ? model : model.slice(dot + 1))
|
||||
.replace(/start|end|finish|begin|first|last|from|to(?![a-z])|\[\d\]|_\d/gi, '')
|
||||
.replace(/^_+|_+$/g, '')
|
||||
return (head + (tail || 'x')).toLowerCase()
|
||||
}
|
||||
|
||||
function scan(base: string, clampRule: (tag: string) => boolean): Control[] {
|
||||
const found: Control[] = []
|
||||
for (const file of walk(base)) {
|
||||
const raw = readFileSync(file, 'utf-8')
|
||||
const clean = blankComments(raw)
|
||||
const re = /<\s*([A-Za-z][\w\-.]*)/g
|
||||
let m: RegExpExecArray | null
|
||||
while ((m = re.exec(clean))) {
|
||||
const tag = tagSlice(clean, m.index)
|
||||
const isPicker = PICKERS.has(m[1].toLowerCase())
|
||||
const type = quotedAttr(tag, 'type').replace(/[{}"]/g, '') || bracedAttr(tag, 'type')
|
||||
if (!isPicker && !DATE_TYPES.has(type) && !RANGE_TYPES.has(type)) continue
|
||||
const model = modelOf(tag)
|
||||
const minVal = quotedAttr(tag, 'min') || bracedAttr(tag, 'min')
|
||||
const maxVal = quotedAttr(tag, 'max') || bracedAttr(tag, 'max')
|
||||
found.push({
|
||||
file: file.slice(WS.length + 1).replace(/\\/g, '/'),
|
||||
line: clean.slice(0, m.index).split('\n').length,
|
||||
type,
|
||||
model,
|
||||
role: roleOf(type, model),
|
||||
family: familyOf(model),
|
||||
minToPartner: isStartWord.test(minVal),
|
||||
maxToPartner: isEndWord.test(maxVal),
|
||||
clamp: clampRule(tag),
|
||||
})
|
||||
}
|
||||
}
|
||||
return found
|
||||
}
|
||||
|
||||
/** 成对控件逐对判:两头都要"禁选对家 + 手输兜底",缺一样登记违规。 */
|
||||
function nakedPairs(controls: Control[]): string[] {
|
||||
const pairs = new Map<string, Control[]>()
|
||||
for (const c of controls) {
|
||||
if (c.role !== 'start' && c.role !== 'end') continue
|
||||
const key = c.file + '#' + c.family
|
||||
pairs.set(key, (pairs.get(key) || []).concat(c))
|
||||
}
|
||||
const bad: string[] = []
|
||||
for (const [key, list] of pairs) {
|
||||
const start = list.find(c => c.role === 'start')
|
||||
const end = list.find(c => c.role === 'end')
|
||||
if (!start || !end) {
|
||||
bad.push(`配对失败(多半是变量名换了写法):${key} -> ${list.map(c => `${c.model}:${c.role}`).join(', ')}`)
|
||||
continue
|
||||
}
|
||||
const miss: string[] = []
|
||||
if (!start.maxToPartner) miss.push('起侧 max 没指向止')
|
||||
if (!end.minToPartner) miss.push('止侧 min 没指向起')
|
||||
if (!start.clamp || !end.clamp) miss.push('缺手输兜底(倒挂交换)')
|
||||
if (miss.length) bad.push(`${start.file}:${start.line}/${end.line} ${start.model}~${end.model} 缺:${miss.join('、')}`)
|
||||
}
|
||||
return bad
|
||||
}
|
||||
|
||||
const pairCount = (controls: Control[]) => {
|
||||
const keys = new Set<string>()
|
||||
for (const c of controls) if (c.role === 'start' || c.role === 'end') keys.add(c.file + '#' + c.family)
|
||||
return [...keys].filter(k => {
|
||||
const list = controls.filter(c => (c.file + '#' + c.family) === k)
|
||||
return list.some(c => c.role === 'start') && list.some(c => c.role === 'end')
|
||||
}).length
|
||||
}
|
||||
|
||||
const vueClamp = (tag: string) => /@change="clamp\w*"/.test(tag)
|
||||
const jsxClamp = (tag: string) => /onChange=\{[\s\S]{0,200}?(setStartDate|setEndDate|set\w+Input)\s*\(/.test(tag)
|
||||
|
||||
const adminCtrls = scan(resolve(here, '../src'), vueClamp)
|
||||
const userCtrls = scan(resolve(WS, 'crawler-plugin/frontend-vue/src'), vueClamp)
|
||||
const finCtrls = scan(resolve(WS, 'shop-finance-source/shop-finance-src/client/src'), jsxClamp)
|
||||
const mxCtrls = scan(resolve(WS, 'maixiang_run_task/maixiang_task_api'), vueClamp)
|
||||
|
||||
test('orderedPair 只在两端都有值且倒挂时交换', () => {
|
||||
assert.deepEqual(orderedPair('2026-10-01', '2026-10-05'), ['2026-10-01', '2026-10-05'])
|
||||
assert.deepEqual(orderedPair('2026-10-05', '2026-10-01'), ['2026-10-01', '2026-10-05'])
|
||||
assert.deepEqual(orderedPair('', '2026-10-05'), ['', '2026-10-05'])
|
||||
assert.deepEqual(orderedPair('2026-10-05', ''), ['2026-10-05', ''])
|
||||
assert.deepEqual(orderedPair('2026-10-05T09:00', '2026-10-05T08:30'), ['2026-10-05T08:30', '2026-10-05T09:00'])
|
||||
})
|
||||
|
||||
test('分母硬钉:四面控件实例数与成对数(扫描失明即红)', () => {
|
||||
assert.equal(adminCtrls.length, 19, '后管实例数变了,先复算普查再改这里')
|
||||
assert.equal(userCtrls.length, 2, '用户端实例数变了')
|
||||
assert.equal(finCtrls.length, 30, '财务系统实例数变了')
|
||||
assert.equal(mxCtrls.length, 4, '麦象实例数变了')
|
||||
assert.equal(pairCount(adminCtrls), 8, '后管成对区间应为 8')
|
||||
assert.equal(pairCount(finCtrls), 11, '财务系统成对区间应为 11')
|
||||
assert.equal(pairCount(mxCtrls), 2, '麦象成对区间应为 2')
|
||||
assert.equal(pairCount(userCtrls), 0, '用户端出现成对区间说明新加了两个单只控件')
|
||||
})
|
||||
|
||||
test('反例自证:裸对、只有一头、只有 min/max 都要被判出', () => {
|
||||
const naked: Control[] = [
|
||||
{ file: 'x.vue', line: 1, type: 'date', model: 'a.startDate', role: 'start', family: 'a.date', minToPartner: false, maxToPartner: false, clamp: false },
|
||||
{ file: 'x.vue', line: 2, type: 'date', model: 'a.endDate', role: 'end', family: 'a.date', minToPartner: false, maxToPartner: false, clamp: false },
|
||||
]
|
||||
assert.equal(nakedPairs(naked).length, 1, '判不出裸对,那它报的"0 违规"不作数')
|
||||
assert.equal(nakedPairs([{ ...naked[0], maxToPartner: true, clamp: true }, { ...naked[1], clamp: true }]).length, 1, '只给一头加约束不算收口')
|
||||
assert.equal(nakedPairs([{ ...naked[0], maxToPartner: true }, { ...naked[1], minToPartner: true }]).length, 1, '只有 min/max、手输能越界,不算收口')
|
||||
assert.deepEqual(nakedPairs([{ ...naked[0], maxToPartner: true, clamp: true }, { ...naked[1], minToPartner: true, clamp: true }]), [], '正例被误报')
|
||||
assert.equal(nakedPairs([naked[0]]).length, 1, '孤儿起止(只有一头)必须露出来')
|
||||
})
|
||||
|
||||
test('反例自证(真文件):裸对判红、写法换了扫描器要掉分母', () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'date-ruler-'))
|
||||
try {
|
||||
// ① 一对裸控件:两头都没有对家约束,必须被点名
|
||||
writeFileSync(join(dir, 'naked.vue'), '<template>\n <input v-model="filter.startDate" type="date" />\n <input v-model="filter.endDate" type="date" />\n</template>\n')
|
||||
// ② 一对齐的:min/max 互绑 + @change 兜手输,不许误报
|
||||
writeFileSync(join(dir, 'good.vue'), '<template>\n <input v-model="f.startDate" type="date" :max="f.endDate" @change="clampDatePair" />\n <input v-model="f.endDate" type="date" :min="f.startDate" @change="clampDatePair" />\n</template>\n')
|
||||
// ③ 只给一头加约束
|
||||
writeFileSync(join(dir, 'half.vue'), '<template>\n <input v-model="q.startDate" type="date" :max="q.endDate" @change="clampDatePair" />\n <input v-model="q.endDate" type="date" />\n</template>\n')
|
||||
const found = scan(dir, vueClamp)
|
||||
assert.equal(found.length, 6, '扫描器从真文件里数出的实例数不对(写法换了就会掉分母)')
|
||||
const bad = nakedPairs(found)
|
||||
assert.equal(bad.length, 2, `应点名 naked 与 half 两组:${bad.join(' | ')}`)
|
||||
assert.ok(bad.some(t => /naked\.vue/.test(t)), '裸对没被点名')
|
||||
assert.ok(bad.some(t => /half\.vue/.test(t)), '只有单侧的没被点名')
|
||||
// ④ 换成扫描器词表外的写法:分母必须掉下来,否则"0 违规"是假的
|
||||
writeFileSync(join(dir, 'naked.vue'), '<template>\n <DateField v-model="filter.startDate" kind="date" />\n <DateField v-model="filter.endDate" kind="date" />\n</template>\n')
|
||||
assert.equal(scan(dir, vueClamp).length, 4, '换了组件写法后实例数没掉——说明分母根本不是数出来的')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test('后管 8 对日期筛选:max/min 互绑 + @change 倒挂交换', () => {
|
||||
assert.deepEqual(nakedPairs(adminCtrls), [])
|
||||
})
|
||||
|
||||
test('麦象控制台 2 对:任务列表与批次列表的起止都收口', () => {
|
||||
assert.deepEqual(nakedPairs(mxCtrls), [])
|
||||
})
|
||||
|
||||
test('财务系统 11 对:max/min 互绑 + onChange 走 useDateRange 的 setter', () => {
|
||||
assert.deepEqual(nakedPairs(finCtrls), [])
|
||||
})
|
||||
|
||||
test('口径统一:财务系统的兜底是交换,不是塌缩', () => {
|
||||
const hook = readFileSync(resolve(WS, 'shop-finance-source/shop-finance-src/client/src/hooks/useDateRange.ts'), 'utf-8')
|
||||
assert.ok(!/\{ startDate: next, endDate: next \}/.test(hook), '还在把区间塌缩到刚点那天——与后管 orderedPair 的交换口径分叉')
|
||||
assert.match(hook, /\{ startDate: prev\.endDate, endDate: next \}/, '起越过止时应交换成 [止, 起]')
|
||||
assert.match(hook, /\{ startDate: next, endDate: prev\.startDate \}/, '止越过起时应交换成 [止, 起]')
|
||||
})
|
||||
|
||||
test('反向钉:交换已接管有序,页面不许再自己弹"开始日期不能晚于结束"', () => {
|
||||
const texts = ['src/pages/asin/DedupeRegistryPage.vue', 'src/pages/tasks/DuplicateCheckPage.vue']
|
||||
.map(rel => readFileSync(resolve(here, '..', rel), 'utf-8'))
|
||||
for (const t of texts) {
|
||||
assert.ok(!t.includes('开始日期不能晚于结束日期'), '倒挂值在 change 时就被换掉了,这条拦截够不着,属死分支')
|
||||
}
|
||||
})
|
||||
|
||||
test('用户端维持:区间型由组件自身保序,单只那处不变量', () => {
|
||||
assert.equal(userCtrls.filter(c => c.role === 'range').length, 1, 'daterange 型数量变了要重新分档')
|
||||
const single = userCtrls.find(c => c.role === 'single')
|
||||
assert.ok(single && /BrandShopMatchTab/.test(single.file), '用户端单只日期控件变了,按首屏语义重新分档')
|
||||
assert.deepEqual(nakedPairs(userCtrls), [])
|
||||
})
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* 起止日期倒挂必须被真的换回来(2026-10-09 指令「项目所有的前端时间控件 开始日期不能晚于结束日期」)。
|
||||
*
|
||||
* 形状钉子(`:max`/`:min`/`@change` 在不在)由 tests/date-range-order.test.ts 管;
|
||||
* 这支跑真组件:往两个 input 里填倒挂的日期、触发 change,看状态与发出去的查询参数
|
||||
* 是不是同一条有序区间。min/max 只管日历面板,手输越界全靠 clampDatePair 兜。
|
||||
*
|
||||
* 跑法:`npm run test:mount`(vitest + jsdom,配置见 vitest.config.ts)。
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
|
||||
import UserSecretUsagePage from '@/pages/account/UserSecretUsagePage.vue'
|
||||
|
||||
const usageApi = vi.hoisted(() => ({ fetchUserSecretUsage: vi.fn() }))
|
||||
|
||||
vi.mock('@/api/user-secret-usage', () => usageApi)
|
||||
vi.mock('@/stores/admin-session', () => ({
|
||||
useAdminSessionStore: () => ({ isSuperAdmin: true }),
|
||||
}))
|
||||
vi.mock('@/stores/company-tab', () => ({
|
||||
useCompanyTabStore: () => ({ activeId: 1, requestCompanyId: 1 }),
|
||||
}))
|
||||
|
||||
const dateInputs = (wrapper: VueWrapper) => wrapper.findAll('input[type="date"]')
|
||||
|
||||
describe('UserSecretUsagePage:起止倒挂时交换', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
usageApi.fetchUserSecretUsage.mockResolvedValue({ items: [], total: 0, groupOptions: [] })
|
||||
})
|
||||
|
||||
it('手输倒挂的结束日期后,两头落回有序区间', async () => {
|
||||
const wrapper = mount(UserSecretUsagePage)
|
||||
await flushPromises()
|
||||
const [start, end] = dateInputs(wrapper)
|
||||
|
||||
await start.setValue('2026-10-05')
|
||||
await start.trigger('change')
|
||||
await end.setValue('2026-10-01')
|
||||
await end.trigger('change')
|
||||
|
||||
expect(start.element.value).toBe('2026-10-01')
|
||||
expect(end.element.value).toBe('2026-10-05')
|
||||
})
|
||||
|
||||
it('点查询发出去的参数同样有序(输入框显示与请求一致)', async () => {
|
||||
const wrapper = mount(UserSecretUsagePage)
|
||||
await flushPromises()
|
||||
const [start, end] = dateInputs(wrapper)
|
||||
|
||||
await start.setValue('2026-10-05')
|
||||
await start.trigger('change')
|
||||
await end.setValue('2026-10-01')
|
||||
await end.trigger('change')
|
||||
usageApi.fetchUserSecretUsage.mockClear()
|
||||
|
||||
await wrapper.get('button.btn').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const sent = usageApi.fetchUserSecretUsage.mock.calls.at(-1)?.[0]
|
||||
expect(sent?.startDate).toBe('2026-10-01')
|
||||
expect(sent?.endDate).toBe('2026-10-05')
|
||||
expect(sent.startDate <= sent.endDate).toBe(true)
|
||||
})
|
||||
|
||||
it('只填一头时不擅自补另一头(空值视为不设限)', async () => {
|
||||
const wrapper = mount(UserSecretUsagePage)
|
||||
await flushPromises()
|
||||
const [start, end] = dateInputs(wrapper)
|
||||
|
||||
await end.setValue('')
|
||||
await end.trigger('change')
|
||||
await start.setValue('2026-10-20')
|
||||
await start.trigger('change')
|
||||
|
||||
expect(start.element.value).toBe('2026-10-20')
|
||||
expect(end.element.value).toBe('')
|
||||
})
|
||||
})
|
||||
@@ -39,7 +39,7 @@ test('test_task_254_dedupe_boundary_empty_input', () => {
|
||||
|
||||
test('test_task_254_dedupe_boundary_single_item', () => {
|
||||
const page = readSource('src/pages/asin/DedupeRegistryPage.vue')
|
||||
assert.match(page, /开始日期不能晚于结束日期|晚于结束日期/, '导出需做日期区间校验')
|
||||
assert.match(page, /:max="filter\.endDate"[^>]*@change="clampDatePair"/, '导出区间需由 min/max 禁选 + 倒挂交换保证有序')
|
||||
assert.match(page, /确定删除总数据/, '行删除确认文案应对齐 admin')
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user