♻️ 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 *.js text eol=lf
*.json text eol=lf *.json text eol=lf
*.yml text eol=lf *.yml text eol=lf
*.yaml text eol=lf
*.tsx text eol=lf *.tsx text eol=lf
*.jsx text eol=lf *.jsx text eol=lf
*.css text eol=lf *.css text eol=lf

View File

@@ -62,7 +62,12 @@ export interface ShouldDeleteParams {
deleteSet: Set<string> 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)) { if (!Number.isFinite(value)) {
return fallback return fallback
} }
@@ -281,7 +286,9 @@ export class CleanerService {
const retryResult = await this.retryFailedOrders({ const retryResult = await this.retryFailedOrders({
workFrame, workFrame,
popupPage, 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, deleteSet,
dryRun, dryRun,
onProgress: input.onProgress onProgress: input.onProgress
@@ -482,7 +489,12 @@ export class CleanerService {
onProgress?.( onProgress?.(
`开始处理订单: ${orderNumber}`, `开始处理订单: ${orderNumber}`,
this.calculateProgress(progressState.completedOrders, 0, detailCount, progressState.totalOrders), this.calculateProgress(
progressState.completedOrders,
0,
detailCount,
progressState.totalOrders
),
{ {
currentOrderIndex: progressState.completedOrders + 1, currentOrderIndex: progressState.completedOrders + 1,
totalOrders: progressState.totalOrders, totalOrders: progressState.totalOrders,
@@ -530,13 +542,17 @@ export class CleanerService {
progressState.totalOrders progressState.totalOrders
) )
onProgress?.(`订单 ${orderNumber} - 物料 ${materialIdx}/${detailCount}: ${materialName}`, progress, { onProgress?.(
currentOrderIndex: progressState.completedOrders + 1, `订单 ${orderNumber} - 物料 ${materialIdx}/${detailCount}: ${materialName}`,
totalOrders: progressState.totalOrders, progress,
currentMaterialIndex: materialIdx, {
totalMaterialsInOrder: detailCount, currentOrderIndex: progressState.completedOrders + 1,
currentOrderNumber: orderNumber totalOrders: progressState.totalOrders,
}) currentMaterialIndex: materialIdx,
totalMaterialsInOrder: detailCount,
currentOrderNumber: orderNumber
}
)
if (deleteSet.has(materialCode)) { if (deleteSet.has(materialCode)) {
const shouldDelete = this.shouldDeleteMaterial({ const shouldDelete = this.shouldDeleteMaterial({
@@ -610,7 +626,10 @@ export class CleanerService {
private async extractSourceOrderNumber(frame: FrameLocator): Promise<string> { private async extractSourceOrderNumber(frame: FrameLocator): Promise<string> {
try { 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}/) const match = sourceOrder.match(/SC\d{14}/)
return match ? match[0] : sourceOrder.trim() return match ? match[0] : sourceOrder.trim()
} catch { } 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 { try {
return await container return await container
.locator('div') .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 className="border-t border-slate-100 pt-3 space-y-3">
<div> <div>
<div className="text-sm font-medium text-slate-800"></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 <input
type="number" type="number"
min={1} min={1}

View File

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