6 changed files with 158 additions and 10 deletions
@ -0,0 +1,46 @@
|
||||
// 记忆“上次选择的单位和人员”——按 用户ID + 节点 分桶
|
||||
export type WfNode = |
||||
| 'initial' | 'review' | 'first' | 'second' | 'third' |
||||
| 'original' | 'audit' | 'end' | string; |
||||
|
||||
const LS_KEY = 'wf_last_choice_v1'; |
||||
|
||||
function keyOf(userId: string | number, node: WfNode) { |
||||
return `${userId ?? ''}__${node ?? ''}`; |
||||
} |
||||
|
||||
function loadAll(): Record<string, any> { |
||||
try { |
||||
return JSON.parse(localStorage.getItem(LS_KEY) || '{}'); |
||||
} catch { |
||||
return {}; |
||||
} |
||||
} |
||||
|
||||
function saveAll(map: Record<string, any>) { |
||||
localStorage.setItem(LS_KEY, JSON.stringify(map)); |
||||
} |
||||
|
||||
export function saveLastChoice( |
||||
userId: string | number, |
||||
node: WfNode, |
||||
payload: { |
||||
approverUnitId?: string | number; |
||||
approverUnit?: string; |
||||
approverId?: string | number; |
||||
approver?: string; |
||||
} |
||||
) { |
||||
const map = loadAll(); |
||||
map[keyOf(userId, node)] = { ...payload, updatedAt: Date.now() }; |
||||
saveAll(map); |
||||
} |
||||
|
||||
export function loadLastChoice(userId: string | number, node: WfNode) { |
||||
const map = loadAll(); |
||||
return map[keyOf(userId, node)]; |
||||
} |
||||
|
||||
export function clearAllLastChoice() { |
||||
localStorage.removeItem(LS_KEY); |
||||
} |
||||
Loading…
Reference in new issue