feat(pl): 吨千克克和升毫升按固定比例折算用证量。
同质量或体积单位不再要求手填系数,普通 http 页面也能生成幂等操作号。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e7f942b399
commit
da3ec62719
21 files changed
+277
-43
No files matched your search
@@ -78,6 +78,7 @@ export const DEFAULT_PRODUCT_UNIT_VALUE = 'dun'
|
||||
|
||||
/** 展示文案 → 字典值;避免「吨」与合同行 dun 混用导致保存校验失败 */
|
||||
const PRODUCT_UNIT_LABEL_TO_VALUE: Record<string, string> = {
|
||||
克: 'g',
|
||||
千克: 'kg',
|
||||
吨: 'dun',
|
||||
升: 'sheng',
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
type RandomSource = {
|
||||
randomUUID?: () => string
|
||||
getRandomValues?: (bytes: Uint8Array) => Uint8Array
|
||||
}
|
||||
|
||||
/** 幂等操作号。安全上下文用 randomUUID;http 页面没有该接口时改用 getRandomValues。 */
|
||||
export function randomOperationId(source?: RandomSource): string {
|
||||
const cryptoSource = source === undefined ? globalThis.crypto : source
|
||||
if (typeof cryptoSource?.randomUUID === 'function') return cryptoSource.randomUUID()
|
||||
const bytes = new Uint8Array(16)
|
||||
if (typeof cryptoSource?.getRandomValues === 'function') cryptoSource.getRandomValues(bytes)
|
||||
else {
|
||||
for (let i = 0; i < bytes.length; i += 1) bytes[i] = Math.floor(Math.random() * 256)
|
||||
}
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x40
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
||||
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')
|
||||
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
|
||||
}
|
||||
Reference in new issue
Block a user