mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	workflow: use pinia replace vuex and fix some bug
This commit is contained in:
		
							parent
							
								
									a26f711d83
								
							
						
					
					
						commit
						d9132ffa64
					
				@ -21,7 +21,7 @@ const systemRouter = {
 | 
				
			|||||||
      // component: () => import("/@/views/system/user/index.vue"),
 | 
					      // component: () => import("/@/views/system/user/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsBaseinfo",
 | 
					        title: "message.hsBaseinfo",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -31,7 +31,7 @@ const systemRouter = {
 | 
				
			|||||||
      // component: () => import("/@/views/system/dict/index.vue"),
 | 
					      // component: () => import("/@/views/system/dict/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsDict",
 | 
					        title: "message.hsDict",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										37
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										37
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -25,6 +25,7 @@
 | 
				
			|||||||
        "nprogress": "^0.2.0",
 | 
					        "nprogress": "^0.2.0",
 | 
				
			||||||
        "path": "^0.12.7",
 | 
					        "path": "^0.12.7",
 | 
				
			||||||
        "path-to-regexp": "^6.2.0",
 | 
					        "path-to-regexp": "^6.2.0",
 | 
				
			||||||
 | 
					        "pinia": "^2.0.0-alpha.19",
 | 
				
			||||||
        "resize-observer-polyfill": "^1.5.1",
 | 
					        "resize-observer-polyfill": "^1.5.1",
 | 
				
			||||||
        "v-contextmenu": "^3.0.0",
 | 
					        "v-contextmenu": "^3.0.0",
 | 
				
			||||||
        "vue": "^3.0.11",
 | 
					        "vue": "^3.0.11",
 | 
				
			||||||
@ -33,7 +34,6 @@
 | 
				
			|||||||
        "vue-router": "^4.0.8",
 | 
					        "vue-router": "^4.0.8",
 | 
				
			||||||
        "vue-types": "^3.0.2",
 | 
					        "vue-types": "^3.0.2",
 | 
				
			||||||
        "vuedraggable": "^4.0.1",
 | 
					        "vuedraggable": "^4.0.1",
 | 
				
			||||||
        "vuex": "^4.0.1",
 | 
					 | 
				
			||||||
        "vxe-table": "^4.0.18-beta.0",
 | 
					        "vxe-table": "^4.0.18-beta.0",
 | 
				
			||||||
        "wangeditor": "^4.0.3",
 | 
					        "wangeditor": "^4.0.3",
 | 
				
			||||||
        "xe-ajax": "^4.0.5",
 | 
					        "xe-ajax": "^4.0.5",
 | 
				
			||||||
@ -2088,6 +2088,14 @@
 | 
				
			|||||||
        "node": ">=0.10.0"
 | 
					        "node": ">=0.10.0"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "node_modules/pinia": {
 | 
				
			||||||
 | 
					      "version": "2.0.0-alpha.19",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.0.0-alpha.19.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-U/FvKm2tVUdqEuPorkYvD3oCgIj/u5EnF9TbX5dEpkNkoWKQM1i23e97QKtQFGuTxMSfzmBFFINv4A9VeVZ1wQ==",
 | 
				
			||||||
 | 
					      "dependencies": {
 | 
				
			||||||
 | 
					        "@vue/devtools-api": "^6.0.0-beta.10"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "node_modules/postcss": {
 | 
					    "node_modules/postcss": {
 | 
				
			||||||
      "version": "8.2.10",
 | 
					      "version": "8.2.10",
 | 
				
			||||||
      "resolved": "https://registry.npm.taobao.org/postcss/download/postcss-8.2.10.tgz",
 | 
					      "resolved": "https://registry.npm.taobao.org/postcss/download/postcss-8.2.10.tgz",
 | 
				
			||||||
@ -2760,17 +2768,6 @@
 | 
				
			|||||||
        "sortablejs": "1.10.2"
 | 
					        "sortablejs": "1.10.2"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/vuex": {
 | 
					 | 
				
			||||||
      "version": "4.0.1",
 | 
					 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/vuex/-/vuex-4.0.1.tgz",
 | 
					 | 
				
			||||||
      "integrity": "sha512-MddakQTAnImDkK1YhEESowKSU5KcjqHH3L1ScPx1lj6NzDDX0FuRBZqJoME5O7/nvj9puudDf6xnWU2w/cqI7g==",
 | 
					 | 
				
			||||||
      "dependencies": {
 | 
					 | 
				
			||||||
        "@vue/devtools-api": "^6.0.0-beta.11"
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      "peerDependencies": {
 | 
					 | 
				
			||||||
        "vue": "^3.0.2"
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    "node_modules/vxe-table": {
 | 
					    "node_modules/vxe-table": {
 | 
				
			||||||
      "version": "4.0.18-beta.0",
 | 
					      "version": "4.0.18-beta.0",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/vxe-table/-/vxe-table-4.0.18-beta.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/vxe-table/-/vxe-table-4.0.18-beta.0.tgz",
 | 
				
			||||||
@ -4590,6 +4587,14 @@
 | 
				
			|||||||
      "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
 | 
					      "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
 | 
				
			||||||
      "dev": true
 | 
					      "dev": true
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "pinia": {
 | 
				
			||||||
 | 
					      "version": "2.0.0-alpha.19",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.0.0-alpha.19.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-U/FvKm2tVUdqEuPorkYvD3oCgIj/u5EnF9TbX5dEpkNkoWKQM1i23e97QKtQFGuTxMSfzmBFFINv4A9VeVZ1wQ==",
 | 
				
			||||||
 | 
					      "requires": {
 | 
				
			||||||
 | 
					        "@vue/devtools-api": "^6.0.0-beta.10"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "postcss": {
 | 
					    "postcss": {
 | 
				
			||||||
      "version": "8.2.10",
 | 
					      "version": "8.2.10",
 | 
				
			||||||
      "resolved": "https://registry.npm.taobao.org/postcss/download/postcss-8.2.10.tgz",
 | 
					      "resolved": "https://registry.npm.taobao.org/postcss/download/postcss-8.2.10.tgz",
 | 
				
			||||||
@ -5126,14 +5131,6 @@
 | 
				
			|||||||
        "sortablejs": "1.10.2"
 | 
					        "sortablejs": "1.10.2"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "vuex": {
 | 
					 | 
				
			||||||
      "version": "4.0.1",
 | 
					 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/vuex/-/vuex-4.0.1.tgz",
 | 
					 | 
				
			||||||
      "integrity": "sha512-MddakQTAnImDkK1YhEESowKSU5KcjqHH3L1ScPx1lj6NzDDX0FuRBZqJoME5O7/nvj9puudDf6xnWU2w/cqI7g==",
 | 
					 | 
				
			||||||
      "requires": {
 | 
					 | 
				
			||||||
        "@vue/devtools-api": "^6.0.0-beta.11"
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    "vxe-table": {
 | 
					    "vxe-table": {
 | 
				
			||||||
      "version": "4.0.18-beta.0",
 | 
					      "version": "4.0.18-beta.0",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/vxe-table/-/vxe-table-4.0.18-beta.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/vxe-table/-/vxe-table-4.0.18-beta.0.tgz",
 | 
				
			||||||
 | 
				
			|||||||
@ -28,6 +28,7 @@
 | 
				
			|||||||
    "nprogress": "^0.2.0",
 | 
					    "nprogress": "^0.2.0",
 | 
				
			||||||
    "path": "^0.12.7",
 | 
					    "path": "^0.12.7",
 | 
				
			||||||
    "path-to-regexp": "^6.2.0",
 | 
					    "path-to-regexp": "^6.2.0",
 | 
				
			||||||
 | 
					    "pinia": "^2.0.0-alpha.19",
 | 
				
			||||||
    "resize-observer-polyfill": "^1.5.1",
 | 
					    "resize-observer-polyfill": "^1.5.1",
 | 
				
			||||||
    "v-contextmenu": "^3.0.0",
 | 
					    "v-contextmenu": "^3.0.0",
 | 
				
			||||||
    "vue": "^3.0.11",
 | 
					    "vue": "^3.0.11",
 | 
				
			||||||
@ -36,7 +37,6 @@
 | 
				
			|||||||
    "vue-router": "^4.0.8",
 | 
					    "vue-router": "^4.0.8",
 | 
				
			||||||
    "vue-types": "^3.0.2",
 | 
					    "vue-types": "^3.0.2",
 | 
				
			||||||
    "vuedraggable": "^4.0.1",
 | 
					    "vuedraggable": "^4.0.1",
 | 
				
			||||||
    "vuex": "^4.0.1",
 | 
					 | 
				
			||||||
    "vxe-table": "^4.0.18-beta.0",
 | 
					    "vxe-table": "^4.0.18-beta.0",
 | 
				
			||||||
    "wangeditor": "^4.0.3",
 | 
					    "wangeditor": "^4.0.3",
 | 
				
			||||||
    "xe-ajax": "^4.0.5",
 | 
					    "xe-ajax": "^4.0.5",
 | 
				
			||||||
 | 
				
			|||||||
@ -16,7 +16,7 @@
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
import { defineComponent } from "vue";
 | 
					import { defineComponent } from "vue"
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
  name: "HamBurger",
 | 
					  name: "HamBurger",
 | 
				
			||||||
  props: {
 | 
					  props: {
 | 
				
			||||||
@ -28,10 +28,10 @@ export default defineComponent({
 | 
				
			|||||||
  emits: ["toggleClick"],
 | 
					  emits: ["toggleClick"],
 | 
				
			||||||
  setup(props, ctx) {
 | 
					  setup(props, ctx) {
 | 
				
			||||||
    const toggleClick = () => {
 | 
					    const toggleClick = () => {
 | 
				
			||||||
      ctx.emit("toggleClick");
 | 
					      ctx.emit("toggleClick")
 | 
				
			||||||
    };
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return { toggleClick };
 | 
					    return { toggleClick }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <div class="navbar">
 | 
					  <div class="navbar">
 | 
				
			||||||
    <Hamburger
 | 
					    <Hamburger
 | 
				
			||||||
      :is-active="sidebar.opened"
 | 
					      :is-active="pureApp.sidebar.opened"
 | 
				
			||||||
      class="hamburger-container"
 | 
					      class="hamburger-container"
 | 
				
			||||||
      @toggleClick="toggleSideBar"
 | 
					      @toggleClick="toggleSideBar"
 | 
				
			||||||
    />
 | 
					    />
 | 
				
			||||||
@ -45,9 +45,9 @@ import { ref, defineComponent, onMounted, unref, watch } from "vue";
 | 
				
			|||||||
import Breadcrumb from "/@/components/BreadCrumb";
 | 
					import Breadcrumb from "/@/components/BreadCrumb";
 | 
				
			||||||
import Hamburger from "/@/components/HamBurger";
 | 
					import Hamburger from "/@/components/HamBurger";
 | 
				
			||||||
import screenfull from "../components/screenfull/index.vue";
 | 
					import screenfull from "../components/screenfull/index.vue";
 | 
				
			||||||
import { useMapGetters } from "../store";
 | 
					 | 
				
			||||||
import { useRouter, useRoute } from "vue-router";
 | 
					import { useRouter, useRoute } from "vue-router";
 | 
				
			||||||
import { useStore } from "vuex";
 | 
					import { useAppStoreHook } from "/@/store/modules/app";
 | 
				
			||||||
 | 
					import { mapGetters } from "pinia";
 | 
				
			||||||
import { storageSession } from "/@/utils/storage";
 | 
					import { storageSession } from "/@/utils/storage";
 | 
				
			||||||
import ch from "/@/assets/ch.png";
 | 
					import ch from "/@/assets/ch.png";
 | 
				
			||||||
import en from "/@/assets/en.png";
 | 
					import en from "/@/assets/en.png";
 | 
				
			||||||
@ -70,7 +70,7 @@ export default defineComponent({
 | 
				
			|||||||
  setup() {
 | 
					  setup() {
 | 
				
			||||||
    let langs = ref(true);
 | 
					    let langs = ref(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const store = useStore();
 | 
					    const pureApp = useAppStoreHook();
 | 
				
			||||||
    const router = useRouter();
 | 
					    const router = useRouter();
 | 
				
			||||||
    const route = useRoute();
 | 
					    const route = useRoute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -108,6 +108,10 @@ export default defineComponent({
 | 
				
			|||||||
      emitter.emit("openPanel");
 | 
					      emitter.emit("openPanel");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function toggleSideBar() {
 | 
				
			||||||
 | 
					      pureApp.toggleSideBar();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    onMounted(() => {
 | 
					    onMounted(() => {
 | 
				
			||||||
      document
 | 
					      document
 | 
				
			||||||
        .querySelector(".el-dropdown__popper")
 | 
					        .querySelector(".el-dropdown__popper")
 | 
				
			||||||
@ -118,11 +122,8 @@ export default defineComponent({
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      // @ts-ignore
 | 
					      pureApp,
 | 
				
			||||||
      ...useMapGetters(["sidebar"]),
 | 
					      toggleSideBar,
 | 
				
			||||||
      toggleSideBar() {
 | 
					 | 
				
			||||||
        store.dispatch("app/toggleSideBar");
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      langs,
 | 
					      langs,
 | 
				
			||||||
      usename,
 | 
					      usename,
 | 
				
			||||||
      toggleLang,
 | 
					      toggleLang,
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,7 @@
 | 
				
			|||||||
        @select="menuSelect"
 | 
					        @select="menuSelect"
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <sidebar-item
 | 
					        <sidebar-item
 | 
				
			||||||
          v-for="route in routes"
 | 
					          v-for="route in routeStore.wholeRoutes"
 | 
				
			||||||
          :key="route.path"
 | 
					          :key="route.path"
 | 
				
			||||||
          :item="route"
 | 
					          :item="route"
 | 
				
			||||||
          :base-path="route.path"
 | 
					          :base-path="route.path"
 | 
				
			||||||
@ -31,21 +31,24 @@ import {
 | 
				
			|||||||
  onBeforeMount
 | 
					  onBeforeMount
 | 
				
			||||||
} from "vue";
 | 
					} from "vue";
 | 
				
			||||||
import { useRoute, useRouter } from "vue-router";
 | 
					import { useRoute, useRouter } from "vue-router";
 | 
				
			||||||
import { useStore } from "vuex";
 | 
					import { useAppStoreHook } from "/@/store/modules/app";
 | 
				
			||||||
import SidebarItem from "./SidebarItem.vue";
 | 
					import SidebarItem from "./SidebarItem.vue";
 | 
				
			||||||
import { algorithm } from "../../../utils/algorithm";
 | 
					import { algorithm } from "../../../utils/algorithm";
 | 
				
			||||||
import { useDynamicRoutesHook } from "../tag/tagsHook";
 | 
					import { useDynamicRoutesHook } from "../tag/tagsHook";
 | 
				
			||||||
import { emitter } from "/@/utils/mitt";
 | 
					import { emitter } from "/@/utils/mitt";
 | 
				
			||||||
import Logo from "./Logo.vue";
 | 
					import Logo from "./Logo.vue";
 | 
				
			||||||
import { storageLocal } from "/@/utils/storage";
 | 
					import { storageLocal } from "/@/utils/storage";
 | 
				
			||||||
 | 
					import { usePermissionStoreHook } from "/@/store/modules/permission";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default defineComponent({
 | 
					export default defineComponent({
 | 
				
			||||||
  name: "sidebar",
 | 
					  name: "sidebar",
 | 
				
			||||||
  components: { SidebarItem, Logo },
 | 
					  components: { SidebarItem, Logo },
 | 
				
			||||||
  setup() {
 | 
					  setup() {
 | 
				
			||||||
 | 
					    const routeStore = usePermissionStoreHook();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const router = useRouter().options.routes;
 | 
					    const router = useRouter().options.routes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const store = useStore();
 | 
					    const pureApp = useAppStoreHook();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const route = useRoute();
 | 
					    const route = useRoute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -89,11 +92,11 @@ export default defineComponent({
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      routes: computed(() => algorithm.increaseIndexes(router)),
 | 
					 | 
				
			||||||
      activeMenu,
 | 
					      activeMenu,
 | 
				
			||||||
      isCollapse: computed(() => !store.getters.sidebar.opened),
 | 
					      isCollapse: computed(() => !pureApp.getSidebarStatus),
 | 
				
			||||||
      menuSelect,
 | 
					      menuSelect,
 | 
				
			||||||
      showLogo
 | 
					      showLogo,
 | 
				
			||||||
 | 
					      routeStore
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
    <div
 | 
					    <div
 | 
				
			||||||
      v-if="device === 'mobile' && sidebar.opened"
 | 
					      v-if="device === 'mobile' && sidebar.opened"
 | 
				
			||||||
      class="drawer-bg"
 | 
					      class="drawer-bg"
 | 
				
			||||||
      @click="handleClickOutside"
 | 
					      @click="handleClickOutside(false)"
 | 
				
			||||||
    />
 | 
					    />
 | 
				
			||||||
    <!-- 侧边栏 -->
 | 
					    <!-- 侧边栏 -->
 | 
				
			||||||
    <sidebar class="sidebar-container" v-if="!containerHiddenSideBar" />
 | 
					    <sidebar class="sidebar-container" v-if="!containerHiddenSideBar" />
 | 
				
			||||||
@ -42,7 +42,8 @@ import {
 | 
				
			|||||||
  onBeforeMount,
 | 
					  onBeforeMount,
 | 
				
			||||||
  onBeforeUnmount
 | 
					  onBeforeUnmount
 | 
				
			||||||
} from "vue";
 | 
					} from "vue";
 | 
				
			||||||
import { useStore } from "vuex";
 | 
					import { useAppStoreHook } from "/@/store/modules/app";
 | 
				
			||||||
 | 
					import { useSettingStoreHook } from "/@/store/modules/settings";
 | 
				
			||||||
import { useEventListener, useFullscreen } from "@vueuse/core";
 | 
					import { useEventListener, useFullscreen } from "@vueuse/core";
 | 
				
			||||||
import { toggleClass, removeClass } from "/@/utils/operate";
 | 
					import { toggleClass, removeClass } from "/@/utils/operate";
 | 
				
			||||||
let hiddenMainContainer = "hidden-main-container";
 | 
					let hiddenMainContainer = "hidden-main-container";
 | 
				
			||||||
@ -67,7 +68,8 @@ export default {
 | 
				
			|||||||
    tag
 | 
					    tag
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  setup() {
 | 
					  setup() {
 | 
				
			||||||
    const store = useStore();
 | 
					    const pureApp = useAppStoreHook();
 | 
				
			||||||
 | 
					    const pureSetting = useSettingStoreHook();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const router = useRouter();
 | 
					    const router = useRouter();
 | 
				
			||||||
    const route = useRoute();
 | 
					    const route = useRoute();
 | 
				
			||||||
@ -78,15 +80,15 @@ export default {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const set: setInter = reactive({
 | 
					    const set: setInter = reactive({
 | 
				
			||||||
      sidebar: computed(() => {
 | 
					      sidebar: computed(() => {
 | 
				
			||||||
        return store.state.app.sidebar;
 | 
					        return pureApp.sidebar;
 | 
				
			||||||
      }),
 | 
					      }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      device: computed(() => {
 | 
					      device: computed(() => {
 | 
				
			||||||
        return store.state.app.device;
 | 
					        return pureApp.device;
 | 
				
			||||||
      }),
 | 
					      }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      fixedHeader: computed(() => {
 | 
					      fixedHeader: computed(() => {
 | 
				
			||||||
        return store.state.settings.fixedHeader;
 | 
					        return pureSetting.fixedHeader;
 | 
				
			||||||
      }),
 | 
					      }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      classes: computed(() => {
 | 
					      classes: computed(() => {
 | 
				
			||||||
@ -99,16 +101,16 @@ export default {
 | 
				
			|||||||
      })
 | 
					      })
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const handleClickOutside = (params: Boolean) => {
 | 
				
			||||||
 | 
					      pureApp.closeSideBar({ withoutAnimation: params });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    watchEffect(() => {
 | 
					    watchEffect(() => {
 | 
				
			||||||
      if (set.device === "mobile" && !set.sidebar.opened) {
 | 
					      if (set.device === "mobile" && !set.sidebar.opened) {
 | 
				
			||||||
        store.dispatch("app/closeSideBar", { withoutAnimation: false });
 | 
					        handleClickOutside(false);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const handleClickOutside = () => {
 | 
					 | 
				
			||||||
      store.dispatch("app/closeSideBar", { withoutAnimation: false });
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const $_isMobile = () => {
 | 
					    const $_isMobile = () => {
 | 
				
			||||||
      const rect = document.body.getBoundingClientRect();
 | 
					      const rect = document.body.getBoundingClientRect();
 | 
				
			||||||
      return rect.width - 1 < WIDTH.value;
 | 
					      return rect.width - 1 < WIDTH.value;
 | 
				
			||||||
@ -117,10 +119,9 @@ export default {
 | 
				
			|||||||
    const $_resizeHandler = () => {
 | 
					    const $_resizeHandler = () => {
 | 
				
			||||||
      if (!document.hidden) {
 | 
					      if (!document.hidden) {
 | 
				
			||||||
        const isMobile = $_isMobile();
 | 
					        const isMobile = $_isMobile();
 | 
				
			||||||
        store.dispatch("app/toggleDevice", isMobile ? "mobile" : "desktop");
 | 
					        pureApp.toggleDevice(isMobile ? "mobile" : "desktop");
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (isMobile) {
 | 
					        if (isMobile) {
 | 
				
			||||||
          store.dispatch("app/closeSideBar", { withoutAnimation: true });
 | 
					          handleClickOutside(true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
@ -146,8 +147,8 @@ export default {
 | 
				
			|||||||
    onMounted(() => {
 | 
					    onMounted(() => {
 | 
				
			||||||
      const isMobile = $_isMobile();
 | 
					      const isMobile = $_isMobile();
 | 
				
			||||||
      if (isMobile) {
 | 
					      if (isMobile) {
 | 
				
			||||||
        store.dispatch("app/toggleDevice", "mobile");
 | 
					        pureApp.toggleDevice("mobile");
 | 
				
			||||||
        store.dispatch("app/closeSideBar", { withoutAnimation: true });
 | 
					        handleClickOutside(true);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      toggleClass(
 | 
					      toggleClass(
 | 
				
			||||||
        unref(containerHiddenSideBar),
 | 
					        unref(containerHiddenSideBar),
 | 
				
			||||||
 | 
				
			|||||||
@ -1,14 +0,0 @@
 | 
				
			|||||||
import { computed, ComputedRef } from "vue";
 | 
					 | 
				
			||||||
import { useStore } from "vuex";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export function useMapGetters<T extends string>(keys: T[]) {
 | 
					 | 
				
			||||||
  const res: Record<string, ComputedRef> = {}
 | 
					 | 
				
			||||||
  // @ts-ignore
 | 
					 | 
				
			||||||
  const { getters } = useStore()
 | 
					 | 
				
			||||||
  keys.map(key => {
 | 
					 | 
				
			||||||
    if (Reflect.has(getters, key)) {
 | 
					 | 
				
			||||||
      res[key] = computed(() => getters[key])
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  })
 | 
					 | 
				
			||||||
  return res as any as Record<T, ComputedRef>
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										10
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/main.ts
									
									
									
									
									
								
							@ -1,7 +1,7 @@
 | 
				
			|||||||
import { createApp } from "vue";
 | 
					import { createApp } from "vue";
 | 
				
			||||||
import App from "./App.vue";
 | 
					import App from "./App.vue";
 | 
				
			||||||
import router from "./router";
 | 
					import router from "./router";
 | 
				
			||||||
import store from "./store";
 | 
					import { setupStore } from "/@/store";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { useElementPlus } from "../src/plugins/element-plus";
 | 
					import { useElementPlus } from "../src/plugins/element-plus";
 | 
				
			||||||
import { useTable } from "../src/plugins/vxe-table";
 | 
					import { useTable } from "../src/plugins/vxe-table";
 | 
				
			||||||
@ -50,7 +50,11 @@ export const getServerConfig = async (): Promise<any> => {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
getServerConfig().then(async () => {
 | 
					getServerConfig().then(async () => {
 | 
				
			||||||
  app.use(router);
 | 
					  setupStore(app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  app.use(router).use(useElementPlus).use(useTable).use(usI18n);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  await router.isReady();
 | 
					  await router.isReady();
 | 
				
			||||||
  app.use(store).use(useElementPlus).use(useTable).use(usI18n).mount("#app");
 | 
					
 | 
				
			||||||
 | 
					  app.mount("#app");
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
@ -8,14 +8,10 @@ import nestedRouter from "./modules/nested";
 | 
				
			|||||||
import errorRouter from "./modules/error";
 | 
					import errorRouter from "./modules/error";
 | 
				
			||||||
import permissionRouter from "./modules/permission";
 | 
					import permissionRouter from "./modules/permission";
 | 
				
			||||||
import remainingRouter from "./modules/remaining"; //静态路由
 | 
					import remainingRouter from "./modules/remaining"; //静态路由
 | 
				
			||||||
import Layout from "/@/layout/index.vue";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// https://cn.vitejs.dev/guide/features.html#glob-import
 | 
					 | 
				
			||||||
const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import { getAsyncRoutes } from "/@/api/routes";
 | 
					 | 
				
			||||||
import { storageSession } from "../utils/storage";
 | 
					import { storageSession } from "../utils/storage";
 | 
				
			||||||
import { i18n } from "/@/plugins/i18n/index";
 | 
					import { i18n } from "/@/plugins/i18n/index";
 | 
				
			||||||
 | 
					import { usePermissionStoreHook } from "/@/store/modules/permission";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const constantRoutes: Array<RouteRecordRaw> = [
 | 
					const constantRoutes: Array<RouteRecordRaw> = [
 | 
				
			||||||
  homeRouter,
 | 
					  homeRouter,
 | 
				
			||||||
@ -27,28 +23,19 @@ const constantRoutes: Array<RouteRecordRaw> = [
 | 
				
			|||||||
  errorRouter,
 | 
					  errorRouter,
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 过滤后端传来的动态路由重新生成规范路由
 | 
					 | 
				
			||||||
const addAsyncRoutes = (arrRoutes: Array<string>) => {
 | 
					 | 
				
			||||||
  if (!arrRoutes || !arrRoutes.length) return;
 | 
					 | 
				
			||||||
  arrRoutes.forEach((v: any) => {
 | 
					 | 
				
			||||||
    if (v.redirect) {
 | 
					 | 
				
			||||||
      v.component = Layout;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      v.component = modulesRoutes[`/src/views${v.path}/index.vue`];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (v.children) {
 | 
					 | 
				
			||||||
      addAsyncRoutes(v.children);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  return arrRoutes;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 按照路由中meta下的rank等级升序来排序路由
 | 
					// 按照路由中meta下的rank等级升序来排序路由
 | 
				
			||||||
function ascending(arr) {
 | 
					export const ascending = (arr) => {
 | 
				
			||||||
  return arr.sort((a: any, b: any) => {
 | 
					  return arr.sort((a: any, b: any) => {
 | 
				
			||||||
    return a?.meta?.rank - b?.meta?.rank;
 | 
					    return a?.meta?.rank - b?.meta?.rank;
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 将所有静态路由导出
 | 
				
			||||||
 | 
					export const constantRoutesArr = ascending(constantRoutes).concat(
 | 
				
			||||||
 | 
					  ...remainingRouter
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const isLogin = storageSession.getItem("info");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const router = createRouter({
 | 
					const router = createRouter({
 | 
				
			||||||
  history: createWebHashHistory(),
 | 
					  history: createWebHashHistory(),
 | 
				
			||||||
@ -73,29 +60,9 @@ import NProgress from "../utils/progress";
 | 
				
			|||||||
const whiteList = ["/login", "/register"];
 | 
					const whiteList = ["/login", "/register"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
router.beforeEach((to, _from, next) => {
 | 
					router.beforeEach((to, _from, next) => {
 | 
				
			||||||
  let isLogin = storageSession.getItem("info");
 | 
					 | 
				
			||||||
  // _from?.name;
 | 
					  // _from?.name;
 | 
				
			||||||
  if (isLogin) {
 | 
					  if (isLogin) {
 | 
				
			||||||
    // 异步路由
 | 
					    usePermissionStoreHook().changeSetting();
 | 
				
			||||||
    getAsyncRoutes({ name: isLogin.username }).then(({ info }) => {
 | 
					 | 
				
			||||||
      if (info.length === 0) {
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      addAsyncRoutes([info]).forEach((v: any) => {
 | 
					 | 
				
			||||||
        // 防止重复添加路由
 | 
					 | 
				
			||||||
        if (
 | 
					 | 
				
			||||||
          router.options.routes.findIndex((value) => value.path === v.path) !==
 | 
					 | 
				
			||||||
          -1
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
          return;
 | 
					 | 
				
			||||||
        // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
 | 
					 | 
				
			||||||
        router.options.routes.push(v);
 | 
					 | 
				
			||||||
        // 最终路由进行升序
 | 
					 | 
				
			||||||
        ascending(router.options.routes);
 | 
					 | 
				
			||||||
        router.addRoute(v.name, v);
 | 
					 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    console.log(router.options.routes);
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  NProgress.start();
 | 
					  NProgress.start();
 | 
				
			||||||
  const { t } = i18n.global;
 | 
					  const { t } = i18n.global;
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/video/index.vue"),
 | 
					      component: () => import("/@/views/components/video/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsvideo",
 | 
					        title: "message.hsvideo",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -29,7 +29,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/map/index.vue"),
 | 
					      component: () => import("/@/views/components/map/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsmap",
 | 
					        title: "message.hsmap",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -39,7 +39,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/draggable/index.vue"),
 | 
					      component: () => import("/@/views/components/draggable/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsdraggable",
 | 
					        title: "message.hsdraggable",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -50,7 +50,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/split-pane/index.vue"),
 | 
					      component: () => import("/@/views/components/split-pane/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hssplitPane",
 | 
					        title: "message.hssplitPane",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -60,7 +60,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/button/index.vue"),
 | 
					      component: () => import("/@/views/components/button/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsbutton",
 | 
					        title: "message.hsbutton",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -70,7 +70,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/cropping/index.vue"),
 | 
					      component: () => import("/@/views/components/cropping/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hscropping",
 | 
					        title: "message.hscropping",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -80,7 +80,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/count-to/index.vue"),
 | 
					      component: () => import("/@/views/components/count-to/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hscountTo",
 | 
					        title: "message.hscountTo",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -90,7 +90,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/selector/index.vue"),
 | 
					      component: () => import("/@/views/components/selector/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsselector",
 | 
					        title: "message.hsselector",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -100,7 +100,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/seamless-scroll/index.vue"),
 | 
					      component: () => import("/@/views/components/seamless-scroll/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsseamless",
 | 
					        title: "message.hsseamless",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -110,7 +110,7 @@ const componentsRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/components/contextmenu/index.vue"),
 | 
					      component: () => import("/@/views/components/contextmenu/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hscontextmenu",
 | 
					        title: "message.hscontextmenu",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,7 @@ const editorRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/editor/index.vue"),
 | 
					      component: () => import("/@/views/editor/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hseditor",
 | 
					        title: "message.hseditor",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,7 @@ const errorRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/error/401.vue"),
 | 
					      component: () => import("/@/views/error/401.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsfourZeroOne",
 | 
					        title: "message.hsfourZeroOne",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -29,7 +29,7 @@ const errorRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/error/404.vue"),
 | 
					      component: () => import("/@/views/error/404.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsfourZeroFour",
 | 
					        title: "message.hsfourZeroFour",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,7 @@ const flowChartRouter = {
 | 
				
			|||||||
      component: () => import("/@/views/flow-chart/index.vue"),
 | 
					      component: () => import("/@/views/flow-chart/index.vue"),
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "message.hsflowChart",
 | 
					        title: "message.hsflowChart",
 | 
				
			||||||
        showLink: false,
 | 
					        showLink: true,
 | 
				
			||||||
        savedPosition: true,
 | 
					        savedPosition: true,
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +0,0 @@
 | 
				
			|||||||
const getters = {
 | 
					 | 
				
			||||||
  sidebar: (state: any) => state.app.sidebar,
 | 
					 | 
				
			||||||
  device: (state: any) => state.app.device,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export default getters
 | 
					 | 
				
			||||||
@ -1,12 +1,9 @@
 | 
				
			|||||||
import { createStore } from 'vuex'
 | 
					import type { App } from "vue";
 | 
				
			||||||
import getters from './getters'
 | 
					import { createPinia } from "pinia";
 | 
				
			||||||
import app from './modules/app'
 | 
					const store = createPinia();
 | 
				
			||||||
import settings from './modules/settings'
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default createStore({
 | 
					export function setupStore(app: App<Element>) {
 | 
				
			||||||
  getters,
 | 
					  app.use(store);
 | 
				
			||||||
  modules: {
 | 
					}
 | 
				
			||||||
    app,
 | 
					
 | 
				
			||||||
    settings
 | 
					export { store };
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
})
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -1,58 +1,64 @@
 | 
				
			|||||||
import { storageLocal } from "../../utils/storage"
 | 
					import { storageLocal } from "../../utils/storage";
 | 
				
			||||||
interface stateInter {
 | 
					import { defineStore } from "pinia";
 | 
				
			||||||
 | 
					import { store } from "/@/store";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface AppState {
 | 
				
			||||||
  sidebar: {
 | 
					  sidebar: {
 | 
				
			||||||
    opened: Boolean,
 | 
					    opened: Boolean;
 | 
				
			||||||
    withoutAnimation: Boolean
 | 
					    withoutAnimation: Boolean;
 | 
				
			||||||
  },
 | 
					  };
 | 
				
			||||||
  device: String
 | 
					  device: String;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const state = {
 | 
					export const useAppStore = defineStore({
 | 
				
			||||||
  sidebar: {
 | 
					  id: "pure-app",
 | 
				
			||||||
    opened: storageLocal.getItem('sidebarStatus') ? !!+storageLocal.getItem('sidebarStatus') : true,
 | 
					  state: (): AppState => ({
 | 
				
			||||||
    withoutAnimation: false
 | 
					    sidebar: {
 | 
				
			||||||
 | 
					      opened: storageLocal.getItem("sidebarStatus")
 | 
				
			||||||
 | 
					        ? !!+storageLocal.getItem("sidebarStatus")
 | 
				
			||||||
 | 
					        : true,
 | 
				
			||||||
 | 
					      withoutAnimation: false,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    device: "desktop",
 | 
				
			||||||
 | 
					  }),
 | 
				
			||||||
 | 
					  getters: {
 | 
				
			||||||
 | 
					    getSidebarStatus() {
 | 
				
			||||||
 | 
					      return this.sidebar.opened;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    getDevice() {
 | 
				
			||||||
 | 
					      return this.device;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  device: 'desktop'
 | 
					  actions: {
 | 
				
			||||||
}
 | 
					    TOGGLE_SIDEBAR() {
 | 
				
			||||||
 | 
					      this.sidebar.opened = !this.sidebar.opened;
 | 
				
			||||||
 | 
					      this.sidebar.withoutAnimation = false;
 | 
				
			||||||
 | 
					      if (this.sidebar.opened) {
 | 
				
			||||||
 | 
					        storageLocal.setItem("sidebarStatus", 1);
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        storageLocal.setItem("sidebarStatus", 0);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    CLOSE_SIDEBAR(withoutAnimation: Boolean) {
 | 
				
			||||||
 | 
					      storageLocal.setItem("sidebarStatus", 0);
 | 
				
			||||||
 | 
					      this.sidebar.opened = false;
 | 
				
			||||||
 | 
					      this.sidebar.withoutAnimation = withoutAnimation;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    TOGGLE_DEVICE(device: String) {
 | 
				
			||||||
 | 
					      this.device = device;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    async toggleSideBar() {
 | 
				
			||||||
 | 
					      await this.TOGGLE_SIDEBAR();
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    closeSideBar(withoutAnimation) {
 | 
				
			||||||
 | 
					      this.CLOSE_SIDEBAR(withoutAnimation);
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    toggleDevice(device) {
 | 
				
			||||||
 | 
					      this.TOGGLE_DEVICE(device);
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const mutations = {
 | 
					export function useAppStoreHook() {
 | 
				
			||||||
  TOGGLE_SIDEBAR: (state: stateInter): void => {
 | 
					  return useAppStore(store);
 | 
				
			||||||
    state.sidebar.opened = !state.sidebar.opened
 | 
					 | 
				
			||||||
    state.sidebar.withoutAnimation = false
 | 
					 | 
				
			||||||
     if (state.sidebar.opened) {
 | 
					 | 
				
			||||||
      storageLocal.setItem('sidebarStatus', 1)
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      storageLocal.setItem('sidebarStatus', 0)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  CLOSE_SIDEBAR: (state: stateInter, withoutAnimation: Boolean) => {
 | 
					 | 
				
			||||||
    storageLocal.setItem('sidebarStatus', 0)
 | 
					 | 
				
			||||||
    state.sidebar.opened = false
 | 
					 | 
				
			||||||
    state.sidebar.withoutAnimation = withoutAnimation
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  TOGGLE_DEVICE: (state: stateInter, device: String) => {
 | 
					 | 
				
			||||||
    state.device = device
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const actions = {
 | 
					 | 
				
			||||||
  // @ts-ignore
 | 
					 | 
				
			||||||
  toggleSideBar({ commit }) {
 | 
					 | 
				
			||||||
    commit('TOGGLE_SIDEBAR')
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  // @ts-ignore
 | 
					 | 
				
			||||||
  closeSideBar({ commit }, { withoutAnimation }) {
 | 
					 | 
				
			||||||
    commit('CLOSE_SIDEBAR', withoutAnimation)
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  // @ts-ignore
 | 
					 | 
				
			||||||
  toggleDevice({ commit }, device) {
 | 
					 | 
				
			||||||
    commit('TOGGLE_DEVICE', device)
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export default {
 | 
					 | 
				
			||||||
  namespaced: true,
 | 
					 | 
				
			||||||
  state,
 | 
					 | 
				
			||||||
  mutations,
 | 
					 | 
				
			||||||
  actions
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										74
									
								
								src/store/modules/permission.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								src/store/modules/permission.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,74 @@
 | 
				
			|||||||
 | 
					import { defineStore } from "pinia";
 | 
				
			||||||
 | 
					import { store } from "/@/store";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { constantRoutesArr, ascending, isLogin } from "/@/router/index";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { getAsyncRoutes } from "/@/api/routes";
 | 
				
			||||||
 | 
					import Layout from "/@/layout/index.vue";
 | 
				
			||||||
 | 
					import router from "/@/router/index";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://cn.vitejs.dev/guide/features.html#glob-import
 | 
				
			||||||
 | 
					const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 过滤后端传来的动态路由重新生成规范路由
 | 
				
			||||||
 | 
					const addAsyncRoutes = (arrRoutes: Array<string>) => {
 | 
				
			||||||
 | 
					  if (!arrRoutes || !arrRoutes.length) return;
 | 
				
			||||||
 | 
					  arrRoutes.forEach((v: any) => {
 | 
				
			||||||
 | 
					    if (v.redirect) {
 | 
				
			||||||
 | 
					      v.component = Layout;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      v.component = modulesRoutes[`/src/views${v.path}/index.vue`];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (v.children) {
 | 
				
			||||||
 | 
					      addAsyncRoutes(v.children);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  return arrRoutes;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const usePermissionStore = defineStore({
 | 
				
			||||||
 | 
					  id: "pure-permission",
 | 
				
			||||||
 | 
					  state: () => ({
 | 
				
			||||||
 | 
					    constantRoutes: constantRoutesArr, //静态路由
 | 
				
			||||||
 | 
					    asyncRoutes: [], //动态路由
 | 
				
			||||||
 | 
					    wholeRoutes: [],
 | 
				
			||||||
 | 
					  }),
 | 
				
			||||||
 | 
					  actions: {
 | 
				
			||||||
 | 
					    asyncActionRoutes(routes) {
 | 
				
			||||||
 | 
					      this.wholeRoutes = ascending(this.constantRoutes.concat(routes)).filter(
 | 
				
			||||||
 | 
					        (v) => v.meta.showLink
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      this.asyncRoutes.push(routes);
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    async changeSetting() {
 | 
				
			||||||
 | 
					      // 异步路由
 | 
				
			||||||
 | 
					      await getAsyncRoutes({ name: isLogin.username }).then(({ info }) => {
 | 
				
			||||||
 | 
					        if (info.length === 0) {
 | 
				
			||||||
 | 
					          this.wholeRoutes = router.options.routes.filter(
 | 
				
			||||||
 | 
					            (v) => v.meta.showLink
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
 | 
					          return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        addAsyncRoutes([info]).forEach((v: any) => {
 | 
				
			||||||
 | 
					          // 防止重复添加路由
 | 
				
			||||||
 | 
					          if (
 | 
				
			||||||
 | 
					            router.options.routes.findIndex(
 | 
				
			||||||
 | 
					              (value) => value.path === v.path
 | 
				
			||||||
 | 
					            ) !== -1
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					          // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
 | 
				
			||||||
 | 
					          router.options.routes.push(v);
 | 
				
			||||||
 | 
					          // 最终路由进行升序
 | 
				
			||||||
 | 
					          ascending(router.options.routes);
 | 
				
			||||||
 | 
					          router.addRoute(v.name, v);
 | 
				
			||||||
 | 
					          this.asyncActionRoutes(v);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function usePermissionStoreHook() {
 | 
				
			||||||
 | 
					  return usePermissionStore(store);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,27 +1,38 @@
 | 
				
			|||||||
import defaultSettings from "../../settings";
 | 
					import defaultSettings from "../../settings";
 | 
				
			||||||
 | 
					import { defineStore } from "pinia";
 | 
				
			||||||
 | 
					import { store } from "/@/store";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const state = {
 | 
					interface SettingState {
 | 
				
			||||||
  title: defaultSettings.title,
 | 
					  title: String;
 | 
				
			||||||
  fixedHeader: defaultSettings.fixedHeader,
 | 
					  fixedHeader: Boolean;
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const mutations = {
 | 
					export const useSettingStore = defineStore({
 | 
				
			||||||
  CHANGE_SETTING: (state: any, { key, value }) => {
 | 
					  id: "pure-setting",
 | 
				
			||||||
    if (state.hasOwnProperty(key)) {
 | 
					  state: (): SettingState => ({
 | 
				
			||||||
      state[key] = value;
 | 
					    title: defaultSettings.title,
 | 
				
			||||||
    }
 | 
					    fixedHeader: defaultSettings.fixedHeader,
 | 
				
			||||||
 | 
					  }),
 | 
				
			||||||
 | 
					  getters: {
 | 
				
			||||||
 | 
					    getTitle() {
 | 
				
			||||||
 | 
					      return this.title;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    getFixedHeader() {
 | 
				
			||||||
 | 
					      return this.fixedHeader;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					  actions: {
 | 
				
			||||||
 | 
					    CHANGE_SETTING({ key, value }) {
 | 
				
			||||||
const actions = {
 | 
					      if (this.hasOwnProperty(key)) {
 | 
				
			||||||
  changeSetting({ commit }, data) {
 | 
					        this[key] = value;
 | 
				
			||||||
    commit("CHANGE_SETTING", data);
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    changeSetting(data) {
 | 
				
			||||||
 | 
					      this.CHANGE_SETTING(data);
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export function useSettingStoreHook() {
 | 
				
			||||||
  namespaced: true,
 | 
					  return useSettingStore(store);
 | 
				
			||||||
  state,
 | 
					}
 | 
				
			||||||
  mutations,
 | 
					 | 
				
			||||||
  actions,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user