hookehuyr

✨ feat: 删除存在cookie, 未完成的表单功能

<!--
* @Date: 2022-07-18 10:22:22
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-11-21 12:15:57
* @LastEditTime: 2024-11-21 13:02:15
* @FilePath: /data-table/src/views/index.vue
* @Description: 首页
-->
......@@ -512,21 +512,21 @@ onMounted(async () => {
}
// TAG:不同类型提交表单处理
if (page_type === 'add' && model === 'edit') { // 表单为新增状态, 检查是否有未完成的表单信息
if (page_type === 'add') { // 表单为新增状态, 检查是否有未完成的表单信息
const existingCookie = Cookies.get($route.query.code);
if (existingCookie) {
// 如果Cookie存在,更新它
let object = JSON.parse(existingCookie);
// 默认值
const objectMap = new Map(Object.entries(object)); // 将 object 转换为 Map,Object.entries() 方法用于返回一个给定对象自身可枚举属性的键值对数组,数组中的每个元素是一个包含键值对的数组,[ ["name", "Alice"], ["age", 30], ["city", "New York"] ]
formData.value.forEach((item) => {
if (objectMap.has(item.key)) {
// 适配双重json字符串问题,比如地址
const value = isJSON(objectMap.get((item.key))) ? JSON.parse(objectMap.get((item.key))) : objectMap.get((item.key));
item.component_props.default = value;
}
});
}
// 如果Cookie存在,更新它
let object = JSON.parse(existingCookie);
// 默认值
const objectMap = new Map(Object.entries(object)); // 将 object 转换为 Map,Object.entries() 方法用于返回一个给定对象自身可枚举属性的键值对数组,数组中的每个元素是一个包含键值对的数组,[ ["name", "Alice"], ["age", 30], ["city", "New York"] ]
formData.value.forEach((item) => {
if (objectMap.has(item.key)) {
// 适配双重json字符串问题,比如地址
const value = isJSON(objectMap.get((item.key))) ? JSON.parse(objectMap.get((item.key))) : objectMap.get((item.key));
item.component_props.default = value;
}
});
}
}
if (page_type === 'add' && !force_back) { // 表单为新增状态, 非后台打开状态
// 过期时间显示
......@@ -973,6 +973,8 @@ const successHandle = () => { // 表单成功提交后续操作
},
});
}
// 删除存在cookie, 未完成的表单功能
Cookies.remove($route.query.code);
}
const onSubmit = async (values) => { // 表单提交回调
......