123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <template>
- <div style="height: 100%; width: 100%;" @click="checkTimeOut()" @mouseenter="checkTimeOut()"
- @mousemove="checkTimeOut()">
- <el-container class="admin-container">
- <!--页面头部(上边)-->
- <el-header>
- <div class="admin-logo-container">
- <!-- <img
- class="admin-logo"
- src="../assets/img/admin.jpg"
- alt=""
- > -->
- <span>安徽省农产品质量安全监测系统</span>
- </div>
- <div class="right-function-container">
- <el-button @click="logout">
- 退 出
- </el-button>
- </div>
- </el-header>
- <!--页面主体部分-->
- <el-container>
- <!--页面侧边栏(左边)-->
- <el-aside style="width: 210px;">
- <!-- 页面左侧菜单区域-->
- <el-menu :default-active="$route.path" background-color="#EEF1F6" text-color="#48576a"
- active-text-color="#31B404" :unique-opened="true" :collapse-transition="false" :router="true">
- <!-- <el-menu-item
- index="/admin"
- @click="addTab('系统首页', '/admin')"
- >
- <i class="el-icon-s-home" />
- <span slot="title">系统首页</span>
- </el-menu-item> -->
- <!-- 一级菜单-->
- <el-submenu :index="index+''" v-for="(item, index) in menuList" :key="index">
- <!-- 一级菜单模板区-->
- <template slot="title">
- <!-- 图标-->
- <i :class="item.icon" />
- <!-- 文本-->
- <span>{{ item.subMenuName }}</span>
- </template>
- <!-- 二级菜单-->
- <el-menu-item :index="subItem.path+''" v-for="subItem in item.children" :key="subItem.id"
- @click="addTab(subItem.subMenuName, subItem.path)">
- <!-- 二级菜单模板区-->
- <template slot="title">
- <!-- 图标-->
- <i class="el-icon-bangzhu" />
- <!-- 文本-->
- <span>{{ subItem.subMenuName }}</span>
- </template>
- </el-menu-item>
- </el-submenu>
- </el-menu>
- </el-aside>
- <!-- 页面主内容(右边)-->
- <el-main>
- <el-tabs v-model="activeTabas" type="card" @tab-remove="removeTab" @tab-click="tabClick">
- <el-tab-pane v-for="item in Tabs" :key="item.name" :label="item.title" :name="item.name"
- :closable="item.isClose">
- <el-container>
- <el-main>
- <el-card shadow="always">
- <!-- 内容显示-->
- <router-view :key="item.name" />
- </el-card>
- </el-main>
- </el-container>
- </el-tab-pane>
- </el-tabs>
- </el-main>
- </el-container>
- </el-container>
- </div>
- </template>
- <script>
- export default {
- name: 'Admin',
- data() {
- return {
- lastTime: null, // 最后一次点击的时间
- currentTime: null, // 当前点击的时间
- timeOut: 30 * 60 * 1000, // 设置超时时间: 30分钟
- /** tabs标签相关属性 */
- // 当前打开的tabs名称
- activeTabas: '/admin',
- Tabs: [],
- // 左侧菜单数据
- menuList: []
- }
- },
- watch: {
- /** 监听,当路由发生变化的时候执行(防止用户手动更换地址导致tabs的面板变动却不切换相应的tabs) */
- '$route.path': function() {
- var iindex = -1
- var jindex = -1
- for (let i = 0; i < this.menuList.length; i++) {
- for (let j = 0; j < this.menuList[i].children.length; j++) {
- if (this.menuList[i].children[j].path == this.$route.path) {
- iindex = i
- jindex = j
- break
- }
- }
- }
- this.addTab(this.menuList[iindex].children[jindex].subMenuName, this.$route.path)
- }
- },
- created() {
- this.lastTime = new Date().getTime() // 网页第一次打开时,记录当前时间
- // 保证admin中的页面刷新后重置到/admin路由下
- if (this.$route.path !== '/admin/routineMonitor') this.$router.push('/admin/routineMonitor')
- let groupname = window.sessionStorage.getItem('groupname')
- let data1 = []
- let data = [
- // {
- // // icon: 'el-icon-user-solid',
- // subMenuName: '监测模型',
- // children: [{
- // id: '1-1',
- // subMenuName: '模型配置',
- // path: '/admin/'
- // }]
- // },
- {
- // icon: 'el-icon-user-solid',
- subMenuName: '监测任务',
- children: [{
- id: '5-1',
- subMenuName: '例行监测',
- path: '/admin/routineMonitor'
- }, {
- id: '5-2',
- subMenuName: '专项监测',
- path: '/admin/specialMonitor'
- }
- // ,{
- // id: '5-3',
- // subMenuName: '监测抽查',
- // path: '/admin/checkMonitor'
- // },{
- // id: '5-4',
- // subMenuName: '复检任务',
- // path: '/admin/'
- // },
- ]
- },
- ]
- this.menuList = data
- },
- methods: {
- handleOpen(index) {
- console.log(index)
- },
- /** tabs标签相关函数 */
- // tab切换时,动态的切换路由
- tabClick(tab) {
- if (this.$route.path == tab.name) return
- this.$router.push(tab.name)
- },
- addTab(title, name) {
- for (let i = 0; i < this.Tabs.length; i++) {
- if (this.Tabs[i].name == name) {
- this.activeTabas = name
- return
- }
- }
- this.Tabs.push({
- title: title,
- name: name,
- isClose: 'closable'
- })
- this.activeTabas = name
- },
- removeTab(targetName) {
- const tabs = this.Tabs
- let activeName = this.activeTabas
- if (activeName == targetName) {
- tabs.forEach((tab, index) => {
- if (tab.name == targetName) {
- const nextTab = tabs[index + 1] || tabs[index - 1]
- if (nextTab) {
- activeName = nextTab.name
- }
- }
- })
- }
- this.activeTabas = activeName
- this.$router.push(activeName)
- this.Tabs = tabs.filter(tab => tab.name !== targetName)
- },
- /** 设置用户为登出状态 */
- async logout() {
- // const formData = { 'token': window.sessionStorage.getItem('token') }
- // // 提交登出请求
- // const result = await this.$http.post('/loginOut', formData)
- // if (result.data.code == 0) {
- // 清除seesion信息
- window.sessionStorage.clear()
- this.$router.push('/login')
- // }
- },
- async checkTimeOut() {
- this.currentTime = new Date().getTime() // 记录这次点击的时间
- // 如果当前页面不是登录,初始化界面就可以执行是否退出
- if (!(this.$route.path == '/login')) {
- /** 判断是否因为超时可以退出 */
- // 判断时间是否过期(判断上次最后一次点击的时间和这次点击的时间间隔是否大于10分钟)
- var isExit = this.currentTime - this.lastTime > this.timeOut
- if (isExit) {
- isExit = false
- // 这里写状态已过期后执行的操作
- this.lastTime = new Date().getTime() // 如果在10分钟内点击,则把这次点击的时间记录覆盖掉之前存的最后一次点击的时间
- this.$router.push('/login')
- // 设置用户为登出状态
- // const formData = {
- // 'token': window.sessionStorage.getItem('token')
- // }
- // 提交登出请求
- // const result = await this.$http.post('login_out', formData)
- // if (result.data.code == 0) {
- // // 清除seesion信息
- // window.sessionStorage.removeItem('token')
- // }
- // this.$message({
- // message: '长时间未操作,请重新登录',
- // type: 'warning',
- // showClose: true,
- // center: true
- // })
- } else {
- /** 判断是否因为用户未登录可以退出 */
- // const token = window.sessionStorage.getItem('token')
- // if (token == null || token == undefined || token == '') {
- // this.$router.push('/login')
- // this.$message({
- // message: '用户未登录,请重新登录',
- // type: 'warning',
- // showClose: true,
- // center: true
- // })
- // }
- this.lastTime = new Date().getTime() // 如果在10分钟内点击,则把这次点击的时间记录覆盖掉之前存的最后一次点击的时间
- }
- } else {
- this.lastTime = new Date().getTime() // 如果在10分钟内点击,则把这次点击的时间记录覆盖掉之前存的最后一次点击的时间
- }
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .admin-container {
- height: 100%;
- // overflow: hidden;
- }
- .el-main {
- padding-top: 8px !important;
- }
- .el-menu-item.is-active {
- // background-color: #3ace04 !important;
- }
- .admin-logo-container {
- // border-color: #5EB9DE;
- // border-right-width: 1px;
- // border-right-style: solid;
- }
- .admin-logo {
- margin-left: 5px;
- height: 55px;
- width: 55px;
- /*自动等比缩放*/
- background-size: 100% 100%;
- }
- .el-header {
- background-color: #31B404;
- width: 100%;
- color: white;
- font-size: 25px;
- display: flex;
- padding-left: 0;
- }
- .admin-logo-container {
- display: flex;
- align-items: center;
- span {
- margin-left: 15px;
- }
- }
- .el-aside {
- // width: 200px;
- background-color: #EEF1F6;
- }
- .toggle-button-container {
- width: 180px;
- display: flex;
- justify-content: left;
- }
- // .toggle-button {
- // width: 50px;
- // line-height: 60px;
- // color: #fff;
- // text-align: center;
- // cursor: pointer;
- // }
- .right-function-container {
- width: 400px;
- line-height: 50px;
- text-align: right;
- position: absolute;
- right: 15px;
- }
- </style>
|