|
@@ -1,33 +1,45 @@
|
|
|
-import { ActionType } from "./actions";
|
|
|
-import { MutationType } from "./mutations";
|
|
|
import { AugmentedActionContext } from "./_module";
|
|
|
import { RouteConfig } from "@/types/route";
|
|
|
import { RouteRecordRaw } from "vue-router";
|
|
|
|
|
|
+// state 定义
|
|
|
type State = {
|
|
|
roles: string[];
|
|
|
routes: RouteConfig[];
|
|
|
addRoutes: RouteConfig[];
|
|
|
};
|
|
|
|
|
|
+// mutation 定义
|
|
|
+enum MutationType {
|
|
|
+ setRoles = "setRoles",
|
|
|
+ setRoutes = "setRoutes",
|
|
|
+}
|
|
|
+
|
|
|
type Mutations<S = State> = {
|
|
|
- [MutationType.SET_ROLES](state: S, roles: string[]): void;
|
|
|
- [MutationType.SET_ROUTES](state: S, routes: RouteConfig[]): void;
|
|
|
+ [MutationType.setRoles](state: S, roles: string[]): void;
|
|
|
+ [MutationType.setRoutes](state: S, routes: RouteConfig[]): void;
|
|
|
};
|
|
|
|
|
|
+// action 定义
|
|
|
+enum ActionType {
|
|
|
+ generatorRoutes = "generatorRoutes",
|
|
|
+ getUserRoles = "getUserRoles",
|
|
|
+}
|
|
|
+
|
|
|
type Actions = {
|
|
|
- [ActionType.INIT_ROUTES](
|
|
|
+ [ActionType.generatorRoutes](
|
|
|
{ commit }: AugmentedActionContext,
|
|
|
roles: string[]
|
|
|
): Promise<RouteConfig[]>;
|
|
|
- [ActionType.GET_USER_ROLES]({
|
|
|
+ [ActionType.getUserRoles]({
|
|
|
commit,
|
|
|
}: AugmentedActionContext): Promise<string[]>;
|
|
|
};
|
|
|
|
|
|
+// getter 定义
|
|
|
type Getters = {
|
|
|
permissionRoutes(state: State): RouteRecordRaw[];
|
|
|
userRoles(state: State): string[];
|
|
|
};
|
|
|
|
|
|
-export { State, Mutations, Actions, Getters };
|
|
|
+export { State, Mutations, MutationType, Actions, ActionType, Getters };
|