consume-admin-policy.js
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function parseDays(data, key, legacyKey) {
let value = parseInt(data[key], 10)
if (isNaN(value) && legacyKey) {
value = parseInt(data[legacyKey], 10)
}
if (isNaN(value)) return 0
return value
}
/**
* 解析管理后台耗卡作废/删除允许天数(兼容旧版合并配置项)
*/
export function parseConsumeAdminPolicy(data = {}) {
return {
voidDays: parseDays(data, 'adminConsumeVoidEditableDays', 'adminConsumeCancelEditableDays'),
deleteDays: parseDays(data, 'adminConsumeDeleteEditableDays', 'adminConsumeCancelEditableDays')
}
}
export function canConsumeAdminOperationByDays(row, days) {
if (!row) return false
if (days === 0) return true
const baseTime = row.hksj ? new Date(row.hksj) : null
if (!baseTime || isNaN(baseTime.getTime())) return true
const elapsedDays = (Date.now() - baseTime.getTime()) / 86400000
return elapsedDays <= days
}
/**
* 规范化业务配置表单字段(保存前/加载后)
*/
export function normalizeBusinessConfigFields(form) {
const next = { ...form }
const intField = (key, defaultValue) => {
if (next[key] === '' || next[key] == null) {
next[key] = defaultValue
return
}
const n = parseInt(next[key], 10)
next[key] = isNaN(n) ? defaultValue : n
}
intField('consumeEditableDays', 3)
intField('adminConsumeVoidEditableDays', 0)
intField('adminConsumeDeleteEditableDays', 0)
return next
}