xiaodai2017 2 years ago
parent
commit
2b1b14a5ab

+ 4 - 3
.env.development

@@ -10,6 +10,7 @@ VITE_PROXY_DOMAIN = /api
 # 开发环境路由历史模式
 VITE_ROUTER_HISTORY = "hash"
 
-# 开发环境后端地址
-VITE_PROXY_DOMAIN_REAL = "http://cxinv.test241.wanyuhengtong.com"
-#"http://stockinv.test241.wanyuhengtong.com"
+# 开发环境后端用户地址
+VITE_PROXY_USER_REAL = "http://stockinv.test241.wanyuhengtong.com"
+# 开发环境后端业务地址
+VITE_PROXY_DOMAIN_REAL = "http://cxinv.test241.wanyuhengtong.com"

+ 4 - 2
.env.production

@@ -4,8 +4,10 @@ VITE_PUBLIC_PATH = /
 # 线上环境路由历史模式
 VITE_ROUTER_HISTORY = "hash"
 
-# 线上环境后端地址
-VITE_PROXY_DOMAIN_REAL = ""
+# 开发环境后端用户地址
+VITE_PROXY_USER_REAL = "http://stockinv.test241.wanyuhengtong.com"
+# 开发环境后端业务地址
+VITE_PROXY_DOMAIN_REAL = "http://cxinv.test241.wanyuhengtong.com"
 
 # 是否为打包后的文件提供传统浏览器兼容性支持 支持 true 不支持 false
 VITE_LEGACY = false

+ 4 - 2
.env.staging

@@ -7,8 +7,10 @@ VITE_PUBLIC_PATH = /
 # 线上环境路由历史模式
 VITE_ROUTER_HISTORY = "hash"
 
-# 线上环境后端地址
-VITE_PROXY_DOMAIN_REAL = ""
+# 开发环境后端用户地址
+VITE_PROXY_USER_REAL = "http://stockinv.test241.wanyuhengtong.com"
+# 开发环境后端业务地址
+VITE_PROXY_DOMAIN_REAL = "http://cxinv.test241.wanyuhengtong.com"
 
 # 是否为打包后的文件提供传统浏览器兼容性支持 支持 true 不支持 false
 VITE_LEGACY = false

+ 4 - 2
src/api/routes.ts

@@ -1,5 +1,7 @@
 import { http } from "../utils/http";
-
+import { loadEnv } from "@build/index";
+const { VITE_PROXY_DOMAIN_REAL } = loadEnv();
+const userAPi = VITE_PROXY_DOMAIN_REAL;
 export const getAsyncRoutes = (data: object) => {
-  return http.request("post", "/Admin/menu", { data });
+  return http.request("post", `${userAPi}/Admin/menu`, { data });
 };

+ 5 - 3
src/api/user.ts

@@ -1,5 +1,7 @@
 import { http } from "../utils/http";
