Showing
2 changed files
with
26 additions
and
15 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2022-05-26 13:57:28 | 2 | * @Date: 2022-05-26 13:57:28 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-12-23 18:00:57 | 4 | + * @LastEditTime: 2024-12-23 18:26:41 |
| 5 | * @FilePath: /data-table/src/router.js | 5 | * @FilePath: /data-table/src/router.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -51,8 +51,31 @@ router.beforeEach((to, from, next) => { | ... | @@ -51,8 +51,31 @@ router.beforeEach((to, from, next) => { |
| 51 | next({ ...to.redirectedFrom, replace: true }); | 51 | next({ ...to.redirectedFrom, replace: true }); |
| 52 | }, 1000); | 52 | }, 1000); |
| 53 | } else { | 53 | } else { |
| 54 | + if (to.query.page_type === 'add' || to.query.page_type === undefined) { // 表单为新增状态, 检查是否有未完成的表单信息 | ||
| 55 | + const existingCookie = Cookies.get(to.query.code); | ||
| 56 | + if (existingCookie && to.query.force_back !== '1') { | ||
| 57 | + // TAG: 只能在进入路由之前判断,不然很多组件数据不渲染 | ||
| 58 | + showConfirmDialog({ | ||
| 59 | + title: '温馨提示', | ||
| 60 | + message: '您还未完成的表单,是否继续?', | ||
| 61 | + confirmButtonColor: styleColor.baseColor, | ||
| 62 | + cancelButtonText: '删除', | ||
| 63 | + closeOnPopstate: false, | ||
| 64 | + }) | ||
| 65 | + .then(() => { // 通过后把数据绑定上去 | ||
| 66 | + next(); | ||
| 67 | + }) | ||
| 68 | + .catch(() => { // 删除cookie | ||
| 69 | + Cookies.remove(to.query.code); | ||
| 70 | + next(); | ||
| 71 | + }); | ||
| 72 | + } else { | ||
| 73 | + next(); | ||
| 74 | + } | ||
| 75 | + } else { | ||
| 54 | next() | 76 | next() |
| 55 | } | 77 | } |
| 78 | + } | ||
| 56 | }) | 79 | }) |
| 57 | 80 | ||
| 58 | router.afterEach(() => { | 81 | router.afterEach(() => { | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-07-18 10:22:22 | 2 | * @Date: 2022-07-18 10:22:22 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-12-23 18:02:25 | 4 | + * @LastEditTime: 2024-11-27 16:23:08 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -514,15 +514,7 @@ onMounted(async () => { | ... | @@ -514,15 +514,7 @@ onMounted(async () => { |
| 514 | // TAG:不同类型提交表单处理 | 514 | // TAG:不同类型提交表单处理 |
| 515 | if (page_type === 'add' || page_type === undefined) { // 表单为新增状态, 检查是否有未完成的表单信息 | 515 | if (page_type === 'add' || page_type === undefined) { // 表单为新增状态, 检查是否有未完成的表单信息 |
| 516 | const existingCookie = Cookies.get($route.query.code); | 516 | const existingCookie = Cookies.get($route.query.code); |
| 517 | - if (existingCookie && !force_back) { | 517 | + if (existingCookie) { |
| 518 | - showConfirmDialog({ | ||
| 519 | - title: '温馨提示', | ||
| 520 | - message: '您还未完成的表单,是否继续?', | ||
| 521 | - confirmButtonColor: styleColor.baseColor, | ||
| 522 | - cancelButtonText: '删除', | ||
| 523 | - closeOnPopstate: false, | ||
| 524 | - }) | ||
| 525 | - .then(() => { // 通过后把数据绑定上去 | ||
| 526 | // 如果Cookie存在,更新它 | 518 | // 如果Cookie存在,更新它 |
| 527 | let object = JSON.parse(existingCookie); | 519 | let object = JSON.parse(existingCookie); |
| 528 | // 默认值 | 520 | // 默认值 |
| ... | @@ -534,10 +526,6 @@ onMounted(async () => { | ... | @@ -534,10 +526,6 @@ onMounted(async () => { |
| 534 | item.component_props.default = value; | 526 | item.component_props.default = value; |
| 535 | } | 527 | } |
| 536 | }); | 528 | }); |
| 537 | - }) | ||
| 538 | - .catch(() => { // 删除cookie | ||
| 539 | - Cookies.remove($route.query.code); | ||
| 540 | - }); | ||
| 541 | } | 529 | } |
| 542 | } | 530 | } |
| 543 | if (page_type === 'add' && !force_back) { // 表单为新增状态, 非后台打开状态 | 531 | if (page_type === 'add' && !force_back) { // 表单为新增状态, 非后台打开状态 | ... | ... |
-
Please register or login to post a comment