Showing
2 changed files
with
38 additions
and
27 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,7 +51,30 @@ router.beforeEach((to, from, next) => { | ... | @@ -51,7 +51,30 @@ 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 | - next() | 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 { | ||
| 76 | + next() | ||
| 77 | + } | ||
| 55 | } | 78 | } |
| 56 | }) | 79 | }) |
| 57 | 80 | ... | ... |
| 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,30 +514,18 @@ onMounted(async () => { | ... | @@ -514,30 +514,18 @@ 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({ | 518 | + // 如果Cookie存在,更新它 |
| 519 | - title: '温馨提示', | 519 | + let object = JSON.parse(existingCookie); |
| 520 | - message: '您还未完成的表单,是否继续?', | 520 | + // 默认值 |
| 521 | - confirmButtonColor: styleColor.baseColor, | 521 | + const objectMap = new Map(Object.entries(object)); // 将 object 转换为 Map,Object.entries() 方法用于返回一个给定对象自身可枚举属性的键值对数组,数组中的每个元素是一个包含键值对的数组,[ ["name", "Alice"], ["age", 30], ["city", "New York"] ] |
| 522 | - cancelButtonText: '删除', | 522 | + formData.value.forEach((item) => { |
| 523 | - closeOnPopstate: false, | 523 | + if (objectMap.has(item.key)) { |
| 524 | - }) | 524 | + // 适配双重json字符串问题,比如地址 |
| 525 | - .then(() => { // 通过后把数据绑定上去 | 525 | + const value = isJSON(objectMap.get((item.key))) ? JSON.parse(objectMap.get((item.key))) : objectMap.get((item.key)); |
| 526 | - // 如果Cookie存在,更新它 | 526 | + item.component_props.default = value; |
| 527 | - let object = JSON.parse(existingCookie); | 527 | + } |
| 528 | - // 默认值 | 528 | + }); |
| 529 | - const objectMap = new Map(Object.entries(object)); // 将 object 转换为 Map,Object.entries() 方法用于返回一个给定对象自身可枚举属性的键值对数组,数组中的每个元素是一个包含键值对的数组,[ ["name", "Alice"], ["age", 30], ["city", "New York"] ] | ||
| 530 | - formData.value.forEach((item) => { | ||
| 531 | - if (objectMap.has(item.key)) { | ||
| 532 | - // 适配双重json字符串问题,比如地址 | ||
| 533 | - const value = isJSON(objectMap.get((item.key))) ? JSON.parse(objectMap.get((item.key))) : objectMap.get((item.key)); | ||
| 534 | - item.component_props.default = value; | ||
| 535 | - } | ||
| 536 | - }); | ||
| 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