testvue-新增图表功能(教师那边-后续放到管理员那边)-src/main.js ,router/index.js

1.安装--然后在src/main.js中 导入 和  使用
2修改:common/sidebar.vue ,page/ echarts.vue , router/index.js , src/main.js


3sidebar.vue

<template><div class="sidebar"><el-menuclass="sidebar-el-menu":default-active="onRoutes":collapse="collapse"background-color="#324157"text-color="#bfcbd9"active-text-color="#20a0ff"unique-openedrouter><template v-for="item in items"><template v-if="item.subs">
<!--                    一级菜单--><el-submenu :index="item.index" :key="item.index"><template slot="title"><i :class="item.icon"></i><span slot="title">{{ item.title }}</span></template><template v-for="subItem in item.subs"><el-submenuv-if="subItem.subs":index="subItem.index":key="subItem.index"><template slot="title"><i :class="subItem.icon"></i>{{ subItem.title }}</template>
<!--                                二级菜单--><el-menu-itemv-for="(threeItem,i) in subItem.subs":key="i":index="threeItem.index"><i :class="threeItem.icon"></i>{{ threeItem.title }}</el-menu-item></el-submenu><!-- :key="subItem.index" 删掉的39行 --><el-menu-itemv-else:index="subItem.index"><i :class="subItem.icon"></i>{{ subItem.title }}</el-menu-item></template></el-submenu></template><template v-else><el-menu-item :index="item.index" :key="item.index"><i :class="item.icon"></i><span slot="title">{{ item.title }}</span></el-menu-item></template></template></el-menu></div>
</template><script>
import bus from '../common/bus';
export default {data() {return {collapse: false,items:[],//管理员菜单userType=0itemList3: [{"id":4,"pid":1,"icon":"el-icon-s-order","index":"3","title":"统一管理","subs":[{"id":9,"pid":4,"icon":"el-icon-plus","index":"user","title":"用户管理","subs":null},{"id":10,"pid":4,"icon":"el-icon-plus","index":"test","title":"题库管理","subs":null},{"id":11,"pid":4,"icon":"el-icon-plus","index":"question2","title":"选题管理","subs":null},{"id":11,"pid":4,"icon":"el-icon-plus","index":"report","title":"成绩管理","subs":null},{"id":12,"pid":4,"icon":"el-icon-plus","index":"parent","title":"家长管理","subs":null},]},],//教师菜单userType=1itemList: [{"id":4,"pid":1,"icon":"el-icon-s-order","index":"3","title":"统一管理","subs":[{"id":9,"pid":4,"icon":"el-icon-plus","index":"user",  //对应就是 /user路径,即在router中是对应user.vue"title":"用户管理","subs":null},{"id":10,"pid":4,"icon":"el-icon-plus","index":"test","title":"题库管理","subs":null},{"id":11,"pid":4,"icon":"el-icon-plus","index":"question2","title":"选题管理","subs":null},{"id":11,"pid":4,"icon":"el-icon-plus","index":"report","title":"成绩管理","subs":null},{"id":12,"pid":4,"icon":"el-icon-plus","index":"parent","title":"家长管理","subs":null},{"id":12,"pid":4,"icon":"el-icon-plus","index":"echarts","title":"后台图表","subs":null},]},],//学生菜单userType=2      itemList2:[{"id":5,"pid":1,"icon":"el-icon-s-data","index":"6","title":"我的管理","subs":[{"id":10,"pid":4,"icon":"el-icon-plus","index":"test","title":"题库管理","subs":null},{"id":11,"pid":4,"icon":"el-icon-plus","index":"report","title":"成绩管理","subs":null},{"id":11,"pid":4,"icon":"el-icon-plus","index":"collect","title":"错题管理","subs":null},{"id":12,"pid":4,"icon":"el-icon-plus","index":"parent","title":"家长管理","subs":null},]}],};},computed: {onRoutes() {return this.$route.path.replace('/', '');},},created() {// 通过 Event Bus 进行组件间通信,来折叠侧边栏bus.$on('collapse', msg => {this.collapse = msg;bus.$emit('collapse-content', msg);});//初始化menuListif ("1" === sessionStorage.getItem('userType')){this.items = this.itemList; //学生的菜单}else if ("2" === sessionStorage.getItem('userType')){this.items = this.itemList2;  //教师的菜单}else {this.items = this.itemList3;  //管理员的菜单}}
};
</script><style scoped>
.sidebar {display: block;position: absolute;left: 0;top: 70px;bottom: 0;overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {width: 250px;
}
.sidebar > ul {height: 100%;
}
</style>

4echarts.vue
 

<template><div><el-card><div ref="echarts" style="width: 100%; height: 800px;"></div></el-card></div>
</template><script>
export default {data() {return {// ECharts 配置chartOptions: {legend: {},tooltip: {trigger: 'axis',showContent: false},dataset: {source: [['product', '2012', '2013', '2014', '2015', '2016', '2017'],['Milk Tea', 56.5, 82.1, 88.7, 70.1, 53.4, 85.1],['Matcha Latte', 51.1, 51.4, 55.1, 53.3, 73.8, 68.7],['Cheese Cocoa', 40.1, 62.2, 69.5, 36.4, 45.2, 32.5],['Walnut Brownie', 25.2, 37.1, 41.2, 18, 33.9, 49.1]]},xAxis: { type: 'category' },yAxis: { gridIndex: 0 },grid: { top: '55%' },series: [{type: 'line',smooth: true,seriesLayoutBy: 'row',emphasis: { focus: 'series' }},{type: 'line',smooth: true,seriesLayoutBy: 'row',emphasis: { focus: 'series' }},{type: 'line',smooth: true,seriesLayoutBy: 'row',emphasis: { focus: 'series' }},{type: 'line',smooth: true,seriesLayoutBy: 'row',emphasis: { focus: 'series' }},{type: 'pie',id: 'pie',radius: '30%',center: ['50%', '25%'],emphasis: {focus: 'self'},label: {formatter: '{b}: {@2012} ({d}%)'},encode: {itemName: 'product',value: '2012',tooltip: '2012'}}]}};},mounted() {// 基于准备好的dom,初始化echarts实例let myChart = this.$echarts.init(this.$refs.echarts,'dark');// 使用刚指定的配置项和数据显示图表。myChart.setOption(this.chartOptions);myChart.on('updateAxisPointer', function (event) {const xAxisInfo = event.axesInfo[0];if (xAxisInfo) {const dimension = xAxisInfo.value + 1;myChart.setOption({series: {id: 'pie',label: {formatter: '{b}: {@[' + dimension + ']} ({d}%)'},encode: {value: dimension,tooltip: dimension}}});}});}
};
</script><style scoped>
/* 在这里添加样式 */
</style>

5main.js
 

import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
import store from './store'
import axios from 'axios'
import echarts from 'echarts';
import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
import './assets/css/icon.css';
import './components/common/directives';
import 'babel-polyfill';Vue.prototype.$echarts = echarts   //Vue.prototype.$echarts = echartsaxios.defaults.baseURL = window.server_ip.BASE_URL;
Vue.config.productionTip = false;
Vue.use(ElementUI, {size: 'small'
});
import limitNum from './utils/inputValid'Vue.directive('limitNum', limitNum);Vue.filter('timeFormat',function (time) {//分钟var minute = time / 60;var minutes = parseInt(minute);if (minutes < 10) {minutes = "0" + minutes;}//秒var second = time % 60;var seconds = Math.round(second);if (seconds < 10) {seconds = "0" + seconds;}return `${minutes}:${seconds}`;
})
//使用钩子函数对路由进行权限跳转
// router.beforeEach((to, from, next) => {
//     document.title = `${to.meta.title} | ls-manage-system`;
//     const role = localStorage.getItem('ms_username');
//     if (!role && to.path !== '/login') {
//         next('/login');
//     } else if (to.meta.permission) {
//         // 如果是管理员权限则可进入,这里只是简单的模拟管理员权限而已
//         role === 'admin' ? next() : next('/403');
//     } else {
//         // 简单的判断IE10及以下不进入富文本编辑器,该组件不兼容
//         if (navigator.userAgent.indexOf('MSIE') > -1 && to.path === '/editor') {
//             Vue.prototype.$alert('vue-quill-editor组件不兼容IE10及以下浏览器,请使用更高版本的浏览器查看', '浏览器不兼容通知', {
//                 confirmButtonText: '确定'
//             });
//         } else {
//             next();
//         }
//     }
// });new Vue({router,store,render: h => h(App)
}).$mount('#app');

6 router/index.js
 

import Vue from 'vue';
import Router from 'vue-router';
//import router from '@vue/cli-service/generator/router/template/src/router';Vue.use(Router);const router = new Router({routes: [{path: '/',redirect: '/Home'},{path: '/Home',component: () => import(/* webpackChunkName: "home" */ '../components/common/Home.vue'),meta: { title: '自述文件' },children: [{path: '/Home',component: () => import(/* webpackChunkName: "dashboard" */ '../components/page/Dashboard.vue'),meta: { title: '系统首页' }},{path: '/user',component: () => import(/* webpackChunkName: "icon" */ '../components/page/User'),meta: { title: '用户管理' }},{path: '/test',component: () => import(/* webpackChunkName: "icon" */ '../components/page/Test'),meta: { title: '题库管理' }},{path: '/question2',component: () => import(/* webpackChunkName: "icon" */ '../components/page/Question2'),meta: { title: '选题管理' }},{path: '/report',component: () => import(/* webpackChunkName: "icon" */ '../components/page/Report'),meta: { title: '成绩管理' }},{path: '/collect',component: () => import(/* webpackChunkName: "icon" */ '../components/page/Collect'),meta: { title: '成绩管理' }},{path: '/parent',component: () => import(/* webpackChunkName: "icon" */ '../components/page/Parent'),meta: { title: '家长管理' }},{path: '/404',component: () => import(/* webpackChunkName: "404" */ '../components/page/404.vue'),meta: { title: '404' }},{path: '/403',component: () => import(/* webpackChunkName: "403" */ '../components/page/403.vue'),meta: { title: '403' }},{path: '/echarts',component: () => import(/* webpackChunkName: "403" */ '../components/page/echarts.vue'),meta: { title: '后台图表' }},]},{path: '/login',component: () => import(/* webpackChunkName: "login" */ '../components/page/Login.vue'),meta: { title: '登录' }},{path: '/start',component: () => import(/* webpackChunkName: "icon" */ '../components/page/StartTest'),meta: { title: '开始考试' }},{path: '/register',component: () => import(/* webpackChunkName: "login" */ '../components/page/Register'),meta: { title: '注册' }},//如果这里后面路由有问题,把这个404注释掉{path: '*',redirect: '/404'}]
});router.beforeEach((to,from,next) =>{if (to.path === '/login') {next()}else{const token = sessionStorage.getItem('userStatus');if (!token){next('/login')}else{next();}}
});export default router

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/521113.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Java EE初阶三十】JVM的简单学习

1. JVM 内存区域划分 一个运行起来的 Java 进程&#xff0c;就是一个 JVM 虚拟机&#xff0c;需要从操作系统申请一大块内存&#xff0c;就会把这个内存&#xff0c;划分成不同的区域&#xff0c;每个区域都有不同的作用. JVM 申请了一大块内存之后,也会划分成不同的内…

Docker容器的操作

目录 运行容器 查看容器 查看容器详细信息 删除容器 启动容器 停止容器 重启容器 暂停容器 激活容器 杀死容器 进入容器 常用 查看容器的日志 拷贝容器的文件到本地 容器改名 查看容器资源 查看容器内部的进程 监测容器发生的事件 检测容器停止以后的反回值…

hexo butterfly博客搭建美化集合+问题记录

文章目录 一、美化1. cs 和js引入2. 图标使用 三、问题总结1. vscode终端输入hexo命令报错 一、美化 1. cs 和js引入 hexo博客添加自定义css和js文件 如果想魔改和美化&#xff0c;添加自定义文件是不可避免的。下面来详细说一下css和js文件的创建和引入&#xff0c;其他文件同…

【计算机组成原理】一、计算机系统的性能指标(机器字长、存储容量、存储单位、CPU时钟周期、主频、CPI、IPS、运算速度、数据通路、吞吐量、响应时间)

文章目录 3.性能指标3.1存储器性能3.1.1存储单位3.1.2存储器指标 3.2CPU性能3.3整体性能3.3.1机器字长 3.性能指标 3.1存储器性能 3.1.1存储单位 计算机的最小存储单位 位&#xff1a;比特bit&#xff0c;简写为b。 存放一位二进制数&#xff0c;即 0 或 1&#xff0c;最小…

基于yolov5的铁轨缺陷检测系统,可进行图像目标检测,也可进行视屏和摄像检测(pytorch框架)【python源码+UI界面+功能源码详解】

功能演示&#xff1a; 基于yolov5的铁轨缺陷检测系统&#xff0c;系统既能够实现图像检测&#xff0c;也可以进行视屏和摄像实时检测_哔哩哔哩_bilibili &#xff08;一&#xff09;简介 基于yolov5的铁轨缺陷检测系统是在pytorch框架下实现的&#xff0c;这是一个完整的项目…

Redis + Caffeine = 王炸!!

在高性能的服务架构设计中,缓存是一个不可或缺的环节。在实际的项目中,我们通常会将一些热点数据存储到Redis或MemCache这类缓存中间件中,只有当缓存的访问没有命中时再查询数据库。在提升访问速度的同时,也能降低数据库的压力。 随着不断的发展,这一架构也产生了改进,在…

“2024杭州智慧城市及安防展会”将于4月在杭州博览中心盛大召开

2024杭州国际智慧城市及安防展览会&#xff0c;将于4月24日在杭州国际博览中心盛大开幕。这场备受瞩目的盛会&#xff0c;不仅汇集了全球智慧城市与安防领域的顶尖企业&#xff0c;更是展示最新技术、交流创新理念的重要平台。近日&#xff0c;从组委会传来消息&#xff0c;展会…

提升工作效率:探索AmazonQ预览版,开发者的生成式AI助手

提升工作效率&#xff1a;探索AmazonQ预览版&#xff0c;开发者的生成式AI助手 前言 亚马逊云科技推出 Amazon Q&#xff0c;这是一款基于生成式人工智能&#xff08;AI&#xff09;的新型助手&#xff0c;专为辅助工作而设计&#xff0c;可以根据你的业务量身定制。在这篇博…

Spring Cloud Nacos集成Seata2.0 AT模式

Spring Cloud Nacos集成Seata2.0 AT模式 以CentOS 7为例&#xff0c;介绍Spring Cloud Nacos集成Seata2.0 AT模式的流程。分成两个步骤&#xff1a;1.安装配置seata-server、2.项目集成seata-client 一、下载seata-server安装包 根据自己的操作系统选择要下载的安装包格式&a…

玩转AI大模型应用开发,轻松打造热门APPai数字人直播软件!

AI大模型应用在数字人直播领域的应用愈发成熟&#xff0c;为开发者提供了更多创意和可能性。数字人直播软件是当前热门的应用之一&#xff0c;它结合了虚拟主播和人工智能技术&#xff0c;为用户带来全新的互动体验。想要打造一个火爆的数字人直播软件&#xff0c;就需要玩转AI…

amv是什么文件格式?如何播放amv视频?

AMV文件格式源自于中国公司Actions Semiconductor&#xff0c;最初作为其MP4播放器中使用的专有视频格式。产生于数码媒体发展的需求下&#xff0c;AMV格式为小屏幕便携设备提供了一种高度压缩的视频存储方案。 AMV文件格式的主要特性与使用场景 AMV格式以其独特的特性在小尺寸…

vis.js network操作学习

前言 网络是显示网络以及由节点和边组成的网络的可视化。可视化易于使用&#xff0c;并支持自定义形状、样式、颜色、尺寸、图像等。网络可视化可以在任何现代浏览器上顺利运行&#xff0c;最多可显示数千个节点和边缘。为了处理大量节点&#xff0c;网络提供了集群支持。Netw…