Skip to content

Commit

Permalink
修改对接后端
Browse files Browse the repository at this point in the history
  • Loading branch information
wmhello committed Jan 7, 2020
1 parent 3bb8a26 commit 388cc32
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NODE_ENV=production
VUE_APP_PREVIEW=false
VUE_APP_API_BASE_URL=http://erp.ouenyione.com
VUE_APP_API_BASE_URL=http://backend.ouenyione.com
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NODE_ENV=development
VUE_APP_PREVIEW=true
VUE_APP_API_BASE_URL=http://erp.ouenyione.com
VUE_APP_API_BASE_URL=http://backend.ouenyione.com
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

## 2、前端:
> 1. 前端使用了antd for vue UI,请参照开发
> 2. html5主要演示了原生功能的使用
> 2. 演示html5功能的使用
## 3、项目演示
> 演示网站(http://wmhello.wicp.com)
> 管理员用户名和密码(admin/123456)
> 演示网站(http://wmhello.wicp.vip)
> 管理员用户名和密码(871228582@qq.com/123456)
## 4、项目截图

Expand Down
4 changes: 2 additions & 2 deletions src/config/router.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const asyncRouterMap = [
name: 'index',
component: BasicLayout,
meta: { title: '首页' },
redirect: '/dashboard/workplace',
redirect: '/dashboard/analysis',
children: [
// dashboard
{
path: '/dashboard',
name: 'dashboard',
redirect: '/dashboard/workplace',
redirect: '/dashboard/analysis',
component: RouteView,
meta: { title: '仪表盘', keepAlive: true, icon: bxAnaalyse, permission: [ 'dashboard' ] },
children: [
Expand Down
9 changes: 5 additions & 4 deletions src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ACCESS_TOKEN } from '@/store/mutation-types'
NProgress.configure({ showSpinner: false }) // NProgress Configuration

const whiteList = ['login', 'register', 'registerResult'] // no redirect whitelist
const defaultRoutePath = '/dashboard/workplace'
const defaultRoutePath = '/dashboard/analysis'

router.beforeEach((to, from, next) => {
NProgress.start() // start progress bar
Expand All @@ -22,12 +22,13 @@ router.beforeEach((to, from, next) => {
next({ path: defaultRoutePath })
NProgress.done()
} else {
if (store.getters.roles.length === 0) {
if (store.getters.roles.length === 0) {
store
.dispatch('GetInfo')
.then(res => {
const roles = res.data && res.data.role
store.dispatch('GenerateRoutes', { roles }).then(() => {
const roles = res && res.roles
const permissions = res && res.permissions
store.dispatch('GenerateRoutes', { roles, permissions }).then(() => {
// 根据roles权限生成可访问的路由表
// 动态添加可访问路由表
router.addRoutes(store.getters.addRouters)
Expand Down
101 changes: 78 additions & 23 deletions src/store/modules/permission.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { asyncRouterMap, constantRouterMap } from '@/config/router.config'
import router from '@/router/index'
import { template } from 'handlebars'

/**
* 过滤账户是否拥有某一个权限,并将菜单从加载列表移除
Expand All @@ -7,19 +9,19 @@ import { asyncRouterMap, constantRouterMap } from '@/config/router.config'
* @param route
* @returns {boolean}
*/
function hasPermission (permission, route) {
if (route.meta && route.meta.permission) {
let flag = false
for (let i = 0, len = permission.length; i < len; i++) {
flag = route.meta.permission.includes(permission[i])
if (flag) {
return true
}
}
return false
}
return true
}
// function hasPermission (permission, route) {
// if (route.meta && route.meta.permission) {
// let flag = false
// for (let i = 0, len = permission.length; i < len; i++) {
// flag = route.meta.permission.includes(permission[i])
// if (flag) {
// return true
// }
// }
// return false
// }
// return true
// }

/**
* 单账户多角色时,使用该方法可过滤角色不存在的菜单
Expand All @@ -37,19 +39,65 @@ function hasRole(roles, route) {
}
}

function filterAsyncRouter (routerMap, roles) {
const accessedRouters = routerMap.filter(route => {
if (hasPermission(roles.permissionList, route)) {
if (route.children && route.children.length) {
route.children = filterAsyncRouter(route.children, roles)
// function filterAsyncRouter (routerMap, roles) {
// let res = []
// routerMap.forEach( route => {
// const tmp = { ...route }
// if (hasPermission(roles, tmp)) {
// if (tmp.children) {
// tmp.children = filterAsyncRouter(tmp.children, roles)
// }
// res.push(tmp)
// }
// })
// return res
// // const accessedRouters = routerMap.filter(route => {
// // if (hasPermission(roles.permissionList, route)) {
// // if (route.children && route.children.length) {
// // route.children = filterAsyncRouter(route.children, roles)
// // }
// // return true
// // }
// // return false
// // })
// // return accessedRouters
// }

/**
* Use meta.role to determine if the current user has permission
* @param roles
* @param route
*/
function hasPermission(roles, route) {
if (route.meta && route.meta.permission) {
return roles.some(role => route.meta.permission.includes(role))
} else {
return false
}
}

/**
* Filter asynchronous routing tables by recursion
* @param routes asyncRoutes
* @param roles
*/
export function filterAsyncRoutes(routes, roles) {
const res = []

routes.forEach(route => {
const tmp = { ...route }
if (hasPermission(roles, tmp)) {
if (tmp.children) {
tmp.children = filterAsyncRoutes(tmp.children, roles)
}
return true
res.push(tmp)
}
return false
})
return accessedRouters

return res
}


const permission = {
state: {
routers: constantRouterMap,
Expand All @@ -64,8 +112,15 @@ const permission = {
actions: {
GenerateRoutes ({ commit }, data) {
return new Promise(resolve => {
const { roles } = data
const accessedRouters = filterAsyncRouter(asyncRouterMap, roles)
let { roles, permissions} = data

let accessedRouters
if (roles.includes('admin')){
accessedRouters = asyncRouterMap || []
} else {
// roles = roles.permissions
accessedRouters = filterAsyncRouter(asyncRouterMap, permissions)
}
commit('SET_ROUTERS', accessedRouters)
resolve()
})
Expand Down
13 changes: 6 additions & 7 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,26 @@ const user = {
GetInfo ({ commit }) {
return new Promise((resolve, reject) => {
getInfo().then(response => {
const result = response.data

if (result.role) {
const role = result.role
role.permissions = result.permission
const result = response
result.avatar = `${process.env.VUE_APP_API_BASE_URL}/${result.avatar}`
if (result.roles) {
const roles = result.roles
roles.permissions = result.permissions
// role.permissions.map(per => {
// if (per.actionEntitySet != null && per.actionEntitySet.length > 0) {
// const action = per.actionEntitySet.map(action => { return action.action })
// per.actionList = action
// }
// })
// role.permissionList = role.permissions.map(permission => { return permission.permissionId })
commit('SET_ROLES', result.role)
commit('SET_ROLES', roles)
commit('SET_INFO', result)
} else {
reject(new Error('getInfo: roles must be a non-null array !'))
}

commit('SET_NAME', { name: result.name, welcome: welcome() })
commit('SET_AVATAR', result.avatar)

resolve(response)
}).catch(error => {
reject(error)
Expand Down
18 changes: 3 additions & 15 deletions src/views/user/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
:form="form"
@submit="handleSubmit"
>
<a-alert v-if="isLoginError" type="error" showIcon style="margin-bottom: 24px;" message="账户或密码错误(admin/123456 )" />
<a-alert v-if="isLoginError" type="error" showIcon style="margin-bottom: 24px;" message="账户或密码错误(871228582@qq.com/123456 )" />
<a-form-item>
<a-input
size="large"
type="text"
placeholder="账户: admin"
placeholder="账户: 871228582@qq.com"
v-decorator="[
'email',
{rules: [{ required: true, message: '请输入登录名' }, { validator: handleUsernameOrEmail }], validateTrigger: 'change'}
Expand Down Expand Up @@ -192,19 +192,7 @@ export default {
})
},
loginSuccess (res) {
console.log(res)
// check res.homePage define, set $router.push name res.homePage
// Why not enter onComplete
/*
this.$router.push({ name: 'analysis' }, () => {
console.log('onComplete')
this.$notification.success({
message: '欢迎',
description: `${timeFix()},欢迎回来`
})
})
*/
this.$router.push({ path: '/' })
this.$router.push({path: '/dashboard/analysis'})
// 延迟 1 秒显示欢迎信息
setTimeout(() => {
this.$notification.success({
Expand Down

0 comments on commit 388cc32

Please sign in to comment.