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) let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
const first = matched[0] const first = matched[0]
if (!this.isDashboard(first)) { /* if (!this.isDashboard(first)) {
matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched) matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched)
} }*/
this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false) 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> <template>
<div class="sidebar-logo-container" :class="{'collapse':collapse}" :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }"> <div class="sidebar-logo-container" :class="{'collapse':collapse}" :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
<transition name="sidebarLogoFade"> <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" /> <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> <h1 v-else class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1>
</router-link> </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" /> <img v-if="logo" :src="logo" class="sidebar-logo" />
<h1 class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1> <h1 class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1>
</router-link> </router-link>
@ -16,7 +16,7 @@
<script> <script>
import logoImg from '@/assets/logo/logo.png' import logoImg from '@/assets/logo/logo.png'
import variables from '@/assets/styles/variables.scss' import variables from '@/assets/styles/variables.scss'
import {mapState} from 'vuex'
export default { export default {
name: 'SidebarLogo', name: 'SidebarLogo',
props: { props: {
@ -31,7 +31,10 @@ export default {
}, },
sideTheme() { sideTheme() {
return this.$store.state.settings.sideTheme return this.$store.state.settings.sideTheme
} },
...mapState({
indexPage: state => state.permission.indexPage
})
}, },
data() { data() {
return { return {

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

@ -31,6 +31,7 @@
<script> <script>
import ScrollPane from './ScrollPane' import ScrollPane from './ScrollPane'
import path from 'path' import path from 'path'
import {mapState} from 'vuex'
export default { export default {
components: { ScrollPane }, components: { ScrollPane },
@ -52,7 +53,10 @@ export default {
}, },
theme() { theme() {
return this.$store.state.settings.theme; return this.$store.state.settings.theme;
} },
...mapState({
indexPage: state => state.permission.indexPage
})
}, },
watch: { watch: {
$route() { $route() {
@ -83,7 +87,11 @@ export default {
}; };
}, },
isAffix(tag) { isAffix(tag) {
return tag.meta && tag.meta.affix if (tag.fullPath == this.indexPage) {
return true
} else {
return tag.meta && tag.meta.affix
}
}, },
isFirstView() { isFirstView() {
try { try {
@ -200,7 +208,7 @@ export default {
// to reload home page // to reload home page
this.$router.replace({ path: '/redirect' + view.fullPath }) this.$router.replace({ path: '/redirect' + view.fullPath })
} else { } 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 => { store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表 // 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表 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 => { }).catch(err => {
store.dispatch('LogOut').then(() => { store.dispatch('LogOut').then(() => {
Message.error(err) Message.error(err)

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

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

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

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

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

@ -11,7 +11,8 @@ const permission = {
addRoutes: [], addRoutes: [],
defaultRoutes: [], defaultRoutes: [],
topbarRouters: [], topbarRouters: [],
sidebarRouters: [] sidebarRouters: [],
indexPage: '',
}, },
mutations: { mutations: {
SET_ROUTES: (state, routes) => { SET_ROUTES: (state, routes) => {
@ -29,6 +30,9 @@ const permission = {
}] }]
state.topbarRouters = routes.concat(index); state.topbarRouters = routes.concat(index);
}, },
SET_INDEX_PAGE: (state, routes) => {
state.indexPage = routes
},
SET_SIDEBAR_ROUTERS: (state, routes) => { SET_SIDEBAR_ROUTERS: (state, routes) => {
state.sidebarRouters = routes state.sidebarRouters = routes
}, },
@ -38,9 +42,23 @@ const permission = {
GenerateRoutes({ commit }) { GenerateRoutes({ commit }) {
return new Promise(resolve => { return new Promise(resolve => {
// 向后端请求路由数据 // 向后端请求路由数据
getRouters(1).then(res => { getRouters().then(res => {
const sdata = JSON.parse(JSON.stringify(res.data)) const sdata = JSON.parse(JSON.stringify(res.data))
const rdata = 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 sidebarRoutes = filterAsyncRouter(sdata)
const rewriteRoutes = filterAsyncRouter(rdata, false, true) const rewriteRoutes = filterAsyncRouter(rdata, false, true)
const asyncRoutes = filterDynamicRoutes(dynamicRoutes); const asyncRoutes = filterDynamicRoutes(dynamicRoutes);
@ -50,6 +68,7 @@ const permission = {
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
commit('SET_DEFAULT_ROUTES', sidebarRoutes) commit('SET_DEFAULT_ROUTES', sidebarRoutes)
commit('SET_TOPBAR_ROUTES', sidebarRoutes) commit('SET_TOPBAR_ROUTES', sidebarRoutes)
commit('SET_INDEX_PAGE', indexdata)
resolve(rewriteRoutes) resolve(rewriteRoutes)
}) })
}) })

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

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

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

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

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

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

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

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

Loading…
Cancel
Save