Commit e180bbe4 authored by 刘斌's avatar 刘斌

fix: 增加关闭缓存功能

parent 2f75ddd2
......@@ -601,7 +601,7 @@
<script setup lang="ts">
import axios from 'axios';
import type { UploaderFileListItem } from 'vant';
import { reactive, ref, watch, nextTick } from 'vue';
import { reactive, ref, watch, nextTick, onMounted, onBeforeUnmount } from 'vue';
interface FamilyMemberModel {
relation: string;
......@@ -934,6 +934,44 @@ watch(
},
);
const CACHE_KEY = 'HR_VIEW_FORM_CACHE';
function saveCache() {
if (!submitSuccess.value) {
try {
localStorage.setItem(CACHE_KEY, JSON.stringify(form));
} catch (e) {
console.error('Save cache failed', e);
}
}
}
function loadCache() {
try {
const cached = localStorage.getItem(CACHE_KEY);
if (cached) {
const data = JSON.parse(cached);
Object.assign(form, data);
// Restore tid from URL if present, ensuring it takes precedence over cache
if (_tid) {
form.tid = _tid;
}
}
} catch (e) {
console.error('Load cache failed', e);
}
}
onMounted(() => {
loadCache();
window.addEventListener('beforeunload', saveCache);
});
onBeforeUnmount(() => {
window.removeEventListener('beforeunload', saveCache);
saveCache();
});
async function onSubmit() {
if (submitSuccess.value) {
showToast('您已提交\n无需再次提交');
......@@ -1014,6 +1052,7 @@ async function onSubmit() {
if (status >= 200 && status < 300) {
if (responseData.success) {
submitSuccess.value = true;
localStorage.removeItem(CACHE_KEY);
showSuccessToast({ message: '提交成功', duration: 5000 });
} else {
showFailToast(responseData.errMessage || '提交失败');
......
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