-
+import { loadEnv } from "@build/index";
+const { VITE_PROXY_DOMAIN_REAL } = loadEnv();
+const userAPi = VITE_PROXY_DOMAIN_REAL;
 interface userType extends Promise<any> {
   svg?: string;
   code?: number;
@@ -13,11 +15,11 @@ export const getVerify = (): userType => {
 
 // 登录
 export const getLogin = (data: object) => {
-  return http.request("post", "/Api/login", { data });
+  return http.request("post", `${userAPi}/Api/login`, { data });
 };
 // 获取当前账号菜单数据
 export const getMenuList = (data: object) => {
-  return http.request("post", "/Admin/menu", { data });
+  return http.request("post", `${userAPi}/Admin/menu`, { data });
 };
 
 // 刷新token

+ 21 - 0
src/layout/components/navbar.vue

@@ -42,6 +42,27 @@ const { logout, onPanel, toggleSideBar, pureApp, username, avatarsStyle } =
         </span>
         <template #dropdown>
           <el-dropdown-menu class="logout">
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              我的信息
+            </el-dropdown-item>
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              更换手机号
+            </el-dropdown-item>
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              修改密码
+            </el-dropdown-item>
             <el-dropdown-item @click="logout">
               <IconifyIconOffline
                 icon="logout-circle-r-line"

+ 21 - 0
src/layout/components/sidebar/horizontal.vue

@@ -76,6 +76,27 @@ watch(
         </span>
         <template #dropdown>
           <el-dropdown-menu class="logout">
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              我的信息
+            </el-dropdown-item>
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              更换手机号
+            </el-dropdown-item>
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              修改密码
+            </el-dropdown-item>
             <el-dropdown-item @click="logout">
               <IconifyIconOffline
                 icon="logout-circle-r-line"

+ 21 - 0
src/layout/components/sidebar/mixNav.vue

@@ -130,6 +130,27 @@ watch(
         </span>
         <template #dropdown>
           <el-dropdown-menu class="logout">
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              我的信息
+            </el-dropdown-item>
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              更换手机号
+            </el-dropdown-item>
+            <el-dropdown-item @click="logout">
+              <IconifyIconOffline
+                icon="logout-circle-r-line"
+                style="margin: 5px"
+              />
+              修改密码
+            </el-dropdown-item>
             <el-dropdown-item @click="logout">
               <IconifyIconOffline
                 icon="logout-circle-r-line"

+ 73 - 64
src/router/index.ts

@@ -5,6 +5,7 @@ import { findIndex } from "lodash-unified";
 import type { StorageConfigs } from "/#/index";
 import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
 import { usePermissionStoreHook } from "/@/store/modules/permission";
+import { useNav } from "../layout/hooks/nav";
 import {
   Router,
   RouteMeta,
@@ -29,7 +30,8 @@ import {
   isUrl,
   storageSession
 } from "@pureadmin/utils";
-
+const { logout, onPanel, toggleSideBar, pureApp, username, avatarsStyle } =
+  useNav();
 import pptRouter from "./modules/ppt";
 import homeRouter from "./modules/home";
 import ableRouter from "./modules/able";
@@ -131,76 +133,83 @@ router.beforeEach((to: toRouteType, _from, next) => {
     } else {
       // 刷新
       if (usePermissionStoreHook().wholeMenus.length === 0)
-        initRouter().then((router: Router) => {
-          if (!useMultiTagsStoreHook().getMultiTagsCache) {
-            const handTag = (
-              path: string,
-              parentPath: string,
-              name: RouteRecordName,
-              meta: RouteMeta
-            ): void => {
-              useMultiTagsStoreHook().handleTags("push", {
-                path,
-                parentPath,
-                name,
-                meta
-              });
-            };
-            // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
-            if (to.meta?.refreshRedirect) {
-              const routes = router.options.routes;
-              const { refreshRedirect } = to.meta;
-              const { name, meta } = findRouteByPath(refreshRedirect, routes);
-              handTag(
-                refreshRedirect,
-                getParentPaths(refreshRedirect, routes)[1],
-                name,
-                meta
-              );
-              return router.push(refreshRedirect);
-            } else {
-              const { path } = to;
-              const index = findIndex(remainingRouter, v => {
-                return v.path == path;
-              });
-              const routes =
-                index === -1
-                  ? router.options.routes[0].children
-                  : router.options.routes;
-              const route = findRouteByPath(path, routes);
-              const routePartent = getParentPaths(path, routes);
-              // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对动态路由)
-              if (
-                path !== routes[0].path &&
-                route?.meta?.rank !== 0 &&
-                routePartent.length === 0
-              ) {
-                if (!route?.meta?.refreshRedirect) return;
-                const { name, meta } = findRouteByPath(
-                  route.meta.refreshRedirect,
-                  routes
-                );
+        initRouter()
+          .then((router: Router) => {
+            console.log(router);
+            if (!useMultiTagsStoreHook().getMultiTagsCache) {
+              const handTag = (
+                path: string,
+                parentPath: string,
+                name: RouteRecordName,
+                meta: RouteMeta
+              ): void => {
+                useMultiTagsStoreHook().handleTags("push", {
+                  path,
+                  parentPath,
+                  name,
+                  meta
+                });
+              };
+              // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
+              if (to.meta?.refreshRedirect) {
+                const routes = router.options.routes;
+                const { refreshRedirect } = to.meta;
+                const { name, meta } = findRouteByPath(refreshRedirect, routes);
                 handTag(
-                  route.meta?.refreshRedirect,
-                  getParentPaths(route.meta?.refreshRedirect, routes)[0],
+                  refreshRedirect,
+                  getParentPaths(refreshRedirect, routes)[1],
                   name,
                   meta
                 );
-                return router.push(route.meta?.refreshRedirect);
+                return router.push(refreshRedirect);
               } else {
-                handTag(
-                  route.path,
-                  routePartent[routePartent.length - 1],
-                  route.name,
-                  route.meta
-                );
-                return router.push(path);
+                const { path } = to;
+                const index = findIndex(remainingRouter, v => {
+                  return v.path == path;
+                });
+                const routes =
+                  index === -1
+                    ? router.options.routes[0].children
+                    : router.options.routes;
+                const route = findRouteByPath(path, routes);
+                const routePartent = getParentPaths(path, routes);
+                // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对动态路由)
+                if (
+                  path !== routes[0].path &&
+                  route?.meta?.rank !== 0 &&
+                  routePartent.length === 0
+                ) {
+                  if (!route?.meta?.refreshRedirect) return;
+                  const { name, meta } = findRouteByPath(
+                    route.meta.refreshRedirect,
+                    routes
+                  );
+                  handTag(
+                    route.meta?.refreshRedirect,
+                    getParentPaths(route.meta?.refreshRedirect, routes)[0],
+                    name,
+                    meta
+                  );
+                  return router.push(route.meta?.refreshRedirect);
+                } else {
+                  handTag(
+                    route.path,
+                    routePartent[routePartent.length - 1],
+                    route.name,
+                    route.meta
+                  );
+                  return router.push(path);
+                }
               }
             }
-          }
-          router.push(to.fullPath);
-        });
-      next();
+            router.push(to.fullPath);
+            next();
+          })
+          .catch(s => {
+            logout();
+            console.log(s);
+            // next({ path: "/login" });
+          });
     }
   } else {
     if (to.path !== "/login") {

+ 66 - 71
src/router/utils.ts

@@ -14,13 +14,8 @@ import { buildHierarchyTree } from "@pureadmin/utils";
 import { usePermissionStoreHook } from "/@/store/modules/permission";
 const Layout = () => import("/@/layout/index.vue");
 const IFrame = () => import("/@/layout/frameView.vue");
-import permissionRouter from "./modules/permissionRouter";
-import systemRouter from "./modules/systemRouter";
-import tabsRouter from "./modules/tabsRouter";
-import { reactive } from "vue";
-// const modules = import.meta.golb("@views/**/**.vue"); //使用golb ++
 // https://cn.vitejs.dev/guide/features.html#glob-import
-// const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
+const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
 
 // 动态路由
 import { getAsyncRoutes } from "/@/api/routes";
@@ -127,78 +122,78 @@ function setDifAuthority(authority, routes) {
 }
 // 初始化路由
 function initRouter() {
-  return new Promise(resolve => {
-    getAsyncRoutes({}).then(({ code, data, message }) => {
-      const arrag: Array<any> = [];
-      data.forEach((e, ei) => {
-        const eitem = {
-          path: `/${e.menu_route}`,
-          component: Layout,
-          redirect: `${e.menu_route}`,
-          meta: {
-            icon: `${e.menu_img}`,
-            title: `${e.menu_name}`
-          },
-          children: []
-        };
-        e.child.forEach((s, si) => {
-          const sitem = reactive({
-            path: `/${e.menu_route}/${s.menu_route}`,
-            // component: () => import(`/@/views/${s.menu_url}.vue`),
-            component: `/views/${s.menu_url}`,
-            //本地能使用,上生产直接GG
-            //()=>import(/* @vite-ignore */ `/@views/${itemRouter.component}`),
-            //使用modules
-            // modules[/* @vite-ignore */ `/@/views/${item.component}`],
+  return new Promise((resolve, reject) => {
+    getAsyncRoutes({}).then(({ code, data }) => {
+      if (code === 0) {
+        const arrag: Array<any> = [];
+        data.forEach(e => {
+          const eitem = {
+            path: `/${e.menu_route}`,
+            component: Layout,
+            redirect: `${e.menu_route}`,
             meta: {
-              icon: `${s.menu_img}`,
-              title: `${s.menu_name}`
+              icon: `${e.menu_img}`,
+              title: `${e.menu_name}`
+            },
+            children: []
+          };
+          e.child.forEach((s, si) => {
+            const sitem = {
+              path: `/${e.menu_route}/${s.menu_route}`,
+              component: `${s.menu_url}`,
+              //本地能使用,上生产直接GG
+              meta: {
+                icon: `${s.menu_img}`,
+                title: `${s.menu_name}`
+              }
+            };
+            console.log(sitem);
+            eitem.children.push(sitem);
+            if (si === 0) {
+              eitem.redirect += `/${s.menu_route}`;
             }
           });
-          console.log(sitem);
-          eitem.children.push(sitem);
-          if (si === 0) {
-            sitem.redirect += `/${s.menu_route}`;
-          }
+          console.log(eitem);
+          arrag.push(eitem);
         });
-        console.log(eitem);
-        arrag.push(eitem);
-      });
 
-      if (arrag.length === 0) {
-        usePermissionStoreHook().changeSetting(arrag);
-        resolve(code);
-      } else {
-        formatFlatteningRoutes(addAsyncRoutes(arrag)).map(
-          (v: RouteRecordRaw) => {
-            // 防止重复添加路由
-            if (
-              router.options.routes[0].children.findIndex(
-                value => value.path === v.path
-              ) !== -1
-            ) {
-              return;
-            } else {
-              // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
-              router.options.routes[0].children.push(v);
-              // 最终路由进行升序
-              ascending(router.options.routes[0].children);
-              if (!router.hasRoute(v?.name)) router.addRoute(v);
-              const flattenRouters = router
-                .getRoutes()
-                .find(n => n.path === "/");
-              router.addRoute(flattenRouters);
+        if (arrag.length === 0) {
+          usePermissionStoreHook().changeSetting(arrag);
+          resolve(code);
+        } else {
+          formatFlatteningRoutes(addAsyncRoutes(arrag)).map(
+            (v: RouteRecordRaw) => {
+              // 防止重复添加路由
+              if (
+                router.options.routes[0].children.findIndex(
+                  value => value.path === v.path
+                ) !== -1
+              ) {
+                return;
+              } else {
+                // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
+                router.options.routes[0].children.push(v);
+                // 最终路由进行升序
+                ascending(router.options.routes[0].children);
+                if (!router.hasRoute(v?.name)) router.addRoute(v);
+                const flattenRouters = router
+                  .getRoutes()
+                  .find(n => n.path === "/");
+                router.addRoute(flattenRouters);
+              }
+              resolve(router);
             }
-            resolve(router);
-          }
-        );
-        usePermissionStoreHook().changeSetting(arrag);
+          );
+          usePermissionStoreHook().changeSetting(arrag);
+        }
+        router.addRoute({
+          path: "/:pathMatch(.*)",
+          redirect: "/error/404"
+        });
+        resolve(router);
+      } else {
+        reject(false);
       }
-      router.addRoute({
-        path: "/:pathMatch(.*)",
-        redirect: "/error/404"
-      });
-      resolve(router);
     });
   });
 }

+ 0 - 35
src/store/modules/user.ts

@@ -5,7 +5,6 @@ import { router } from "/@/router";
 import { routerArrays } from "/@/layout/types";
 import { storageSession } from "@pureadmin/utils";
 import { getLogin, getMenuList, refreshToken } from "/@/api/user";
-import { initRouter } from "/@/router/utils";
 import {
   getToken,
   setToken,
@@ -70,40 +69,6 @@ export const useUserStore = defineStore({
           .then((res: resType) => {
             const { code, data } = res;
             if (code === 0) {
-              // let list = data;
-              // list = list.filter(item => item.child && item.child.length > 0);
-              // const arrag = [];
-              // const btnList = [];
-              // console.log(list);
-              // list.forEach(v1 => {
-              //   const pItem = {
-              //     name: v1.menu_route,
-              //     path: `/${v1.menu_route}`,
-              //     meta: {
-              //       title: v1.menu_name,
-              //       icon: v1.menu_img
-              //     },
-              //     children: []
-              //   };
-              //   v1.child.forEach(v2 => {
-              //     const item = {
-              //       path: v2.menu_route,
-              //       name: v2.menu_route,
-              //       meta: {
-              //         title: v2.menu_name,
-              //         icon: v2.menu_img
-              //       },
-              //       url: v2.menu_url
-              //     };
-              //     const model = {
-              //       menu_route: v2.menu_route,
-              //       action: v2.action
-              //     };
-              //     btnList.push(model);
-              //     pItem.children.push(item);
-              //   });
-              //   arrag.push(pItem);
-              // });
               const systemRouter = {
                 path: "/system",
                 redirect: "/system/menuOperator/index",

+ 7 - 5
src/utils/http/index.ts

@@ -9,7 +9,7 @@ import {
 import qs from "qs";
 import NProgress from "../progress";
 import { loadEnv } from "@build/index";
-import { getToken } from "/@/utils/auth";
+import { getToken, setToken } from "/@/utils/auth";
 import { useUserStoreHook } from "/@/store/modules/user";
 
 // 加载环境变量 VITE_PROXY_DOMAIN(开发环境)  VITE_PROXY_DOMAIN_REAL(打包后的线上环境)
@@ -18,7 +18,7 @@ console.log(VITE_PROXY_DOMAIN_REAL);
 
 // 相关配置请参考:www.axios-js.com/zh-cn/docs/#axios-request-config-1
 const defaultConfig: AxiosRequestConfig = {
-  baseURL: VITE_PROXY_DOMAIN_REAL,
+  baseURL: "",
   // 当前使用mock模拟请求,将baseURL制空,如果你的环境用到了http请求,请删除下面的baseURL启用上面的baseURL,并将11行、16行代码注释取消
   // baseURL: "",
   timeout: 10000,
@@ -47,6 +47,7 @@ class PureHttp {
     PureHttp.axiosInstance.interceptors.request.use(
       (config: PureHttpRequestConfig) => {
         const $config = config;
+        // console.log($config);
         // 开启进度条动画
         NProgress.start();
         // 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
@@ -59,9 +60,10 @@ class PureHttp {
           return $config;
         }
         const token = getToken();
-        console.log(token);
-        if (token) {
-          config.data.token = token;
+        // console.log(token);
+        if (token && config && config.data) {
+          // config.data.token = token;
+          config.data["token"] = token;
           // config.headers["Authorization"] = "Bearer " + data.accessToken;
           return $config;
         } else {

+ 12 - 20
src/views/login/index.vue

@@ -60,29 +60,21 @@ const onLogin = async (formEl: FormInstance | undefined) => {
       useUserStoreHook()
         .loginByUsername(ruleForm)
         .then((res: resType) => {
-          const { code, message: msg } = res;
+          const { code, message: msg, data } = res;
+          const { userinfo, token } = data;
+          const { nickname } = userinfo;
 
           if (code === 0) {
-            setTimeout(() => {
+            storageSession.setItem("info", {
+              username: nickname,
+              accessToken: token
+            });
+            initRouter().then(ress => {
               loading.value = false;
-              storageSession.setItem("info", {
-                username: "admin1",
-                accessToken: "eyJhbGciOiJIUzUxMiJ9.test"
-              });
-              initRouter("admin").then(ress => {
-                console.log(ress);
-                message.success("登录成功");
-                router.push("/");
-              });
-            }, 2000);
-            // loading.value = false;
-            // ElMessage.success("登录成功");
-            // router.push("/");
-            // // initRouter().then(co => {
-            // //   console.log(co);
-            // //   loading.value = false;
-            // //   ElMessage.success("登录成功");
-            // // });
+              console.log(ress);
+              message.success("登录成功");
+              router.push("/");
+            });
           } else if (code > 100 && code < 200) {
             loading.value = false;
           } else {