feat: 🚀 优化
This commit is contained in:
@@ -29,22 +29,6 @@ const router = createRouter({
|
|||||||
scrollBehavior: () => ({ left: 0, top: 0 })
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
||||||
});
|
});
|
||||||
|
|
||||||
// 1. 定义获取URL参数的函数
|
|
||||||
function getUrlParam(paramName: any) {
|
|
||||||
// 获取当前页面URL的查询参数部分(如 "?redirect_path=xxx&t=xxx")
|
|
||||||
const searchStr = window.location.search.slice(1);
|
|
||||||
// 将参数按 "&" 分割成数组(如 ["redirect_path=xxx", "t=xxx"])
|
|
||||||
const paramArr = searchStr.split("&");
|
|
||||||
// 遍历数组匹配目标参数
|
|
||||||
for (let item of paramArr) {
|
|
||||||
const [key, value] = item.split("=");
|
|
||||||
if (key === paramName) {
|
|
||||||
return decodeURIComponent(value); // 解码特殊字符,确保内容准确
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null; // 未找到参数时返回null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 路由拦截 beforeEach
|
* @description 路由拦截 beforeEach
|
||||||
* */
|
* */
|
||||||
@@ -54,8 +38,8 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
|
|
||||||
// 1.NProgress 开始
|
// 1.NProgress 开始
|
||||||
NProgress.start();
|
NProgress.start();
|
||||||
let redirect_path = getUrlParam("redirect_path");
|
const currentPath = window.location.pathname;
|
||||||
|
console.log(currentPath, "=currentPath=");
|
||||||
// 2.动态设置标题
|
// 2.动态设置标题
|
||||||
const title = import.meta.env.VITE_GLOB_APP_TITLE;
|
const title = import.meta.env.VITE_GLOB_APP_TITLE;
|
||||||
document.title = to.meta.title ? `${to.meta.title} - ${title}` : title;
|
document.title = to.meta.title ? `${to.meta.title} - ${title}` : title;
|
||||||
@@ -72,11 +56,11 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
if (ROUTER_WHITE_LIST.includes(to.path)) return next();
|
if (ROUTER_WHITE_LIST.includes(to.path)) return next();
|
||||||
|
|
||||||
// 如果没有token但是有订阅路由就将订阅路由当参数携带
|
// 如果没有token但是有订阅路由就将订阅路由当参数携带
|
||||||
if (!userStore.newUserToken && redirect_path) {
|
if (!userStore.newUserToken && currentPath === "/foundation/subscribe/warehousing/index") {
|
||||||
return next({
|
return next({
|
||||||
path: LOGIN_URL,
|
path: LOGIN_URL,
|
||||||
replace: true,
|
replace: true,
|
||||||
query: { redirect_path: redirect_path } // 通过query传递参数
|
query: { redirect_path: currentPath } // 通过query传递参数
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ const getSubscribeAdd = async (params: any) => {
|
|||||||
const result = await getSubscribeAddApi(params);
|
const result = await getSubscribeAddApi(params);
|
||||||
if (result?.code === 0) {
|
if (result?.code === 0) {
|
||||||
useMsg("success", "新增成功 !");
|
useMsg("success", "新增成功 !");
|
||||||
|
dataStore.ruleForm = cloneDeep(RULE_FORM);
|
||||||
|
init();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$router.replace({ path: "/foundation/subscribe/list/index" });
|
$router.replace({ path: "/foundation/subscribe/list/index" });
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|||||||
@@ -6,51 +6,51 @@
|
|||||||
|
|
||||||
<script setup lang="ts" name="home">
|
<script setup lang="ts" name="home">
|
||||||
//登录请求接口
|
//登录请求接口
|
||||||
import { getOrgsApi, getWarehousesListApi } from "@/api/modules/global";
|
// import { getOrgsApi, getWarehousesListApi } from "@/api/modules/global";
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
//用户信息存储
|
//用户信息存储
|
||||||
import { useUserStore } from "@/stores/modules/user";
|
// import { useUserStore } from "@/stores/modules/user";
|
||||||
const userStore = useUserStore();
|
// const userStore = useUserStore();
|
||||||
//路由;
|
//路由;
|
||||||
const $route = useRoute();
|
const $route = useRoute();
|
||||||
const $router = useRouter();
|
const $router = useRouter();
|
||||||
//获取组织
|
// //获取组织
|
||||||
const getOrgs = async () => {
|
// const getOrgs = async () => {
|
||||||
const result = await getOrgsApi();
|
// const result = await getOrgsApi();
|
||||||
if (result?.code === 0) {
|
// if (result?.code === 0) {
|
||||||
const { data } = result;
|
// const { data } = result;
|
||||||
if (data?.length) {
|
// if (data?.length) {
|
||||||
let options: any = [];
|
// let options: any = [];
|
||||||
data.forEach((item: any) => {
|
// data.forEach((item: any) => {
|
||||||
options.push({
|
// options.push({
|
||||||
id: item.id,
|
// id: item.id,
|
||||||
value: item.org_number,
|
// value: item.org_number,
|
||||||
label: item.org_name
|
// label: item.org_name
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
userStore.setOrgIdArr(options);
|
// userStore.setOrgIdArr(options);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
getOrgs();
|
// getOrgs();
|
||||||
const getWarehousesList = async () => {
|
// const getWarehousesList = async () => {
|
||||||
const result = await getWarehousesListApi();
|
// const result = await getWarehousesListApi();
|
||||||
if (result?.code === 0) {
|
// if (result?.code === 0) {
|
||||||
const { data } = result;
|
// const { data } = result;
|
||||||
if (data?.length) {
|
// if (data?.length) {
|
||||||
let options: any = [];
|
// let options: any = [];
|
||||||
data.forEach((item: any) => {
|
// data.forEach((item: any) => {
|
||||||
options.push({
|
// options.push({
|
||||||
id: item.id,
|
// id: item.id,
|
||||||
value: item.warehouse_name,
|
// value: item.warehouse_name,
|
||||||
label: item.warehouse_name
|
// label: item.warehouse_name
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
userStore.setWarehouse(options);
|
// userStore.setWarehouse(options);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
getWarehousesList();
|
// getWarehousesList();
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
let redirect_path: any = $route.query.redirect_path;
|
let redirect_path: any = $route.query.redirect_path;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
//useRouter
|
//useRouter
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
|
import { getOrgsApi, getWarehousesListApi } from "@/api/modules/global";
|
||||||
// import { useMsg } from "@/hooks/useMsg";
|
// import { useMsg } from "@/hooks/useMsg";
|
||||||
//重定向
|
//重定向
|
||||||
import { usePathUrl } from "@/hooks/usePathUrl";
|
import { usePathUrl } from "@/hooks/usePathUrl";
|
||||||
@@ -18,6 +19,43 @@ const userStore = useUserStore();
|
|||||||
const $route = useRoute();
|
const $route = useRoute();
|
||||||
const $router = useRouter();
|
const $router = useRouter();
|
||||||
|
|
||||||
|
//获取组织
|
||||||
|
const getOrgs = async () => {
|
||||||
|
const result = await getOrgsApi();
|
||||||
|
if (result?.code === 0) {
|
||||||
|
const { data } = result;
|
||||||
|
if (data?.length) {
|
||||||
|
let options: any = [];
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
options.push({
|
||||||
|
id: item.id,
|
||||||
|
value: item.org_number,
|
||||||
|
label: item.org_name
|
||||||
|
});
|
||||||
|
});
|
||||||
|
userStore.setOrgIdArr(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getWarehousesList = async () => {
|
||||||
|
const result = await getWarehousesListApi();
|
||||||
|
if (result?.code === 0) {
|
||||||
|
const { data } = result;
|
||||||
|
if (data?.length) {
|
||||||
|
let options: any = [];
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
options.push({
|
||||||
|
id: item.id,
|
||||||
|
value: item.warehouse_name,
|
||||||
|
label: item.warehouse_name
|
||||||
|
});
|
||||||
|
});
|
||||||
|
userStore.setWarehouse(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 登录
|
// 登录
|
||||||
const loginHttp = async (code: any) => {
|
const loginHttp = async (code: any) => {
|
||||||
const result: Record<string, any> = await loginApi(code);
|
const result: Record<string, any> = await loginApi(code);
|
||||||
@@ -25,7 +63,13 @@ const loginHttp = async (code: any) => {
|
|||||||
userStore.setToken(result?.data?.access_token);
|
userStore.setToken(result?.data?.access_token);
|
||||||
// 设置用户信息
|
// 设置用户信息
|
||||||
userStore.setUserInfo(result?.data?.user_data);
|
userStore.setUserInfo(result?.data?.user_data);
|
||||||
|
|
||||||
let redirect_path: any = $route.query.redirect_path;
|
let redirect_path: any = $route.query.redirect_path;
|
||||||
|
|
||||||
|
if (result?.data?.access_token) {
|
||||||
|
getWarehousesList();
|
||||||
|
getOrgs();
|
||||||
|
}
|
||||||
if (redirect_path) {
|
if (redirect_path) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$router.replace({ path: redirect_path });
|
$router.replace({ path: redirect_path });
|
||||||
|
|||||||
Reference in New Issue
Block a user