动态路由修改
This commit is contained in:
parent
0554c79f65
commit
0e62d9e1a4
|
@ -1,3 +1,4 @@
|
|||
NODE_ENV=development
|
||||
VUE_APP_PREVIEW=true
|
||||
VUE_APP_API_BASE_URL=/dawa
|
||||
VUE_APP_API_BASE_URL=/dawa
|
||||
VUE_APP_PUBLIC_PATH =/
|
|
@ -1,8 +1,8 @@
|
|||
<template>
|
||||
<a-dropdown v-if="currentUser && currentUser.name" placement="bottomRight">
|
||||
<a-dropdown v-if="currentUser && currentUser.userName" placement="bottomRight">
|
||||
<span class="ant-pro-account-avatar">
|
||||
<a-avatar size="small" src="https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png" class="antd-pro-global-header-index-avatar" />
|
||||
<span>{{ currentUser.name }}</span>
|
||||
<span>{{ currentUser.userName }}</span>
|
||||
</span>
|
||||
<template v-slot:overlay>
|
||||
<a-menu class="ant-pro-drop-down menu" :selected-keys="[]">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div :class="wrpCls">
|
||||
<avatar-dropdown :menu="showMenu" :current-user="currentUser" :class="prefixCls" />
|
||||
<select-lang :class="prefixCls" />
|
||||
<!-- <select-lang :class="prefixCls" /> -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -49,9 +49,7 @@ export default {
|
|||
},
|
||||
mounted () {
|
||||
setTimeout(() => {
|
||||
this.currentUser = {
|
||||
name: 'Serati Ma'
|
||||
}
|
||||
this.currentUser = this.$store.getters.userInfo || { userName: '***' }
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
import Vue from 'vue'
|
||||
import router from './router'
|
||||
import store from './store'
|
||||
import storage from 'store'
|
||||
import storage from 'store'
|
||||
|
||||
import NProgress from 'nprogress' // progress bar
|
||||
import '@/components/NProgress/nprogress.less' // progress bar custom style
|
||||
import notification from 'ant-design-vue/es/notification'
|
||||
import { setDocumentTitle, domTitle } from '@/utils/domUtil'
|
||||
import { ACCESS_TOKEN } from '@/store/mutation-types'
|
||||
import { i18nRender } from '@/locales'
|
||||
|
||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||
|
||||
import { Modal } from 'ant-design-vue' // NProgress Configuration
|
||||
NProgress.configure({ showSpinner: false })
|
||||
const whiteList = ['login', 'register', 'registerResult'] // no redirect whitelist
|
||||
const loginRoutePath = '/user/login'
|
||||
const defaultRoutePath = '/dashboard/workplace'
|
||||
// 无默认首页的情况
|
||||
const defaultRoutePath = '/welcome'
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start() // start progress bar
|
||||
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${i18nRender(to.meta.title)} - ${domTitle}`))
|
||||
console.log(storage.get(ACCESS_TOKEN))
|
||||
debugger
|
||||
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`))
|
||||
if (storage.get(ACCESS_TOKEN)) {
|
||||
if (to.path === loginRoutePath) {
|
||||
next({ path: defaultRoutePath })
|
||||
|
@ -42,7 +41,6 @@ router.beforeEach((to, from, next) => {
|
|||
return
|
||||
}
|
||||
const antDesignMenus = res.menus
|
||||
// generate dynamic router
|
||||
store.dispatch('GenerateRoutes', { antDesignMenus }).then(() => {
|
||||
// 根据菜单权限生成可访问的路由表
|
||||
// 动态添加可访问路由表
|
||||
|
@ -51,12 +49,14 @@ router.beforeEach((to, from, next) => {
|
|||
const element = routes[i];
|
||||
router.addRoute(element);
|
||||
}
|
||||
// router.addRoutes(store.getters.addRouters) router.addRoutes方法被遗弃
|
||||
// router.addRoutes方法被遗弃
|
||||
// router.addRoutes(store.getters.addRouters)
|
||||
|
||||
// 请求带有 redirect 重定向时,登录自动重定向到该地址
|
||||
const redirect = decodeURIComponent(from.query.redirect || to.path)
|
||||
if (to.path === redirect) {
|
||||
next({ path: redirect })
|
||||
// set the replace: true so the navigation will not leave a history record
|
||||
// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
|
||||
next({ ...to, replace: true })
|
||||
} else {
|
||||
// 跳转到目的路由
|
||||
|
|
|
@ -12,7 +12,6 @@ Router.prototype.push = function push (location, onResolve, onReject) {
|
|||
Vue.use(Router)
|
||||
|
||||
export default new Router({
|
||||
mode: 'history',
|
||||
base: process.env.VUE_APP_PUBLIC_PATH,
|
||||
mode: 'hash',
|
||||
routes: constantRouterMap
|
||||
})
|
||||
|
|
|
@ -45,7 +45,7 @@ const user = {
|
|||
commit('SET_TOKEN', response.token)
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
reject('后端未启动或代理错误')
|
||||
})
|
||||
})
|
||||
},
|
||||
|
@ -65,8 +65,7 @@ const user = {
|
|||
}
|
||||
resolve(data)
|
||||
} else {
|
||||
// eslint-disable-next-line no-undef
|
||||
reject(new Error(data.message))
|
||||
reject(new Error(data.msg))
|
||||
}
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
|
@ -85,6 +84,7 @@ const user = {
|
|||
commit('SET_TOKEN', '')
|
||||
commit('SET_ROLES', [])
|
||||
commit('SET_BUTTONS', [])
|
||||
commit('SET_ROUTERS', [])
|
||||
storage.remove(ACCESS_TOKEN)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
</div>
|
||||
|
||||
<div class="table-operator">
|
||||
<a-button type="primary" icon="plus" @click="$refs.menuForm.add()">新增菜单</a-button>
|
||||
<a-button v-if="hasPerm('sys:menu:add')" type="primary" icon="plus" @click="$refs.menuForm.add()">新增菜单</a-button>
|
||||
</div>
|
||||
|
||||
<s-table
|
||||
|
@ -43,9 +43,9 @@
|
|||
</span>
|
||||
<span slot="action" slot-scope="text, record">
|
||||
<template>
|
||||
<a @click="$refs.menuForm.edit(record)">编辑</a>
|
||||
<a-divider type="vertical"/>
|
||||
<a-popconfirm placement="topRight" title="删除本菜单与下级?" @confirm="() => handleDel(record)">
|
||||
<a v-if="hasPerm('sys:menu:edit')" @click="$refs.menuForm.edit(record)">编辑</a>
|
||||
<a-divider type="vertical" v-if="hasPerm('sys:menu:edit')" />
|
||||
<a-popconfirm v-if="hasPerm('sys:menu:delete')" placement="topRight" title="删除本菜单与下级?" @confirm="() => handleDel(record)">
|
||||
<a>删除</a>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
|
@ -100,12 +100,6 @@ export default {
|
|||
{
|
||||
title: '排序',
|
||||
dataIndex: 'intCode'
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
dataIndex: 'action',
|
||||
width: '150px',
|
||||
scopedSlots: { customRender: 'action' }
|
||||
}
|
||||
],
|
||||
loadData: parameter => {
|
||||
|
@ -117,15 +111,15 @@ export default {
|
|||
}
|
||||
},
|
||||
created () {
|
||||
// 根据权限加载,待处理
|
||||
// if (this.hasPerm('sysMenu:edit') || this.hasPerm('sysMenu:delete')) {
|
||||
// this.columns.push({
|
||||
// title: '操作',
|
||||
// dataIndex: 'action',
|
||||
// width: '150px',
|
||||
// scopedSlots: { customRender: 'action' }
|
||||
// })
|
||||
// }
|
||||
// 根据权限加载
|
||||
if (this.hasPerm('sys:menu:edit') || this.hasPerm('sys:menu:delete')) {
|
||||
this.columns.push({
|
||||
title: '操作',
|
||||
dataIndex: 'action',
|
||||
width: '150px',
|
||||
scopedSlots: { customRender: 'action' }
|
||||
})
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
typeFilter (type) {
|
||||
|
|
|
@ -163,7 +163,7 @@
|
|||
_this.$emit('ok', values)
|
||||
_this.handleCancel()
|
||||
} else {
|
||||
_this.$message.error('授权失败:' + res.message)
|
||||
_this.$message.error('授权失败:' + res.msg)
|
||||
}
|
||||
}).finally((res) => {
|
||||
_this.confirmLoading = false
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
<a-row :gutter="24">
|
||||
<a-col :md="6" :sm="24">
|
||||
<a-form-item label="用户名称" >
|
||||
<a-input v-model="queryParam.userName" placeholder="请输入用户名称"/>
|
||||
<a-input v-model="queryParam.name" placeholder="请输入用户名称"/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :md="6" :sm="24">
|
||||
<a-form-item label="账号" >
|
||||
<a-input v-model="queryParam.loginName" placeholder="请输入账号"/>
|
||||
<a-input v-model="queryParam.userName" placeholder="请输入账号"/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :md="6" :sm="24">
|
||||
<a-form-item label="手机号码" >
|
||||
<a-input v-model="queryParam.phoneNumber" placeholder="请输入手机号码"/>
|
||||
<a-input v-model="queryParam.phone" placeholder="请输入手机号码"/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :md="4" :sm="24">
|
||||
|
@ -47,7 +47,7 @@
|
|||
</span>
|
||||
<span slot="action" slot-scope="text, record">
|
||||
<a v-if="hasPerm('sys:user:edit')" @click="$refs.userForm.edit(record)">编辑</a>
|
||||
<a-divider type="vertical" v-if="hasPerm('sysUser:edit')" />
|
||||
<a-divider type="vertical" v-if="hasPerm('sys:user:edit')" />
|
||||
<a-dropdown v-if="hasPerm('sys:user:resetPwd') || hasPerm('sys:user:grantRole') || hasPerm('sys:user:delete')">
|
||||
<a class="ant-dropdown-link">
|
||||
更多 <a-icon type="down" />
|
||||
|
@ -95,11 +95,11 @@ export default {
|
|||
columns: [
|
||||
{
|
||||
title: '账号',
|
||||
dataIndex: 'loginName'
|
||||
dataIndex: 'userName'
|
||||
},
|
||||
{
|
||||
title: '姓名',
|
||||
dataIndex: 'userName'
|
||||
dataIndex: 'name'
|
||||
},
|
||||
{
|
||||
title: '昵称',
|
||||
|
@ -111,7 +111,7 @@ export default {
|
|||
scopedSlots: { customRender: 'sex' }
|
||||
}, {
|
||||
title: '手机',
|
||||
dataIndex: 'phoneNumber'
|
||||
dataIndex: 'phone'
|
||||
}
|
||||
],
|
||||
// 加载数据方法 必须为 Promise 对象
|
||||
|
@ -155,7 +155,7 @@ export default {
|
|||
this.$message.success('重置成功')
|
||||
// this.$refs.table.refresh()
|
||||
} else {
|
||||
this.$message.error('重置失败:' + res.message)
|
||||
this.$message.error('重置失败:' + res.msg)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -176,10 +176,10 @@ export default {
|
|||
this.$message.success('删除成功')
|
||||
this.$refs.table.refresh()
|
||||
} else {
|
||||
this.$message.error('删除失败:' + res.message)
|
||||
this.$message.error('删除失败:' + res.msg)
|
||||
}
|
||||
}).catch((err) => {
|
||||
this.$message.error('删除错误:' + err.message)
|
||||
this.$message.error('删除错误:' + err.msg)
|
||||
})
|
||||
},
|
||||
handleOk () {
|
||||
|
|
|
@ -97,7 +97,7 @@
|
|||
this.$emit('ok', this.recordEntity)
|
||||
this.handleCancel()
|
||||
} else {
|
||||
this.$message.error('授权失败:' + res.message)
|
||||
this.$message.error('授权失败:' + res.msg)
|
||||
}
|
||||
}).finally((res) => {
|
||||
this.confirmLoading = false
|
||||
|
|
|
@ -102,12 +102,12 @@ const vueConfig = {
|
|||
// 如果需要开启代理,请移除mockjs /src/main.jsL11
|
||||
proxy: {
|
||||
'/dawa': { // 捕获API的标志,如果API中有这个字符串,那么就开始匹配代理
|
||||
target: 'http://a.3a6.cn/', // 地址可以是域名,也可以是IP地址。比如API请求/api/getList, 会被代理到请求http://www.baidu.com/api/getList 。
|
||||
target: 'http://localhost:8080/', // 地址可以是域名,也可以是IP地址。比如API请求/api/getList, 会被代理到请求http://www.baidu.com/api/getList 。
|
||||
ws: false,
|
||||
changeOrigin: true // 如果target是域名需要额外添加一个参数changeOrigin: true,否则会代理失败。
|
||||
// , pathRewrite: {
|
||||
// '^/dawa': '/'
|
||||
// }
|
||||
, pathRewrite: {
|
||||
'^/dawa': '/'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue