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:27:37 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4dcd56c289358bc1bcaa65abd31b8f7eacd395f0
4dcd56c2
1 parent
95d6fa2f
fix 只能在进入路由之前判断,不然很多组件数据不渲染
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
src/router.js
src/views/index.vue
src/router.js
View file @
4dcd56c
/*
* @Date: 2022-05-26 13:57:28
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-12-23 18:
00:57
* @LastEditTime: 2024-12-23 18:
26:41
* @FilePath: /data-table/src/router.js
* @Description: 文件描述
*/
...
...
@@ -51,8 +51,31 @@ 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'
)
{
// TAG: 只能在进入路由之前判断,不然很多组件数据不渲染
showConfirmDialog
({
title
:
'温馨提示'
,
message
:
'您还未完成的表单,是否继续?'
,
confirmButtonColor
:
styleColor
.
baseColor
,
cancelButtonText
:
'删除'
,
closeOnPopstate
:
false
,
})
.
then
(()
=>
{
// 通过后把数据绑定上去
next
();
})
.
catch
(()
=>
{
// 删除cookie
Cookies
.
remove
(
to
.
query
.
code
);
next
();
});
}
else
{
next
();
}
}
else
{
next
()
}
}
})
router
.
afterEach
(()
=>
{
...
...
src/views/index.vue
View file @
4dcd56c
<!--
* @Date: 2022-07-18 10:22:22
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-1
2-23 18:02:25
* @LastEditTime: 2024-1
1-27 16:23:08
* @FilePath: /data-table/src/views/index.vue
* @Description: 首页
-->
...
...
@@ -514,15 +514,7 @@ onMounted(async () => {
// TAG:不同类型提交表单处理
if (page_type === 'add' || page_type === undefined) { // 表单为新增状态, 检查是否有未完成的表单信息
const existingCookie = Cookies.get($route.query.code);
if (existingCookie && !force_back) {
showConfirmDialog({
title: '温馨提示',
message: '您还未完成的表单,是否继续?',
confirmButtonColor: styleColor.baseColor,
cancelButtonText: '删除',
closeOnPopstate: false,
})
.then(() => { // 通过后把数据绑定上去
if (existingCookie) {
// 如果Cookie存在,更新它
let object = JSON.parse(existingCookie);
// 默认值
...
...
@@ -534,10 +526,6 @@ onMounted(async () => {
item.component_props.default = value;
}
});
})
.catch(() => { // 删除cookie
Cookies.remove($route.query.code);
});
}
}
if (page_type === 'add' && !force_back) { // 表单为新增状态, 非后台打开状态
...
...
Please
register
or
login
to post a comment