hi-ucs/back/src/views/main.vue

141 lines
3.6 KiB
Vue
Raw Normal View History

2022-06-14 09:32:49 +08:00
<template>
2022-06-21 15:48:41 +08:00
<div
v-loading.fullscreen.lock="loading"
:element-loading-text="$t('loading')"
:class="['aui-wrapper', { 'aui-sidebar--fold': $store.state.sidebarFold }]"
>
2022-06-14 09:32:49 +08:00
<template v-if="!loading">
<main-navbar />
<main-sidebar />
<div class="aui-content__wrapper">
<main-content v-if="!$store.state.contentIsNeedRefresh" />
</div>
<main-theme-tools />
</template>
</div>
</template>
<script>
2022-07-26 18:08:24 +08:00
import MainNavbar from './main-navbar'
import MainSidebar from './main-sidebar'
import MainContent from './main-content'
import MainThemeTools from './main-theme-tools'
import debounce from 'lodash/debounce'
import { isURL } from '@/utils/validate'
2022-06-14 09:32:49 +08:00
export default {
2022-07-26 18:08:24 +08:00
provide () {
2022-06-14 09:32:49 +08:00
return {
// 刷新
2022-07-26 18:08:24 +08:00
refresh () {
this.$store.state.contentIsNeedRefresh = true
2022-06-14 09:32:49 +08:00
this.$nextTick(() => {
2022-07-26 18:08:24 +08:00
this.$store.state.contentIsNeedRefresh = false
})
}
}
2022-06-14 09:32:49 +08:00
},
2022-07-26 18:08:24 +08:00
data () {
2022-06-14 09:32:49 +08:00
return {
2022-07-26 18:08:24 +08:00
loading: true
}
2022-06-14 09:32:49 +08:00
},
components: {
MainNavbar,
MainSidebar,
MainContent,
2022-07-26 18:08:24 +08:00
MainThemeTools
2022-06-14 09:32:49 +08:00
},
watch: {
2022-07-26 18:08:24 +08:00
$route: 'routeHandle'
2022-06-14 09:32:49 +08:00
},
2022-07-26 18:08:24 +08:00
created () {
this.windowResizeHandle()
this.routeHandle(this.$route)
2022-06-21 15:48:41 +08:00
Promise.all([this.getUserInfo(), this.getPermissions()]).then(() => {
2022-07-26 18:08:24 +08:00
this.loading = false
})
2022-06-14 09:32:49 +08:00
},
methods: {
// 窗口改变大小
2022-07-26 18:08:24 +08:00
windowResizeHandle () {
2022-06-21 15:48:41 +08:00
this.$store.state.sidebarFold =
2022-07-26 18:08:24 +08:00
document.documentElement.clientWidth <= 992 || false
2022-06-21 15:48:41 +08:00
window.addEventListener(
2022-07-26 18:08:24 +08:00
'resize',
2022-06-21 15:48:41 +08:00
debounce(() => {
this.$store.state.sidebarFold =
2022-07-26 18:08:24 +08:00
document.documentElement.clientWidth <= 992 || false
2022-06-21 15:48:41 +08:00
}, 150)
2022-07-26 18:08:24 +08:00
)
2022-06-14 09:32:49 +08:00
},
// 路由, 监听
2022-07-26 18:08:24 +08:00
routeHandle (route) {
2022-06-14 09:32:49 +08:00
if (!route.meta.isTab) {
2022-07-26 18:08:24 +08:00
return false
2022-06-14 09:32:49 +08:00
}
2022-07-26 18:08:24 +08:00
let tab = {}
let routeName = route.name
const routeMeta = route.meta
if (route.name === 'iframe') {
const url = route.query.url || ''
2022-06-14 09:32:49 +08:00
if (!isURL(url)) {
2022-07-26 18:08:24 +08:00
return false
2022-06-14 09:32:49 +08:00
}
2022-07-26 18:08:24 +08:00
const key = route.query.key || new Date().getTime()
routeName = `${routeName}_${key}`
routeMeta.title = key.toString()
routeMeta.menuId = route.query.menuId || ''
routeMeta.iframeURL = url
2022-06-14 09:32:49 +08:00
}
2022-06-21 15:48:41 +08:00
tab = this.$store.state.contentTabs.filter(
(item) => item.name === routeName
2022-07-26 18:08:24 +08:00
)[0]
2022-06-14 09:32:49 +08:00
if (!tab) {
tab = {
2022-07-26 18:08:24 +08:00
...window.SITE_CONFIG.contentTabDefault,
2022-06-14 09:32:49 +08:00
...routeMeta,
2022-06-21 15:48:41 +08:00
name: routeName,
params: { ...route.params },
2022-07-26 18:08:24 +08:00
query: { ...route.query }
}
2022-06-21 15:48:41 +08:00
this.$store.state.contentTabs =
2022-07-26 18:08:24 +08:00
this.$store.state.contentTabs.concat(tab)
2022-06-14 09:32:49 +08:00
}
2022-07-26 18:08:24 +08:00
this.$store.state.sidebarMenuActiveName = tab.menuId
this.$store.state.contentTabsActiveName = tab.name
2022-06-14 09:32:49 +08:00
},
// 获取当前管理员信息
2022-07-26 18:08:24 +08:00
getUserInfo () {
2022-06-21 15:48:41 +08:00
return this.$http
2022-07-26 18:08:24 +08:00
.get('/sys/user/info')
2022-06-21 15:48:41 +08:00
.then(({ data: res }) => {
if (res.code !== 0) {
2022-07-26 18:08:24 +08:00
return this.$message.error(res.msg)
2022-06-21 15:48:41 +08:00
}
2022-07-26 18:08:24 +08:00
this.$store.state.user.id = res.data.id
this.$store.state.user.name = res.data.realName
this.$store.state.user.superAdmin = res.data.superAdmin
2022-06-21 15:48:41 +08:00
})
2022-07-26 18:08:24 +08:00
.catch(() => {})
2022-06-14 09:32:49 +08:00
},
// 获取权限
2022-07-26 18:08:24 +08:00
getPermissions () {
2022-06-21 15:48:41 +08:00
return this.$http
2022-07-26 18:08:24 +08:00
.get('/sys/menu/permissions')
2022-06-21 15:48:41 +08:00
.then(({ data: res }) => {
if (res.code !== 0) {
2022-07-26 18:08:24 +08:00
return this.$message.error(res.msg)
2022-06-21 15:48:41 +08:00
}
2022-07-26 18:08:24 +08:00
window.SITE_CONFIG.permissions = res.data
2022-06-21 15:48:41 +08:00
})
2022-07-26 18:08:24 +08:00
.catch(() => {})
}
}
}
2022-06-21 15:48:41 +08:00
</script>
<style scoped lang="scss">
.aui-content__wrapper {
margin-left: 266px;
2022-06-14 09:32:49 +08:00
}
2022-06-21 15:48:41 +08:00
</style>