pc端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.8 KiB

4 years ago
<script setup>
4 years ago
import { computed, ref } from 'vue';
import { useStore } from 'vuex';
import { useRoute, useRouter } from 'vue-router';
4 years ago
import Navbar from 'components/navbar.vue';
import zhCn from 'element-plus/lib/locale/lang/zh-cn';
import { ElMessage } from 'element-plus';
4 years ago
import { routes } from '@/routers/index.js';
const local = zhCn;
const store = useStore();
let timer = null;
4 years ago
const routeList = ref(routes);
const menu = computed(() => store.state.menu);
const activeMenuIndex = ref(0);
4 years ago
// 验证 获取query中u参数 获取token
const route = useRoute();
const router = useRouter();
useRouter()
.isReady()
.then(async () => {
activeMenuIndex.value = routes.findIndex(item => item.name === route.name);
const u = computed(() => route.query.u);
if (!u.value) {
// 获取url中的u参数, 没有提示缺少参数
ElMessage.error('缺少用户信息参数');
} else {
// 根据userId 获取token
await store.dispatch('user/getTokenByUserId', u.value);
}
});
const token = computed(() => store.getters['user/token']);
// 获取设备数据
const getDeviceData = async () => {
if (token && token.value) {
await store.dispatch('device/getDevices');
timer && clearTimeout(timer);
timer = null;
} else {
timer = setTimeout(() => {
getDeviceData();
}, 16);
}
};
getDeviceData();
/**
* 打开页面
* @param {string} path 页面路径
*/
function openPage(path) {
const { query } = route;
router.push({
path,
query,
});
}
4 years ago
</script>
<template>
<el-config-provider :locale="local">
4 years ago
<el-container>
<el-header style="padding: 0">
<Navbar />
</el-header>
4 years ago
<el-container class="overflow-hidden">
4 years ago
<!-- <el-aside width="180px" v-if="menu.show"> -->
<el-aside v-if="menu.show" :width="!menu.collapse ? '200px' : '64px'">
<el-menu :collapse="menu.collapse" :default-active="activeMenuIndex" class="el-menu-vertical-demo">
<el-menu-item
v-for="(item, index) in routeList"
:key="item.name"
:index="index"
class="flex items-center"
@click="openPage(item.path)"
>
4 years ago
<i :class="item.meta.icon"></i>
<template #title>{{ item.meta.title }}</template>
4 years ago
</el-menu-item>
</el-menu>
</el-aside>
<el-main style="padding: 0">
<div class="p-4">
<router-view></router-view>
</div>
</el-main>
</el-container>
</el-container>
</el-config-provider>
4 years ago
</template>
4 years ago
<style>
4 years ago
html,
body,
#app,
#app > section {
height: 100%;
}
.el-menu {
min-height: 100%;
}
4 years ago
.el-form--label-top .el-form-item__label {
padding-bottom: 0 !important;
}
4 years ago
.el-form-item {
margin-bottom: 10px !important;
}
</style>