hookehuyr

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

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