Commit 24a983d0 authored by 刘斌's avatar 刘斌

fix: 增加关闭未提交时的暂存功能

parent e180bbe4
...@@ -939,7 +939,60 @@ const CACHE_KEY = 'HR_VIEW_FORM_CACHE'; ...@@ -939,7 +939,60 @@ const CACHE_KEY = 'HR_VIEW_FORM_CACHE';
function saveCache() { function saveCache() {
if (!submitSuccess.value) { if (!submitSuccess.value) {
try { try {
localStorage.setItem(CACHE_KEY, JSON.stringify(form)); const photoList =
Array.isArray(form.photoList)
? form.photoList.map((x: any) => ({ url: x?.url, name: x?.name }))
: [];
const data = {
name: form.name,
phoneNumber: form.phoneNumber,
gender: form.gender,
genderText: form.genderText,
photoList,
ossId: form.ossId,
idCardNumber: form.idCardNumber,
birthDate: form.birthDate,
age: form.age,
homeAddress: form.homeAddress,
ethnicity: form.ethnicity,
nativePlace: form.nativePlace,
maritalStatus: form.maritalStatus,
maritalText: form.maritalText,
politicalStatus: form.politicalStatus,
politicalText: form.politicalText,
emergencyContact: form.emergencyContact,
emergencyContactPhone: form.emergencyContactPhone,
householdRegistrationAddress: form.householdRegistrationAddress,
workStartDisplay: form.workStartDisplay,
professionalTitle: form.professionalTitle,
certificateStatus: form.certificateStatus,
fulltimeEducation: form.fulltimeEducation,
fulltimeSchool: form.fulltimeSchool,
fulltimeMajor: form.fulltimeMajor,
fulltimeGraduationDate: form.fulltimeGraduationDate,
fulltimeDegree: form.fulltimeDegree,
nonFulltimeEducation: form.nonFulltimeEducation,
nonFulltimeSchool: form.nonFulltimeSchool,
nonFulltimeMajor: form.nonFulltimeMajor,
nonFulltimeGraduationDate: form.nonFulltimeGraduationDate,
nonFulltimeDegree: form.nonFulltimeDegree,
externalResumeItems: form.externalResumeItems.map((o) => ({
startDate: o.startDate,
endDate: o.endDate,
company: o.company,
position: o.position,
})),
familyMembers: form.familyMembers.map((o) => ({
relation: o.relation,
name: o.name,
birthDate: o.birthDate,
companyAndJob: o.companyAndJob,
contact: o.contact,
})),
familyEmergencyIndex: form.familyEmergencyIndex,
tid: form.tid,
};
localStorage.setItem(CACHE_KEY, JSON.stringify(data));
} catch (e) { } catch (e) {
console.error('Save cache failed', e); console.error('Save cache failed', e);
} }
...@@ -952,7 +1005,6 @@ function loadCache() { ...@@ -952,7 +1005,6 @@ function loadCache() {
if (cached) { if (cached) {
const data = JSON.parse(cached); const data = JSON.parse(cached);
Object.assign(form, data); Object.assign(form, data);
// Restore tid from URL if present, ensuring it takes precedence over cache
if (_tid) { if (_tid) {
form.tid = _tid; form.tid = _tid;
} }
...@@ -964,10 +1016,28 @@ function loadCache() { ...@@ -964,10 +1016,28 @@ function loadCache() {
onMounted(() => { onMounted(() => {
loadCache(); loadCache();
const onVisibilityChange = () => {
if (document.visibilityState === 'hidden') saveCache();
};
const onPageHide = () => {
saveCache();
};
(window as any).__onVisibilityChange__ = onVisibilityChange;
(window as any).__onPageHide__ = onPageHide;
document.addEventListener('visibilitychange', onVisibilityChange);
window.addEventListener('pagehide', onPageHide);
window.addEventListener('beforeunload', saveCache); window.addEventListener('beforeunload', saveCache);
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
const onVisibilityChange = (window as any).__onVisibilityChange__;
const onPageHide = (window as any).__onPageHide__;
if (onVisibilityChange) {
document.removeEventListener('visibilitychange', onVisibilityChange);
}
if (onPageHide) {
window.removeEventListener('pagehide', onPageHide);
}
window.removeEventListener('beforeunload', saveCache); window.removeEventListener('beforeunload', saveCache);
saveCache(); saveCache();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment