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