Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2024-12-23 18:01:47 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
80f4b8c4dec7779be13d2fc6a65797223430d59f
80f4b8c4
1 parent
7af23108
fix 检查是否有未完成的表单逻辑修改
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
36 deletions
src/router.js
src/views/index.vue
src/router.js
View file @
80f4b8c
/*
* @Date: 2022-05-26 13:57:28
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-1
1-25 15:01:10
* @LastEditTime: 2024-1
2-23 18:00:57
* @FilePath: /data-table/src/router.js
* @Description: 文件描述
*/
...
...
@@ -51,29 +51,7 @@ router.beforeEach((to, from, next) => {
next
({
...
to
.
redirectedFrom
,
replace
:
true
});
},
1000
);
}
else
{
if
(
to
.
query
.
page_type
===
'add'
||
to
.
query
.
page_type
===
undefined
)
{
// 表单为新增状态, 检查是否有未完成的表单信息
const
existingCookie
=
Cookies
.
get
(
to
.
query
.
code
);
if
(
existingCookie
&&
to
.
query
.
force_back
!==
'1'
)
{
showConfirmDialog
({
title
:
'温馨提示'
,
message
:
'您还未完成的表单,是否继续?'
,
confirmButtonColor
:
styleColor
.
baseColor
,
cancelButtonText
:
'删除'
,
closeOnPopstate
:
false
,
})
.
then
(()
=>
{
// 通过后把数据绑定上去
next
();
})
.
catch
(()
=>
{
// 删除cookie
Cookies
.
remove
(
to
.
query
.
code
);
next
();
});
}
else
{
next
();
}
}
else
{
next
()
}
next
()
}
})
...
...
src/views/index.vue
View file @
80f4b8c
...
...
@@ -514,18 +514,30 @@ onMounted(async () => {
// TAG:不同类型提交表单处理
if (page_type === 'add' || page_type === undefined) { // 表单为新增状态, 检查是否有未完成的表单信息
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;
}
});
if (existingCookie && !force_back) {
showConfirmDialog({
title: '温馨提示',
message: '您还未完成的表单,是否继续?',
confirmButtonColor: styleColor.baseColor,
cancelButtonText: '删除',
closeOnPopstate: false,
})
.then(() => { // 通过后把数据绑定上去
// 如果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;
}
});
})
.catch(() => { // 删除cookie
Cookies.remove(to.query.code);
});
}
}
if (page_type === 'add' && !force_back) { // 表单为新增状态, 非后台打开状态
...
...
Please
register
or
login
to post a comment