|
@@ -1,222 +0,0 @@
|
|
|
-import {
|
|
|
- login,
|
|
|
- logout,
|
|
|
- userinfo,
|
|
|
- dingdingdetail,
|
|
|
- usergetinfo,
|
|
|
- roleProcessInfo,
|
|
|
-} from "@/apis/user";
|
|
|
-import configRouter from "@/router/data";
|
|
|
-import {
|
|
|
- getToken,
|
|
|
- setToken,
|
|
|
- removeToken,
|
|
|
- getMenu,
|
|
|
- setMenu,
|
|
|
- removeMenu,
|
|
|
- getBtn,
|
|
|
-} from "@/utils/auth";
|
|
|
-const state = {
|
|
|
- token: getToken(),
|
|
|
- name: "",
|
|
|
- avatar: require("@/assets/img/avatar.gif"),
|
|
|
- introduction: "",
|
|
|
- roles: ["admin"],
|
|
|
- btnList: getBtn(),
|
|
|
- navList: getMenu(),
|
|
|
-};
|
|
|
-const mutations = {
|
|
|
- SET_TOKEN: (state, token) => {
|
|
|
- state.token = token;
|
|
|
- },
|
|
|
- SET_MENU: (state, menu) => {
|
|
|
- state.menu = menu;
|
|
|
- },
|
|
|
- SET_HAS: (state, has) => {
|
|
|
- state.has = has;
|
|
|
- },
|
|
|
- SET_INTRODUCTION: (state, introduction) => {
|
|
|
- state.introduction = introduction;
|
|
|
- },
|
|
|
- SET_NAME: (state, name) => {
|
|
|
- state.name = name;
|
|
|
- },
|
|
|
- SET_AVATAR: (state, avatar) => {
|
|
|
- state.avatar = avatar;
|
|
|
- },
|
|
|
- SET_ROLES: (state, roles) => {
|
|
|
- state.roles = roles;
|
|
|
- },
|
|
|
- navListFn(state, val) {
|
|
|
- if (!val) {
|
|
|
- val = [];
|
|
|
- }
|
|
|
- state.navList = val;
|
|
|
- setMenu(val);
|
|
|
- },
|
|
|
-};
|
|
|
-
|
|
|
-const actions = {
|
|
|
- // user login
|
|
|
- login({ commit }, userInfo) {
|
|
|
- const { username, password } = userInfo;
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- login({ username: username.trim(), password: password })
|
|
|
- .then((response) => {
|
|
|
- const { data } = response;
|
|
|
- if (response.code === 0) {
|
|
|
- commit("SET_TOKEN", data.token);
|
|
|
- setToken(data.token);
|
|
|
- }
|
|
|
- resolve(response);
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- reject(error);
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- dingUserInfor({ commit }, code) {
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
- dingdingdetail(code)
|
|
|
- .then((response) => {
|
|
|
- const { data } = response;
|
|
|
- if (response.code === 0) {
|
|
|
- commit("SET_TOKEN", data.token);
|
|
|
- setToken(data.token);
|
|
|
- resolve("success");
|
|
|
- } else {
|
|
|
- resolve("error");
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- reject(error);
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- async getMenuList({ commit, that }) {
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
- if (!getToken()) {
|
|
|
- resolve("noToken");
|
|
|
- } else {
|
|
|
- const { mcode, mdata, mmsg } = await getRoleMenuList();
|
|
|
- console.log(mdata);
|
|
|
- if (mcode >= 100 && mcode <= 104) {
|
|
|
- resolve("noToken");
|
|
|
- } else if (mcode !== 0) {
|
|
|
- resolve({ code: mcode, data: {}, massage: mmsg });
|
|
|
- } else {
|
|
|
- const { arrag } = mdata;
|
|
|
- // 生成页面权限
|
|
|
- commit("navListFn", arrag);
|
|
|
- // 生成路由
|
|
|
- initRouter(arrag, that);
|
|
|
- // state.commit("loginInfoCommit", res.data);
|
|
|
- resolve("success");
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- // user logout
|
|
|
- logout({ commit, state, dispatch }) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- commit("SET_TOKEN", "");
|
|
|
- commit("SET_ROLES", []);
|
|
|
- removeToken();
|
|
|
- commit("SET_MENU", "");
|
|
|
- commit("SET_HAS", "");
|
|
|
-
|
|
|
- removeMenu();
|
|
|
- // reset visited views and cached views
|
|
|
- // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
|
|
|
- dispatch("tagsView/delAllViews", null, { root: true });
|
|
|
- resolve();
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- // remove token
|
|
|
- resetToken({ commit }) {
|
|
|
- return new Promise((resolve) => {
|
|
|
- commit("SET_TOKEN", "");
|
|
|
- commit("SET_ROLES", []);
|
|
|
- removeToken();
|
|
|
- resolve();
|
|
|
- });
|
|
|
- },
|
|
|
-};
|
|
|
-
|
|
|
-async function getRoleMenuList() {
|
|
|
- let arrag = [
|
|
|
- {
|
|
|
- path: "/order",
|
|
|
- name: "/order",
|
|
|
- meta: {
|
|
|
- title: "业务管理",
|
|
|
- icon: 'el-icon-s-shop',
|
|
|
- },
|
|
|
- children: [],
|
|
|
- },
|
|
|
- ];
|
|
|
- configRouter.forEach((v1) => {
|
|
|
- const item = {
|
|
|
- path: v1.menu_route,
|
|
|
- name: v1.menu_route,
|
|
|
- hidden: parseInt(v1.is_display + "") === 0,
|
|
|
- alwaysShow: v1.alwaysShow,
|
|
|
- meta: {
|
|
|
- title: v1.menu_name,
|
|
|
- icon: v1.menu_img,
|
|
|
- noCache: v1.noCache,
|
|
|
- breadcrumb: v1.breadcrumb,
|
|
|
- },
|
|
|
- url: v1.menu_url,
|
|
|
- };
|
|
|
- arrag[0].children.push(item);
|
|
|
- // arrag.push(pItem);
|
|
|
- });
|
|
|
- return {
|
|
|
- mcode: 0,
|
|
|
- mdata: {
|
|
|
- arrag,
|
|
|
- },
|
|
|
- mmsg: "",
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-function initRouter(arr) {
|
|
|
- const IndexRoute = [];
|
|
|
-
|
|
|
- arr.map((v1) => {
|
|
|
- v1.component = (resolve) => require([`@/layout/index.vue`], resolve);
|
|
|
- if (v1.children && v1.children.length > 0) {
|
|
|
- v1.redirect = `${v1.path}/${v1.children[0].name}`;
|
|
|
- // v1.noCache= true;
|
|
|
- v1.children.map((v1) => {
|
|
|
- v1.component = (resolve) => require([`@/views/${v1.url}.vue`], resolve);
|
|
|
- return v1;
|
|
|
- });
|
|
|
- }
|
|
|
- return v1;
|
|
|
- });
|
|
|
- IndexRoute.push(...arr);
|
|
|
- IndexRoute.push({
|
|
|
- path: "404",
|
|
|
- component: () => import("@/views/error-page/404"),
|
|
|
- hidden: false,
|
|
|
- noCache: true,
|
|
|
- });
|
|
|
-
|
|
|
- IndexRoute.push({
|
|
|
- path: "*",
|
|
|
- redirect: "/404",
|
|
|
- });
|
|
|
- window.vm.$router.addRoutes(IndexRoute);
|
|
|
-}
|
|
|
-
|
|
|
-export default {
|
|
|
- namespaced: true,
|
|
|
- state,
|
|
|
- mutations,
|
|
|
- actions,
|
|
|
-};
|