Ai
1 Star 0 Fork 0

Egret/uni-app实验室后端

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
leftWindow.vue 2.29 KB
一键复制 编辑 原始数据 按行查看 历史
Egret 提交于 2022-07-11 11:57 +08:00 . init
<template>
<scroll-view class="sidebar" scroll-y="true">
<uni-data-menu ref="menu" :value="currentMenu" :staticMenu="staticMenu" collection="opendb-admin-menus" :page-size="500"
:field="field" orderby="sort asc" active-text-color="#409eff" @select="select">
</uni-data-menu>
</scroll-view>
</template>
<script>
import {
mapState,
mapActions
} from 'vuex'
import config from '@/admin.config.js'
export default {
data() {
return {
...config.sideBar,
field: 'url as value, name as text, menu_id, parent_id, sort, icon, permission'
}
},
computed: {
...mapState('app', ['inited', 'navMenu', 'active']),
...mapState('user', ['userInfo']),
currentMenu() {
return this.splitFullPath(this.active)
}
},
// #ifdef H5
watch: {
$route: {
immediate: true,
handler(newRoute, oldRoute) {
if (newRoute.fullPath !== (oldRoute && oldRoute.fullPath)) {
this.changeMenuActive(newRoute.fullPath)
}
}
},
userInfo: {
immediate: true,
handler(newVal, oldVal) {
if (newVal) {
this.$nextTick(function(){
this.$refs.menu.load()
})
}
}
}
},
// #endif
methods: {
...mapActions({
changeMenuActive: 'app/changeMenuActive'
}),
select(e) {
let url = e.value
if (!url) {
url = this.active
}
this.clickMenuItem(url)
},
clickMenuItem(url) {
// #ifdef H5
if (url.indexOf('http') === 0) {
return window.open(url)
}
// #endif
// url 开头可用有 / ,也可没有
if (url[0] !== '/' && url.indexOf('http') !== 0) {
url = '/' + url
}
// TODO 后续要调整
uni.redirectTo({
url: url,
fail: () => {
uni.showModal({
title: '提示',
content: '页面 ' + url + ' 跳转失败',
showCancel: false
})
}
})
},
splitFullPath(path) {
if (!path) {
path = '/'
}
return path.split('?')[0]
},
}
}
</script>
<style lang="scss">
.sidebar {
position: fixed;
// top: var(--top-window-height); // useless
width: 240px;
height: calc(100vh - (var(--top-window-height)));
box-sizing: border-box;
border-right: 1px solid darken($left-window-bg-color, 8%);
background-color: $left-window-bg-color;
padding-bottom: 10px;
}
.title {
margin-left: 5px;
}
</style>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/Egrt/uni-app-lab-server.git
git@gitee.com:Egrt/uni-app-lab-server.git
Egrt
uni-app-lab-server
uni-app实验室后端
master

搜索帮助