后台项目总结
一.动态路由的添加
- 1.在首页请求权限菜单
openMenu(item = {}) {
this.$store.dispatch("GetMenu",{type: true,id: item.id}).then(data => {
if (data.length !== 0) {
this.$router.$avueRouter.formatRoutes(data, true);
}
});
},
- 2.动态添加路由
const RouterPlugin = function() {
this.$router = null
this.$store = null
}
RouterPlugin.install = function(router, store) {
this.$router = router
this.$store = store
function isURL(s) {
return /^http[s]?://.*/.test(s)
}
function objToform(obj) {
const result = []
Object.keys(obj).forEach(ele => {
result.push(`${ele}=${obj[ele]}`)
})
return result.join('&')
}
this.$router.$avueRouter = {
// 全局配置
$website: this.$store.getters.website,
routerList: [],
group: '',
safe: this,
// 设置标题
setTitle: function(title) {
title = title ? `${title}——${this.$website.title}` : this.$website.title
document.title = title
},
closeTag: (value) => {
const tag = value || this.$store.getters.tag
this.$store.commit('DEL_TAG', tag)
},
// 处理路由
getPath: function(params) {
const { src } = params
let result = src || '/'
if (src.includes('http') || src.includes('https')) {
result = `/myiframe/urlPath?${objToform(params)}`
}
return result
},
// 正则处理路由
vaildPath: function(list, path) {
let result = false
list.forEach(ele => {
if (new RegExp('^' + ele + '.*', 'g')