♻️ style: format code with Prettier and fix .gitattributes

- Add *.yaml text eol=lf rule to .gitattributes for consistent line endings
- Format cleaner.ts with Prettier (parameter and chain formatting)
- Format CleanerPage.tsx (JSX formatting)
- Format cleaner.test.ts (array formatting)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
test
2026-03-16 22:42:16 +08:00
parent 975bee6ce8
commit 103effcfca
4 changed files with 39 additions and 18 deletions

1
.gitattributes vendored
View File

@@ -6,6 +6,7 @@
*.js text eol=lf
*.json text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.tsx text eol=lf
*.jsx text eol=lf
*.css text eol=lf

View File

@@ -62,7 +62,12 @@ export interface ShouldDeleteParams {
deleteSet: Set<string>
}
function clampNumber(value: number | undefined, fallback: number, min: number, max: number): number {
function clampNumber(
value: number | undefined,
fallback: number,
min: number,
max: number
): number {
if (!Number.isFinite(value)) {
return fallback
}
@@ -281,7 +286,9 @@ export class CleanerService {
const retryResult = await this.retryFailedOrders({
workFrame,
popupPage,
failedDetails: result.details.filter((d) => d.errors.length > 0 && this.isOrderNumber(d.orderNumber)),
failedDetails: result.details.filter(
(d) => d.errors.length > 0 && this.isOrderNumber(d.orderNumber)
),
deleteSet,
dryRun,
onProgress: input.onProgress
@@ -482,7 +489,12 @@ export class CleanerService {
onProgress?.(
`开始处理订单: ${orderNumber}`,
this.calculateProgress(progressState.completedOrders, 0, detailCount, progressState.totalOrders),
this.calculateProgress(
progressState.completedOrders,
0,
detailCount,
progressState.totalOrders
),
{
currentOrderIndex: progressState.completedOrders + 1,
totalOrders: progressState.totalOrders,
@@ -530,13 +542,17 @@ export class CleanerService {
progressState.totalOrders
)
onProgress?.(`订单 ${orderNumber} - 物料 ${materialIdx}/${detailCount}: ${materialName}`, progress, {
onProgress?.(
`订单 ${orderNumber} - 物料 ${materialIdx}/${detailCount}: ${materialName}`,
progress,
{
currentOrderIndex: progressState.completedOrders + 1,
totalOrders: progressState.totalOrders,
currentMaterialIndex: materialIdx,
totalMaterialsInOrder: detailCount,
currentOrderNumber: orderNumber
})
}
)
if (deleteSet.has(materialCode)) {
const shouldDelete = this.shouldDeleteMaterial({
@@ -610,7 +626,10 @@ export class CleanerService {
private async extractSourceOrderNumber(frame: FrameLocator): Promise<string> {
try {
const sourceOrder = await frame.locator('.vsourcebillcode .code-detail-link').first().innerText()
const sourceOrder = await frame
.locator('.vsourcebillcode .code-detail-link')
.first()
.innerText()
const match = sourceOrder.match(/SC\d{14}/)
return match ? match[0] : sourceOrder.trim()
} catch {
@@ -650,7 +669,10 @@ export class CleanerService {
}
}
private async getInputValue(container: FrameLocator | Locator, labelRegex: RegExp): Promise<string> {
private async getInputValue(
container: FrameLocator | Locator,
labelRegex: RegExp
): Promise<string> {
try {
return await container
.locator('div')

View File

@@ -465,7 +465,9 @@ const CleanerPage: React.FC = () => {
<div className="border-t border-slate-100 pt-3 space-y-3">
<div>
<div className="text-sm font-medium text-slate-800"></div>
<div className="text-xs text-slate-500 mt-0.5"> 1-100</div>
<div className="text-xs text-slate-500 mt-0.5">
1-100
</div>
<input
type="number"
min={1}

View File

@@ -140,11 +140,7 @@ describe('Cleaner Service (Unit)', () => {
describe('batch and concurrency helpers', () => {
it('should split orders into batches', () => {
const batches = createBatches(['A', 'B', 'C', 'D', 'E'], 2)
expect(batches).toEqual([
['A', 'B'],
['C', 'D'],
['E']
])
expect(batches).toEqual([['A', 'B'], ['C', 'D'], ['E']])
})
it('should identify missing orders', () => {