Commit fba33186 by 姜雷

初始化菜单信息

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