Browse Source

添加设置

xiaodai2017 2 years ago
parent
commit
27f6ef6c22

+ 67 - 0
src/components/NoAuth/NoAuth.vue

@@ -0,0 +1,67 @@
+<script setup lang="ts">
+import noAccess from "/@/assets/status/403.svg?component";
+
+defineOptions({
+  name: "NoAuth"
+});
+</script>
+
+<template>
+  <div class="flex justify-center items-center h-screen-sm">
+    <noAccess />
+    <div class="ml-12">
+      <p
+        class="font-medium text-4xl mb-4"
+        v-motion
+        :initial="{
+          opacity: 0,
+          y: 100
+        }"
+        :enter="{
+          opacity: 1,
+          y: 0,
+          transition: {
+            delay: 100
+          }
+        }"
+      >
+        403
+      </p>
+      <p
+        class="mb-4 text-gray-500"
+        v-motion
+        :initial="{
+          opacity: 0,
+          y: 100
+        }"
+        :enter="{
+          opacity: 1,
+          y: 0,
+          transition: {
+            delay: 300
+          }
+        }"
+      >
+        抱歉,你无权访问该页面
+      </p>
+      <el-button
+        type="primary"
+        @click="$router.push('/')"
+        v-motion
+        :initial="{
+          opacity: 0,
+          y: 100
+        }"
+        :enter="{
+          opacity: 1,
+          y: 0,
+          transition: {
+            delay: 500
+          }
+        }"
+      >
+        返回首页
+      </el-button>
+    </div>
+  </div>
+</template>

+ 3 - 0
src/components/NoAuth/index.ts

@@ -0,0 +1,3 @@
+import NoAuth from "./NoAuth.vue";
+
+export default NoAuth;

+ 4 - 2
src/main.ts

@@ -39,12 +39,14 @@ Object.keys(directives).forEach(key => {
 // 全局注册`@iconify/vue`图标库
 import {
   IconifyIconOffline,
-  IconifyIconOnline,
+  // IconifyIconOnline,
   FontIcon
 } from "./components/ReIcon";
+import NoAuth from "./components/NoAuth/index";
 app.component("IconifyIconOffline", IconifyIconOffline);
-app.component("IconifyIconOnline", IconifyIconOnline);
+// app.component("IconifyIconOnline", IconifyIconOnline);
 app.component("FontIcon", FontIcon);
+app.component("NoAuth", NoAuth);
 
 getServerConfig(app).then(async config => {
   app.use(router);

+ 76 - 81
src/router/utils.ts

@@ -14,12 +14,10 @@ import { buildHierarchyTree } from "@pureadmin/utils";
 import { usePermissionStoreHook } from "/@/store/modules/permission";
 const Layout = () => import("/@/layout/index.vue");
 const IFrame = () => import("/@/layout/frameView.vue");
+import { useUserStoreHook } from "/@/store/modules/user";
 // https://cn.vitejs.dev/guide/features.html#glob-import
 const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
 
-// 动态路由
-import { getAsyncRoutes } from "/@/api/user";
-
 // 按照路由中meta下的rank等级升序来排序路由
 function ascending(arr: any[]) {
   arr.forEach(v => {
@@ -121,90 +119,87 @@ function setDifAuthority(authority, routes) {
 // 初始化路由
 function initRouter() {
   return new Promise((resolve, reject) => {
-    getAsyncRoutes({}).then(({ code, data }) => {
-      if (code === 0) {
-        const arrag: Array<any> = [];
-        const actionList: Array<any> = [];
-        data.forEach(e => {
-          // const arr = e.menu_img.split("ep:");
-          const eitem = {
-            path: `/${e.menu_route}`,
-            component: Layout,
-            redirect: `${e.menu_route}`,
-            meta: {
-              // icon: arr.length === 2 ? arr[1] : "",
-              // icon: `${e.menu_img}`,
-              title: `${e.menu_name}`,
-              showLink: e.is_private + "" === "1"
-            },
-            children: []
-          };
+    useUserStoreHook()
+      .postMenuList({})
+      .then(({ code, data }) => {
+        if (code === 0) {
+          const arrag: Array<any> = [];
 
-          e.child.forEach((s, si) => {
-            // const arr2 = s.menu_img.split("ep:");
-            const sitem = {
-              path: `/${e.menu_route}/${s.menu_route}`,
-              component: `${s.menu_url}`,
-              //本地能使用,上生产直接GG
+          data.forEach(e => {
+            // const arr = e.menu_img.split("ep:");
+            const eitem = {
+              path: `/${e.menu_route}`,
+              component: Layout,
+              redirect: `${e.menu_route}`,
               meta: {
-                // icon: arr2.length === 2 ? arr2[1] : "",
-                showLink: s.is_private + "" === "1",
-                title: `${s.menu_name}`
-              }
+                // icon: arr.length === 2 ? arr[1] : "",
+                // icon: `${e.menu_img}`,
+                title: `${e.menu_name}`,
+                showLink: e.is_private + "" === "1"
+              },
+              children: []
             };
-            // console.log(sitem);
-            eitem.children.push(sitem);
-            if (si === 0) {
-              eitem.redirect += `/${s.menu_route}`;
-            }
-            const asitem = {
-              menu_route: s.menu_route,
-              action: s.action
-            };
-            actionList.push(asitem);
+
+            e.child.forEach((s, si) => {
+              // const arr2 = s.menu_img.split("ep:");
+              const sitem = {
+                path: `/${e.menu_route}/${s.menu_route}`,
+                component: `${s.menu_url}`,
+                //本地能使用,上生产直接GG
+                meta: {
+                  // icon: arr2.length === 2 ? arr2[1] : "",
+                  showLink: s.is_private + "" === "1",
+                  title: `${s.menu_name}`
+                }
+              };
+              // console.log(sitem);
+              eitem.children.push(sitem);
+              if (si === 0) {
+                eitem.redirect += `/${s.menu_route}`;
+              }
+            });
+            // console.log(eitem);
+            arrag.push(eitem);
           });
-          // console.log(eitem);
-          arrag.push(eitem);
-        });
-        // console.log(arrag);
-        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);
+          // console.log(arrag);
+          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);
-      } else {
-        reject(false);
-      }
-    });
+      });
   });
 }
 

+ 1 - 2
src/store/modules/types.ts

@@ -1,4 +1,3 @@
-import { message } from "@pureadmin/components";
 import { RouteRecordName } from "vue-router";
 
 export type cacheType = {
@@ -41,7 +40,7 @@ export type userType = {
   name?: string;
   verifyCode?: string;
   currentPage?: number;
-  userInfo?: object;
+  menuActions: string;
 };
 export type resType = {
   code: number;

+ 38 - 99
src/store/modules/user.ts

@@ -9,12 +9,13 @@ import {
   getToken,
   setToken,
   removeToken,
-  getUserInfo,
-  setUserInfo,
-  removeUserInfo
+  getAction,
+  setAction,
+  removeAction
 } from "/@/utils/auth";
+
 import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
-const userinfo = getUserInfo();
+
 export const useUserStore = defineStore({
   id: "pure-user",
   state: (): userType => ({
@@ -24,9 +25,24 @@ export const useUserStore = defineStore({
     verifyCode: "",
     // 登录显示组件判断 0:登录 1:手机登录 2:二维码登录 3:注册 4:忘记密码,默认0:登录
     currentPage: 0,
-    userInfo: userinfo || null,
-    actions: [] || []
+    menuActions: getAction()
   }),
+  getters: {
+    getMenuActions(code) {
+      console.log(code);
+      // console.log(this.menuActions);
+      if (this.menuActions && this.menuActions.length > 0) {
+        const arr = JSON.parse(this.menuActions);
+        console.log(arr);
+        const tran = arr.find(i => i.menu_route == code) || {};
+        console.log(tran);
+        const { action } = tran ?? {};
+        return action ?? [];
+      } else {
+        return [];
+      }
+    }
+  },
   actions: {
     SET_TOKEN(token) {
       this.token = token;
@@ -40,8 +56,8 @@ export const useUserStore = defineStore({
     SET_CURRENTPAGE(value) {
       this.currentPage = value;
     },
-    SET_USERINFO(value) {
-      this.userInfo = value;
+    SET_ACTIONS(value) {
+      this.actions = value;
     },
     // 登入
     async loginByUsername(form) {
@@ -50,9 +66,8 @@ export const useUserStore = defineStore({
           .then((res: resType) => {
             const { code, data } = res;
             if (code === 0) {
-              const { token, userinfo } = data;
+              const { token } = data;
               setToken(token);
-              setUserInfo(userinfo);
               resolve(res);
             } else {
               resolve(res);
@@ -63,6 +78,7 @@ export const useUserStore = defineStore({
           });
       });
     },
+
     // 获取当前账号菜单数据
     async postMenuList(form) {
       return new Promise((resolve, reject) => {
@@ -70,96 +86,18 @@ export const useUserStore = defineStore({
           .then((res: resType) => {
             const { code, data } = res;
             if (code === 0) {
-              const systemRouter = {
-                path: "/system",
-                redirect: "/system/menuOperator/index",
-                meta: {
-                  icon: "setting",
-                  title: "系统管理",
-                  rank: 11
-                },
-                children: [
-                  {
-                    path: "/system/menuOperator/index",
-                    name: "menuOperator",
-                    meta: {
-                      icon: "flUser",
-                      title: "用户管理"
-                    }
-                  },
-                  {
-                    path: "/system/oplog/index",
-                    name: "oplog",
-                    meta: {
-                      icon: "role",
-                      title: "角色管理"
-                    }
-                  },
-                  {
-                    path: "/system/updates/index",
-                    name: "updates",
-                    meta: {
-                      icon: "dept",
-                      title: "部门管理"
-                    }
-                  }
-                ]
-              };
-              const interestRouter = {
-                path: "/interest",
-                redirect: "/interest/account/index",
-                meta: {
-                  icon: "setting",
-                  title: "权限管理",
-                  rank: 11
-                },
-                children: [
-                  {
-                    path: "/interest/account/index",
-                    name: "account",
-                    meta: {
-                      icon: "flUser",
-                      title: "用户管理"
-                    }
-                  },
-                  {
-                    path: "/interest/role/index",
-                    name: "role",
-                    meta: {
-                      icon: "role",
-                      title: "角色管理"
-                    }
-                  },
-                  {
-                    path: "/interest/action/index",
-                    name: "action",
-                    meta: {
-                      icon: "dept",
-                      title: "部门管理"
-                    }
-                  },
-                  {
-                    path: "/interest/dataShare/index",
-                    name: "dataShare",
-                    meta: {
-                      icon: "dict",
-                      title: "字典管理"
-                    }
-                  },
-                  {
-                    path: "/interest/group/index",
-                    name: "group",
-                    meta: {
-                      icon: "dict",
-                      title: "字典管理"
-                    }
-                  }
-                ]
-              };
-              const arrag = [interestRouter, systemRouter];
-
+              const actionList: Array<any> = [];
+              data.forEach(e => {
+                e.child?.forEach(s => {
+                  const item = {
+                    menu_route: s.menu_route,
+                    action: s.action
+                  };
+                  actionList.push(item);
+                });
+              });
+              setAction(JSON.stringify(actionList));
               resolve(res);
-              // console.log(arrag);
             } else {
               resolve(res);
             }
@@ -174,6 +112,7 @@ export const useUserStore = defineStore({
       this.token = "";
       this.name = "";
       removeToken();
+      removeAction();
       storageSession.clear();
       useMultiTagsStoreHook().handleTags("equal", routerArrays);
       router.push("/login");

+ 13 - 11
src/utils/auth.ts

@@ -5,6 +5,7 @@ const MenuKey = "compute-Console-Menu";
 const BtnKey = "compute-Console-MenuBtn";
 const NoticeKey = "compute-Console-Notice";
 const InfoKey = "compute-Console-Info";
+const ActionKey = "compute-Console-Action";
 export function getToken() {
   return Cookies.get(TokenKey);
 }
@@ -17,17 +18,6 @@ export function removeToken() {
   return Cookies.remove(TokenKey);
 }
 
-export function getUserInfo() {
-  return Cookies.get(InfoKey);
-}
-
-export function setUserInfo(token) {
-  return Cookies.set(InfoKey, token);
-}
-
-export function removeUserInfo() {
-  return Cookies.remove(InfoKey);
-}
 export function getMenu() {
   const menu = Cookies.get(MenuKey);
   if (menu) {
@@ -68,3 +58,15 @@ export function setNotice(has) {
 export function removeNotice() {
   return Cookies.remove(NoticeKey);
 }
+
+export function getAction() {
+  return Cookies.get(ActionKey);
+}
+
+export function setAction(has) {
+  return Cookies.set(ActionKey, has);
+}
+
+export function removeAction() {
+  return Cookies.remove(ActionKey);
+}

+ 3 - 0
src/views/InvoiceSales/invoiceApply/index.vue

@@ -10,10 +10,13 @@ import { statusList, inv_type_list } from "./status";
 import { useRouter } from "vue-router";
 import { responseHandle } from "/@/utils/responseHandle";
 import IntervalTime from "/@/components/IntervalTime";
+import { useUserStoreHook } from "/@/store/modules/user";
 const { logout } = useNav();
 defineOptions({
   name: "invoiceApply"
 });
+console.log(useUserStoreHook().getMenuActions("invoiceApply"));
+// const aa=ref([].push(useUserStoreHook().))
 const initform = {
   inv_in: "", //客户公司
   inv_out: "", //业务企业公司

+ 2 - 5
src/views/login/index.vue

@@ -47,8 +47,8 @@ const currentPage = computed(() => {
 });
 
 const ruleForm = reactive({
-  username: "17744520491",
-  password: "aa1111",
+  username: "",
+  password: "",
   verifyCode: ""
 });
 
@@ -61,7 +61,6 @@ const onLogin = async (formEl: FormInstance | undefined) => {
         .loginByUsername(ruleForm)
         .then((res: resType) => {
           const { code, message, data } = res;
-
           if (code === 0) {
             const { userinfo, token } = data ?? {};
             const { nickname } = userinfo ?? {};
@@ -71,9 +70,7 @@ const onLogin = async (formEl: FormInstance | undefined) => {
             });
             initRouter().then(() => {
               loading.value = false;
-              // console.log(ress);
               ElMessage.success("登录成功");
-              // message.success("登录成功");
               router.push("/");
             });
           } else if (code > 100 && code < 200) {