Browse Source

修复财务管理左侧菜单树形图的数据由后台接口返回的参数中获取

master
yunuo970428 3 years ago
parent
commit
1b02517728
  1. 12
      anrui-buscenter/anrui-finmanage-ui/src/api/system/Role/role.js
  2. 17
      anrui-buscenter/anrui-finmanage-ui/src/layout/components/Sidebar/SidebarItem.vue
  3. 128
      anrui-buscenter/anrui-finmanage-ui/src/layout/components/Sidebar/index.vue

12
anrui-buscenter/anrui-finmanage-ui/src/api/system/Role/role.js

@ -32,3 +32,15 @@ export function sourcesofrole(data) {
headers: {'Content-Type': 'application/json'} headers: {'Content-Type': 'application/json'}
}) })
} }
// 根据token值获取登录后的用户信息
export function loginDetails(data) {
return request({
url: '/portal/v1/sysuser/loginDetails',
method: 'post',
data: data,
headers: {
'Content-Type': 'application/json'
}
})
}

17
anrui-buscenter/anrui-finmanage-ui/src/layout/components/Sidebar/SidebarItem.vue

@ -1,13 +1,12 @@
<template> <template>
<div v-if="!item.hidden"> <div v-if="!item.hidden">
<template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow"> <template v-if="hasOneShowingChild(item.children,item)">
<app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)"> <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}"> <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title" /> <item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title" />
</el-menu-item> </el-menu-item>
</app-link> </app-link>
</template> </template>
<el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body> <el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body>
<template slot="title"> <template slot="title">
<item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" /> <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
@ -54,12 +53,15 @@ export default {
// To fix https://github.com/PanJiaChen/vue-admin-template/issues/237 // To fix https://github.com/PanJiaChen/vue-admin-template/issues/237
// TODO: refactor with render function // TODO: refactor with render function
this.onlyOneChild = null this.onlyOneChild = null
return {} return {
// onlyOneChild:null
}
}, },
methods: { methods: {
hasOneShowingChild(children = [], parent) { hasOneShowingChild(children = [], parent) {
// debugger
// var tempItem=null
const showingChildren = children.filter(item => { const showingChildren = children.filter(item => {
console.log(item)
if (item.hidden) { if (item.hidden) {
return false return false
} else { } else {
@ -70,9 +72,10 @@ export default {
}) })
// When there is only one child router, the child router is displayed by default // When there is only one child router, the child router is displayed by default
// if (showingChildren.length === 1) { /* if (showingChildren.length === 1) {
// return true // this.onlyOneChild=item()
// } return true
}*/
// Show parent if there are no child router to display // Show parent if there are no child router to display
if (showingChildren.length === 0) { if (showingChildren.length === 0) {

128
anrui-buscenter/anrui-finmanage-ui/src/layout/components/Sidebar/index.vue

@ -1,57 +1,60 @@
<template> <template>
<div :class="{ 'has-logo': showLogo }"> <div :class="{'has-logo':showLogo}">
<logo v-if="showLogo" :collapse="isCollapse" /> <logo v-if="showLogo" :collapse="isCollapse" />
<el-scrollbar wrap-class="scrollbar-wrapper"> <el-scrollbar wrap-class="scrollbar-wrapper">
<el-menu <el-menu :default-active="activeMenu" :background-color="variables.menuBg" :text-color="variables.menuText"
:default-active="activeMenu" :unique-opened="false" :active-text-color="variables.menuActiveText" :collapse-transition="false"
:background-color="variables.menuBg" mode="vertical">
:text-color="variables.menuText" <sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
:unique-opened="true"
:active-text-color="variables.menuActiveText"
:collapse-transition="true"
mode="vertical"
router
>
<!--:key:"'/anruifinmanagement'"-->
<el-menu-item :key="'/anruifinmanagement/finginvoiceapply'" :index="'/anruifinmanagement/finginvoiceapply'"><span slot="title">开票管理</span></el-menu-item>
<el-menu-item :key="'/anruifinmanagement/finreceipt'" :index="'/anruifinmanagement/finreceipt'"><span slot="title">款项确认</span></el-menu-item>
<!-- <el-menu-item :key="'/anruifinmanagement'" :index="'/anruifinmanagement/finmaterial'"><span slot="title">物料信息管理</span></el-menu-item>-->
<el-menu-item :key="'/anruifinmanagement/finitem'" :index="'/anruifinmanagement/finitem'"><span slot="title">费用项目管理</span></el-menu-item>
</el-menu> </el-menu>
</el-scrollbar> </el-scrollbar>
</div> </div>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex' import {
mapGetters
} from 'vuex'
import Logo from './Logo' import Logo from './Logo'
// import SidebarItem from './SidebarItem' import SidebarItem from './SidebarItem'
import variables from '@/styles/variables.scss' import variables from '@/styles/variables.scss'
import { getrolemenus } from '@/api/system/Role/role.js' import {
import Layout from '@/layout' getrolemenus,
loginDetails
} from '@/api/system/Role/role.js'
import {
getStorage
} from '@/utils/auth'
export default { export default {
components: { components: {
// SidebarItem, SidebarItem,
Logo Logo
}, },
data() { data() {
return { return {
routes: [] YongHuid: [],
routes: [],
params: {
sourceSid: '8825edb1-3b9f-48e0-8d78-a62aa8037fcb',
userSid: ''
}
} }
}, },
computed: { computed: {
...mapGetters(['sidebar']), ...mapGetters([
'sidebar'
]),
// routes() { // routes() {
// console.log(this.$router.options.routes) // f4d2e507-c4ed-451c-b364-04c08f962045
// console.log('78979789', this.$router.options.routes)
// return this.$router.options.routes // return this.$router.options.routes
// }, // },
activeMenu() { activeMenu() {
const route = this.$route; const route = this.$route
const { meta, path } = route; const {
meta,
path
} = route
// if set path, the sidebar will highlight the path you set // if set path, the sidebar will highlight the path you set
if (meta.activeMenu) { if (meta.activeMenu) {
return meta.activeMenu return meta.activeMenu
@ -68,56 +71,31 @@ export default {
return !this.sidebar.opened return !this.sidebar.opened
} }
}, },
mounted() { created() {
this.getRoleRouter() this.postHuoquyonghu()
}, },
methods: { methods: {
getRoleRouter() { //
const userSid = window.sessionStorage.getItem('userSid') postHuoquyonghu() {
// let rolemenus = getrolemenus({userSid: userSid}) var token = getStorage()
const params = { loginDetails(token).then((response) => {
sourceSid: 'df3e44ae-412e-4b02-b9e4-6893dbf5f83b', if (response.code === '200') {
userSid: userSid this.YongHuid = response.data
} this.params.userSid = this.YongHuid.sid
getrolemenus(params).then(res => { getrolemenus(this.params).then((res) => {
console.log(res) // const userRoles = this.resRouter(res.data)
this.routes = res.data
const userRoles = this.resRouter(res.data) console.log('userRoles:', this.routes)
userRoles.push({ path: '*', redirect: '/404', hidden: true }) this.routes.push({
return userRoles path: '*',
redirect: '/404',
hidden: true
})
// return this.routes
}) })
},
resRouter(menus) {
//
for (var i = 0; i < menus.length; i++) {
if (menus[i].children && menus[i].children.length != 0) {
this.resRouter(menus[i].children)
}
if (menus[i].children.length == 0) {
delete menus[i].children
delete menus[i].redirect
}
if (menus[i].component == '') {
// menus[i].component = eval(menus[i].path.substr(1))
console.log(menus[i])
menus[i] = {
path: menus[i].path,
component: Layout,
redirect: menus[i].path,
children: [menus[i]],
name: menus[i].meta.title
}
}
} }
console.log(menus) })
this.routes = menus
return menus
} }
} }
} }
</script> </script>
<style scoped="scoped">
/deep/.scrollbar-wrapper {
padding-bottom: 40px;
}
</style>

Loading…
Cancel
Save