Browse Source

去除首页,加载第一个动态路由

develop
王兴琳 3 weeks ago
parent
commit
1e1ffaa4c5
  1. 4
      ruoyi-ui/src/components/Breadcrumb/index.vue
  2. 11
      ruoyi-ui/src/layout/components/Sidebar/Logo.vue
  3. 14
      ruoyi-ui/src/layout/components/TagsView/index.vue
  4. 25
      ruoyi-ui/src/permission.js
  5. 3
      ruoyi-ui/src/plugins/tab.js
  6. 4
      ruoyi-ui/src/router/index.js
  7. 23
      ruoyi-ui/src/store/modules/permission.js
  8. 3
      ruoyi-ui/src/utils/request.js
  9. 8
      ruoyi-ui/src/views/error/401.vue
  10. 20
      ruoyi-ui/src/views/index.vue
  11. 2
      ruoyi-ui/src/views/login.vue

4
ruoyi-ui/src/components/Breadcrumb/index.vue

@ -34,9 +34,9 @@ export default {
let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
const first = matched[0]
if (!this.isDashboard(first)) {
/* if (!this.isDashboard(first)) {
matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched)
}
}*/
this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
},

11
ruoyi-ui/src/layout/components/Sidebar/Logo.vue

@ -1,11 +1,11 @@
<template>
<div class="sidebar-logo-container" :class="{'collapse':collapse}" :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
<transition name="sidebarLogoFade">
<router-link v-if="collapse" key="collapse" class="sidebar-logo-link" to="/">
<router-link v-if="collapse" key="collapse" class="sidebar-logo-link" :to="indexPage">
<img v-if="logo" :src="logo" class="sidebar-logo" />
<h1 v-else class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1>
</router-link>
<router-link v-else key="expand" class="sidebar-logo-link" to="/">
<router-link v-else key="expand" class="sidebar-logo-link" :to="indexPage">
<img v-if="logo" :src="logo" class="sidebar-logo" />
<h1 class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1>
</router-link>
@ -16,7 +16,7 @@
<script>
import logoImg from '@/assets/logo/logo.png'
import variables from '@/assets/styles/variables.scss'
import {mapState} from 'vuex'
export default {
name: 'SidebarLogo',
props: {
@ -31,7 +31,10 @@ export default {
},
sideTheme() {
return this.$store.state.settings.sideTheme
}
},
...mapState({
indexPage: state => state.permission.indexPage
})
},
data() {
return {

14
ruoyi-ui/src/layout/components/TagsView/index.vue

@ -31,6 +31,7 @@
<script>
import ScrollPane from './ScrollPane'
import path from 'path'
import {mapState} from 'vuex'
export default {
components: { ScrollPane },
@ -52,7 +53,10 @@ export default {
},
theme() {
return this.$store.state.settings.theme;
}
},
...mapState({
indexPage: state => state.permission.indexPage
})
},
watch: {
$route() {
@ -83,7 +87,11 @@ export default {
};
},
isAffix(tag) {
return tag.meta && tag.meta.affix
if (tag.fullPath == this.indexPage) {
return true
} else {
return tag.meta && tag.meta.affix
}
},
isFirstView() {
try {
@ -200,7 +208,7 @@ export default {
// to reload home page
this.$router.replace({ path: '/redirect' + view.fullPath })
} else {
this.$router.push('/')
this.$router.push(this.indexPage)
}
}
},

25
ruoyi-ui/src/permission.js

@ -27,8 +27,29 @@ router.beforeEach((to, from, next) => {
store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
})
let path = '';
path = accessRoutes[0].path + accessRoutes[0].children[0].path //获取第一路由路径
if (accessRoutes[0].children[0].query !== undefined) { //如果当前路由存在路由参数,则带入
let query = JSON.parse(accessRoutes[0].children[0].query);
let temp = '';
for (var val in query) {
if (temp.length == 0) {
temp = "?";
} else {
temp = temp + "&";
}
temp = temp + val + "=" + query[val];
}
path = path + temp;
}
var temp = {...to, replace: true};
var curPath = temp.path;
if (from.path == '/login' || curPath == "/" ) {
next({path, replace: true}) // hack方法 确保addRoutes已完成
} else {
next(temp) // hack方法 确保addRoutes已完成
} })
}).catch(err => {
store.dispatch('LogOut').then(() => {
Message.error(err)

3
ruoyi-ui/src/plugins/tab.js

@ -31,9 +31,10 @@ export default {
},
// 关闭指定tab页签
closePage(obj) {
let indexPage = store.state.permission.indexPage;
if (obj === undefined) {
return store.dispatch('tagsView/delView', router.currentRoute).then(({ lastPath }) => {
return router.push(lastPath || '/');
return router.push(lastPath || indexPage);
});
}
return store.dispatch('tagsView/delView', obj);

4
ruoyi-ui/src/router/index.js

@ -68,7 +68,7 @@ export const constantRoutes = [
hidden: true
},
/** 支付路由结束 */
{
/* {
path: '',
component: Layout,
redirect: 'index',
@ -80,7 +80,7 @@ export const constantRoutes = [
meta: { title: '首页', icon: 'dashboard', affix: true }
}
]
},
},*/
{
path: '/user',
component: Layout,

23
ruoyi-ui/src/store/modules/permission.js

@ -11,7 +11,8 @@ const permission = {
addRoutes: [],
defaultRoutes: [],
topbarRouters: [],
sidebarRouters: []
sidebarRouters: [],
indexPage: '',
},
mutations: {
SET_ROUTES: (state, routes) => {
@ -29,6 +30,9 @@ const permission = {
}]
state.topbarRouters = routes.concat(index);
},
SET_INDEX_PAGE: (state, routes) => {
state.indexPage = routes
},
SET_SIDEBAR_ROUTERS: (state, routes) => {
state.sidebarRouters = routes
},
@ -38,9 +42,23 @@ const permission = {
GenerateRoutes({ commit }) {
return new Promise(resolve => {
// 向后端请求路由数据
getRouters(1).then(res => {
getRouters().then(res => {
const sdata = JSON.parse(JSON.stringify(res.data))
const rdata = JSON.parse(JSON.stringify(res.data))
let indexdata = res.data[0].path + "/" + res.data[0].children[0].path
if (res.data[0].children[0].query !== undefined) { //如果当前路由存在路由参数,则带入
let query = JSON.parse(res.data[0].children[0].query);
let temp = '';
for (var val in query) {
if (temp.length == 0) {
temp = "?";
} else {
temp = temp + "&";
}
temp = temp + val + "=" + query[val];
}
indexdata = indexdata + temp;
}
const sidebarRoutes = filterAsyncRouter(sdata)
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
const asyncRoutes = filterDynamicRoutes(dynamicRoutes);
@ -50,6 +68,7 @@ const permission = {
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
commit('SET_TOPBAR_ROUTES', sidebarRoutes)
commit('SET_INDEX_PAGE', indexdata)
resolve(rewriteRoutes)
})
})

3
ruoyi-ui/src/utils/request.js

@ -103,7 +103,8 @@ service.interceptors.response.use(res => {
).then(() => {
isRelogin.show = false;
store.dispatch('LogOut').then(() => {
location.href = '/index';
let indexurl = store.state.permission.indexPage
location.href = indexurl;
})
}).catch(() => {
isRelogin.show = false;

8
ruoyi-ui/src/views/error/401.vue

@ -12,7 +12,7 @@
<h6>对不起您没有访问权限请不要进行非法操作您可以返回主页面</h6>
<ul class="list-unstyled">
<li class="link-type">
<router-link to="/">
<router-link :to="indexPage">
回首页
</router-link>
</li>
@ -27,6 +27,7 @@
<script>
import errGif from '@/assets/401_images/401.gif'
import {mapState} from "vuex";
export default {
name: 'Page401',
@ -35,6 +36,11 @@ export default {
errGif: errGif + '?' + +new Date()
}
},
computed: {
...mapState({
indexPage: state => state.permission.indexPage
}),
},
methods: {
back() {
if (this.$route.query.noGoBack) {

20
ruoyi-ui/src/views/index.vue

@ -701,7 +701,7 @@ export default {
/************************************ 设备消息 **************************************/
/** 时间按钮选项 */
timeDimensionChange() {
/*if (this.messageMonitorTimeDimension === 'day') {
if (this.messageMonitorTimeDimension === 'day') {
this.messageMonitorTimePick = this.getTodayTime()
const params = {
time: '1h',
@ -763,7 +763,7 @@ export default {
this.getMessageMonitorData(params, 'received_message')
this.getMessageMonitorData(params, 'sent_message')
}*/
}
},
/** 设备消息char初始化 */
@ -1056,11 +1056,17 @@ export default {
</script>
<style lang="scss" scoped>
.meter-chart {
height: 200px;
}
.meter-title {
font-size: 20px
.app-container {
padding: 20px 5px 10px 5px;
.meter-chart {
height: 200px;
}
.meter-title {
font-size: 20px
}
}
</style>

2
ruoyi-ui/src/views/login.vue

@ -200,7 +200,7 @@ export default {
Cookies.remove("password");
Cookies.remove("rememberMe");
}
if(this.captchaOnOff && 'behavioral' === this.captchaType){
this.$refs.verify.show();
}else{

Loading…
Cancel
Save