Showing
2 changed files
with
26 additions
and
36 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-11-25 15:01:10 | 4 | + * @LastEditTime: 2024-12-23 18:00:57 |
| 5 | * @FilePath: /data-table/src/router.js | 5 | * @FilePath: /data-table/src/router.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -51,29 +51,7 @@ router.beforeEach((to, from, next) => { | ... | @@ -51,29 +51,7 @@ 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) { // 表单为新增状态, 检查是否有未完成的表单信息 | 54 | + next() |
| 55 | - const existingCookie = Cookies.get(to.query.code); | ||
| 56 | - if (existingCookie && to.query.force_back !== '1') { | ||
| 57 | - showConfirmDialog({ | ||
| 58 | - title: '温馨提示', | ||
| 59 | - message: '您还未完成的表单,是否继续?', | ||
| 60 | - confirmButtonColor: styleColor.baseColor, | ||
| 61 | - cancelButtonText: '删除', | ||
| 62 | - closeOnPopstate: false, | ||
| 63 | - }) | ||
| 64 | - .then(() => { // 通过后把数据绑定上去 | ||
| 65 | - next(); | ||
| 66 | - }) | ||
| 67 | - .catch(() => { // 删除cookie | ||
| 68 | - Cookies.remove(to.query.code); | ||
| 69 | - next(); | ||
| 70 | - }); | ||
| 71 | - } else { | ||
| 72 | - next(); | ||
| 73 | - } | ||
| 74 | - } else { | ||
| 75 | - next() | ||
| 76 | - } | ||
| 77 | } | 55 | } |
| 78 | }) | 56 | }) |
| 79 | 57 | ... | ... |
| ... | @@ -514,18 +514,30 @@ onMounted(async () => { | ... | @@ -514,18 +514,30 @@ 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) { | 517 | + if (existingCookie && !force_back) { |
| 518 | - // 如果Cookie存在,更新它 | 518 | + showConfirmDialog({ |
| 519 | - let object = JSON.parse(existingCookie); | 519 | + title: '温馨提示', |
| 520 | - // 默认值 | 520 | + message: '您还未完成的表单,是否继续?', |
| 521 | - const objectMap = new Map(Object.entries(object)); // 将 object 转换为 Map,Object.entries() 方法用于返回一个给定对象自身可枚举属性的键值对数组,数组中的每个元素是一个包含键值对的数组,[ ["name", "Alice"], ["age", 30], ["city", "New York"] ] | 521 | + confirmButtonColor: styleColor.baseColor, |
| 522 | - formData.value.forEach((item) => { | 522 | + cancelButtonText: '删除', |
| 523 | - if (objectMap.has(item.key)) { | 523 | + closeOnPopstate: false, |
| 524 | - // 适配双重json字符串问题,比如地址 | 524 | + }) |
| 525 | - const value = isJSON(objectMap.get((item.key))) ? JSON.parse(objectMap.get((item.key))) : objectMap.get((item.key)); | 525 | + .then(() => { // 通过后把数据绑定上去 |
| 526 | - item.component_props.default = value; | 526 | + // 如果Cookie存在,更新它 |
| 527 | - } | 527 | + let object = JSON.parse(existingCookie); |
| 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(to.query.code); | ||
| 540 | + }); | ||
| 529 | } | 541 | } |
| 530 | } | 542 | } |
| 531 | if (page_type === 'add' && !force_back) { // 表单为新增状态, 非后台打开状态 | 543 | if (page_type === 'add' && !force_back) { // 表单为新增状态, 非后台打开状态 | ... | ... |
-
Please register or login to post a comment