7 changed files with 151 additions and 11 deletions
@ -0,0 +1,71 @@ |
|||||
|
// 问题工单字段缓存工具
|
||||
|
const CACHE_KEY = 'issue_form_cache'; |
||||
|
|
||||
|
export interface IssueFormCache { |
||||
|
contacts?: string; |
||||
|
contactsMobile?: string; |
||||
|
contactsEmail?: string; |
||||
|
customer?: string; |
||||
|
productId?: number; |
||||
|
versionId?: number; |
||||
|
appVersion?: string; |
||||
|
agent?: string; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存问题工单表单字段到localStorage |
||||
|
*/ |
||||
|
export const saveIssueFormCache = (formData: Partial<IssueFormCache>) => { |
||||
|
try { |
||||
|
const cacheData: IssueFormCache = {}; |
||||
|
|
||||
|
// 只缓存指定的字段
|
||||
|
const fieldsToCache = [ |
||||
|
'contacts', |
||||
|
'contactsMobile', |
||||
|
'contactsEmail', |
||||
|
'customer', |
||||
|
'productId', |
||||
|
'versionId', |
||||
|
'appVersion', |
||||
|
'agent' |
||||
|
] as const; |
||||
|
|
||||
|
fieldsToCache.forEach(field => { |
||||
|
const value = formData[field]; |
||||
|
if (value !== undefined) { |
||||
|
(cacheData as any)[field] = value; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
localStorage.setItem(CACHE_KEY, JSON.stringify(cacheData)); |
||||
|
} catch (error) { |
||||
|
console.error('保存表单缓存失败:', error); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* 从localStorage获取问题工单表单字段缓存 |
||||
|
*/ |
||||
|
export const getIssueFormCache = (): IssueFormCache => { |
||||
|
try { |
||||
|
const cacheStr = localStorage.getItem(CACHE_KEY); |
||||
|
if (cacheStr) { |
||||
|
return JSON.parse(cacheStr); |
||||
|
} |
||||
|
} catch (error) { |
||||
|
console.error('获取表单缓存失败:', error); |
||||
|
} |
||||
|
return {}; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* 清除问题工单表单字段缓存 |
||||
|
*/ |
||||
|
export const clearIssueFormCache = () => { |
||||
|
try { |
||||
|
localStorage.removeItem(CACHE_KEY); |
||||
|
} catch (error) { |
||||
|
console.error('清除表单缓存失败:', error); |
||||
|
} |
||||
|
}; |
||||
Loading…
Reference in new issue