hookehuyr

feat(表单): 添加未完成表单数据到cookie的功能

在RadioField组件中添加对未完成表单数据的cookie存储支持
当表单失去焦点时,将当前值保存到cookie中以便恢复
......@@ -149,6 +149,20 @@ const onBlur = (item) => {
// 发送自定义数据结构
props.item.value = { key: props.item.key, value: radio_value.value, affix: affix_value.value, type: "radio" };
emit("active", props.item.value);
// 适配cookie保存未完成表单
const currentValue = affix_value.value ? affix_value.value : radio_value.value;
const existingCookie = Cookies.get($route.query.code);
if (existingCookie) {
// 如果Cookie存在,更新它
let obj = JSON.parse(existingCookie);
obj[props.item.key] = currentValue; // 替换掉旧值
Cookies.set($route.query.code, JSON.stringify(obj), { expires: 1 });
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }), { expires: 1 });
}
}
const clearAffix = () => {
const options = props.item.component_props.options;
......