hookehuyr

✨ feat: 路由拦截有cookie的表单进行判断操作

/*
* @Date: 2022-05-26 13:57:28
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-29 21:36:59
* @FilePath: /tswj/src/router.js
* @LastEditTime: 2024-11-21 17:08:22
* @FilePath: /data-table/src/router.js
* @Description: 文件描述
*/
import { createRouter, createWebHashHistory } from 'vue-router';
import RootRoute from './route.js';
import asyncRoutesArr from "./mock/routes"
import generateRoutes from './utils/generateRoute'
import { showConfirmDialog } from "vant";
import Cookies from 'js-cookie';
import { styleColor } from "@/constant.js";
// TAG: 路由配置表
/**
......@@ -48,7 +51,26 @@ router.beforeEach((to, from, next) => {
next({ ...to.redirectedFrom, replace: true });
}, 1000);
} else {
next()
if (to.query.page_type === 'add') { // 表单为新增状态, 检查是否有未完成的表单信息
const existingCookie = Cookies.get(to.query.code);
if (existingCookie) {
showConfirmDialog({
title: '温馨提示',
message: '您还未完成的表单,是否继续?',
confirmButtonColor: styleColor.baseColor,
cancelButtonText: '删除'
})
.then(() => { // 通过后把数据绑定上去
next();
})
.catch(() => { // 删除cookie
Cookies.remove(to.query.code);
next();
});
}
} else {
next()
}
}
})
......