Commit fba33186 by 姜雷

初始化菜单信息

parent 3d1a7644
......@@ -38,12 +38,12 @@ service.interceptors.request.use(
service.interceptors.response.use(response => {
const res = response.data;
/**
* code为非'0'是抛错
* code为非'1000'是抛错
*/
setTimeout(() => {
store.dispatch('fetchDone');
}, 500);
if (res.code !== '0') {
if (res.code !== 1000) {
if (
response.headers &&
response.headers['content-type'] === 'application/octet-stream'
......
......@@ -3,11 +3,9 @@ import fetch from '@/api/fetch';
// 登录
export const login = entity =>
fetch({
url: '/login/manager/login.do',
method: 'post',
data: {
...entity,
},
withCredentials: true,
data: entity,
});
// 登出
export const logout = () =>
......
export default {
SERVER_URL: '', // DEV
SERVER_URL: 'http://192.168.1.33:8888', // DEV
TOKEN_KEY: 'Admin-Token',
};
import constants from './constants';
export const PAGE_TITLE = '管理系统';
export const RYM_GZKEY = 'dc2017';
export const IMG_URL = 'http://qiniu.dcrym.com/';
export const CONSTANTS = constants;
......
<template>
<div>publicCarNumber</div>
</template>
<template>
<div>publicCarType</div>
</template>
<template>
<div>repairArea</div>
</template>
<template>
<div>repairProject</div>
</template>
......@@ -4,7 +4,7 @@
<div class="com-logo">
<img src="../../assets/images/logo.png" alt="logo">
</div>
<h1 class="com-title">管理系统</h1>
<h1 class="com-title">{{title}}</h1>
<UserBox></UserBox>
</div>
<div>
......@@ -60,6 +60,7 @@ import {
TagsView,
UserBox,
} from '@/containers/layout/components';
import { PAGE_TITLE } from '@/config';
export default {
name: 'layout',
......@@ -70,6 +71,11 @@ export default {
TagsView,
UserBox,
},
data() {
return {
title: PAGE_TITLE,
};
},
computed: {
sidebar() {
return this.$store.state.app.sidebar;
......
<template>
<div class="login-container">
<el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left" label-width="0px" class="card-box login-form">
<h3 class="title">多彩校园综合管理系统</h3>
<h3 class="title">{{title}}</h3>
<el-form-item prop="username">
<span class="svg-container svg-container_login">
<svg-icon icon-class="user" />
......@@ -32,7 +32,8 @@
<script>
import { isvalidUsername } from '@/utils/validate';
import { mapActions } from 'vuex';
import { mapActions, mapGetters } from 'vuex';
import { PAGE_TITLE } from '@/config';
export default {
name: 'login',
......@@ -52,6 +53,7 @@ export default {
}
};
return {
title: PAGE_TITLE,
loginForm: {
name: '',
password: '',
......@@ -64,10 +66,12 @@ export default {
{ required: true, trigger: 'blur', validator: validatePass },
],
},
loading: false,
pwdType: 'password',
};
},
computed: {
...mapGetters(['loading']),
},
methods: {
...mapActions(['Login']),
showPwd() {
......@@ -80,15 +84,13 @@ export default {
handleLogin() {
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true;
this.Login(this.loginForm)
.then(() => {
console.log('login done');
this.loading = false;
this.$router.push({ path: '/' });
})
.catch(() => {
this.loading = false;
.catch(err => {
console.log(err);
});
} else {
console.log('error submit!!');
......
<template>
<div>account</div>
</template>
<template>
<div>wx</div>
</template>
......@@ -11,9 +11,12 @@ import store from './store';
import '@/assets/styles/index.scss'; // global css
import '@/assets/icons'; // icon
import '@/permission' // 用户登录认证
import '@/permission'; // 用户登录认证
// import './mock' // mockjs
import extendCom from '@/utils/extends';
import { PAGE_TITLE } from '@/config';
document.title = PAGE_TITLE;
Vue.use(ElementUI);
extendCom(Vue);
......
......@@ -22,12 +22,12 @@ router.beforeEach((to, from, next) => {
store
.dispatch('GenerateRoutes')
.then(() => {
router.addRoutes(store.getters.addRouters.slice()); // 动态添加可访问路由表
router.addRoutes(store.getters.addRouters); // 动态添加可访问路由表
next({ ...to, replace: true });
})
.catch((err) => {
console.log('验证失败,请重新登录')
console.log(err)
.catch(err => {
console.log('验证失败,请重新登录');
console.log(err);
store.dispatch('FedLogOut').then(() => {
// Message.error('验证失败,请重新登录');
next({ path: '/login' });
......@@ -39,8 +39,7 @@ router.beforeEach((to, from, next) => {
if (whiteList.indexOf(to.path) !== -1) {
next();
} else {
// next('/login');
next();
next('/login');
NProgress.done();
}
}
......
const _import = require('./_import_' + process.env.NODE_ENV);
const systemRoutes = [
{
id: 7,
component: _import('baseData/repairArea/repairArea'),
},
{
id: 8,
component: _import('baseData/repairProject/repairProject'),
},
{
id: 9,
component: _import('baseData/publicCarType/publicCarType'),
},
{
id: 10,
component: _import('baseData/publicCarNumber/publicCarNumber'),
},
];
export default systemRoutes;
......@@ -4,6 +4,7 @@ import Layout from '../containers/layout/Layout.vue';
import Login from '@/containers/login/index';
import errorPage404 from '@/containers/errorPage/404';
import errorPage401 from '@/containers/errorPage/401';
import systemRoute from './system';
const _import = require('./_import_' + process.env.NODE_ENV);
......@@ -35,6 +36,7 @@ export const asyncRouterMap = [
component: Layout,
meta: { icon: 'example' },
},
...systemRoute,
{ path: '*', redirect: '/404', hidden: true },
];
......
const _import = require('./_import_' + process.env.NODE_ENV);
const systemRoutes = [
{
id: 11,
component: _import('system/wxAuth/wxAuth'),
},
{
id: 12,
component: _import('system/account/account'),
},
];
export default systemRoutes;
......@@ -13,7 +13,7 @@ const store = new Vuex.Store({
app,
user,
},
strict: debug,
// strict: debug,
plugins: debug ? [createLogger()] : [],
});
export default store;
......@@ -3,7 +3,7 @@ import sidebar from './sidebar';
import { FETCH_START, FETCH_DONE } from './mutation-types';
const state = () => ({
loading: true,
loading: false,
});
const getters = {
......
......@@ -21,17 +21,24 @@ const getters = {
const actions = {
// 登录
Login({ commit, dispatch }, entity) {
return login(entity).then(response => {
const {
token,
userInfo: { menus, ...others },
} = response.data;
setToken(token);
commit(SET_TOKEN, token);
commit(UPDATE_USERINFO, others);
dispatch('initRoute', menus).then(() => {
return new Promise((resolve, reject) => {
login(entity)
.then(response => {
const { admin, menu } = response.data;
console.log(admin, menu);
// setToken(token);
setToken('token');
// commit(SET_TOKEN, token);
commit(SET_TOKEN, 'token');
commit(UPDATE_USERINFO, admin);
dispatch('initRoute', menu).then(() => {
resolve();
});
})
.catch(error => {
reject(error);
});
});
},
......@@ -40,7 +47,6 @@ const actions = {
return logout(state.token).then(() => {
commit(SET_TOKEN, '');
removeToken();
resolve();
});
},
......@@ -70,6 +76,7 @@ const mutations = {
[UPDATE_USERINFO](state, userInfo) {
state = Object.assign(state, {
...userInfo,
loginState: 1,
});
},
};
......
......@@ -3,6 +3,7 @@ import { INIT_ROUTERS, SET_ROUTERS, ROUTERS_DONE } from './mutation-types';
import cloneDeep from 'lodash/cloneDeep';
let initRouter = cloneDeep(constantRouterMap);
const filterAsyncRouter = () => {};
const state = {
......@@ -28,15 +29,15 @@ const actions = {
if (mainMenu) {
const { children, ...routeMenu } = mainMenu;
let subMenuList = [];
if (item.children && item.children.length) {
item.children.map(subItem => {
if (item.childList && item.childList.length) {
item.childList.map(subItem => {
const subMenu = asyncRouterMap.find(
menu => menu.id === subItem.id
);
if (subMenu) {
subMenuList.push({
...subMenu,
path: subItem.menuLink,
path: subItem.menuUrl,
name: subItem.id,
meta: {
...subMenu.meta,
......@@ -49,7 +50,7 @@ const actions = {
}
authList.push({
...routeMenu,
path: '/' + item.menuLink,
path: item.menuUrl,
name: item.menuName,
meta: { ...routeMenu.meta, title: item.menuName },
children: subMenuList,
......@@ -83,7 +84,7 @@ const actions = {
const mutations = {
[SET_ROUTERS](state, routers) {
state.addRouters = routers.slice();
state.addRouters = routers;
state.routers = initRouter.concat(routers);
},
[ROUTERS_DONE](state) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment