Blame view

泰额版/Food Labeling Management App UniApp/src/utils/weightElement.ts 674 Bytes
5a192b24   杨鑫   最新同步
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  export type WeightInputMode = 'net' | 'tare'
  
  export function readWeightInputMode(cfg: Record<string, unknown> | undefined | null): WeightInputMode {
    const v = String(cfg?.weightInputMode ?? cfg?.WeightInputMode ?? 'net')
      .trim()
      .toLowerCase()
    return v === 'tare' ? 'tare' : 'net'
  }
  
  export function formatWeightDisplay(rawValue: string, unit: string): string {
    const raw = String(rawValue ?? '').trim()
    const u = String(unit ?? '').trim()
    if (!raw) return ''
    if (u && !raw.endsWith(u)) return `${raw}${u}`
    return raw
  }
  
  export function weightInputPlaceholder(mode: WeightInputMode): string {
    return mode === 'tare' ? 'Tare weight' : 'Net weight'
  }