feat: 🚀 优化

This commit is contained in:
2025-10-17 09:56:05 +08:00
parent 8a064cf1b9
commit 7efeb8faf0
4 changed files with 90 additions and 60 deletions

View File

@@ -29,22 +29,6 @@ const router = createRouter({
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
* */
@@ -54,8 +38,8 @@ router.beforeEach(async (to, from, next) => {
// 1.NProgress 开始
NProgress.start();
let redirect_path = getUrlParam("redirect_path");
const currentPath = window.location.pathname;
console.log(currentPath, "=currentPath=");
// 2.动态设置标题
const title = import.meta.env.VITE_GLOB_APP_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();
// 如果没有token但是有订阅路由就将订阅路由当参数携带
if (!userStore.newUserToken && redirect_path) {
if (!userStore.newUserToken && currentPath === "/foundation/subscribe/warehousing/index") {
return next({
path: LOGIN_URL,
replace: true,
query: { redirect_path: redirect_path } // 通过query传递参数
query: { redirect_path: currentPath } // 通过query传递参数
});
}

View File

@@ -77,6 +77,8 @@ const getSubscribeAdd = async (params: any) => {
const result = await getSubscribeAddApi(params);
if (result?.code === 0) {
useMsg("success", "新增成功 ");
dataStore.ruleForm = cloneDeep(RULE_FORM);
init();
setTimeout(() => {
$router.replace({ path: "/foundation/subscribe/list/index" });
}, 300);

View File

@@ -6,51 +6,51 @@
<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 { useUserStore } from "@/stores/modules/user";
const userStore = useUserStore();
// import { useUserStore } from "@/stores/modules/user";
// const userStore = useUserStore();
//路由;
const $route = useRoute();
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);
}
}
};
getOrgs();
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);
}
}
};
getWarehousesList();
// //获取组织
// 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);
// }
// }
// };
// getOrgs();
// 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);
// }
// }
// };
// getWarehousesList();
const init = () => {
let redirect_path: any = $route.query.redirect_path;

View File

@@ -4,6 +4,7 @@
<script setup lang="ts">
//useRouter
import { useRoute, useRouter } from "vue-router";
import { getOrgsApi, getWarehousesListApi } from "@/api/modules/global";
// import { useMsg } from "@/hooks/useMsg";
//重定向
import { usePathUrl } from "@/hooks/usePathUrl";
@@ -18,6 +19,43 @@ const userStore = useUserStore();
const $route = useRoute();
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 result: Record<string, any> = await loginApi(code);
@@ -25,7 +63,13 @@ const loginHttp = async (code: any) => {
userStore.setToken(result?.data?.access_token);
// 设置用户信息
userStore.setUserInfo(result?.data?.user_data);
let redirect_path: any = $route.query.redirect_path;
if (result?.data?.access_token) {
getWarehousesList();
getOrgs();
}
if (redirect_path) {
setTimeout(() => {
$router.replace({ path: redirect_path });