update code

master
bettleChen 1 year ago
parent 30697a8483
commit 7e07967092

@ -47,7 +47,7 @@
ruleForm: { ruleForm: {
username: null, username: null,
password: null, password: null,
type: null, type: "student",
}, },
rules: { rules: {
username: [ username: [
@ -76,6 +76,7 @@
sessionStorage.setItem("username", this.ruleForm.username) sessionStorage.setItem("username", this.ruleForm.username)
sessionStorage.setItem("type", this.ruleForm.type) sessionStorage.setItem("type", this.ruleForm.type)
sessionStorage.setItem("name", resp.data.data.name) sessionStorage.setItem("name", resp.data.data.name)
sessionStorage.setItem("token", resp.data.token)
if (that.ruleForm.type == "student"){ if (that.ruleForm.type == "student"){
this.$router.push("/student/home") this.$router.push("/student/home")
}else if (that.ruleForm.type == "teacher") { }else if (that.ruleForm.type == "teacher") {
@ -97,6 +98,12 @@
resetForm(formName) { resetForm(formName) {
this.$refs[formName].resetFields(); this.$refs[formName].resetFields();
}, },
},
mounted() {
if (this.$route.query.message) {
this.$message({message: this.$route.query.message, type: "warning"})
this.$router.push("/login")
}
} }
} }
</script> </script>

@ -4,7 +4,6 @@ import router from './router'
import ElementUI from 'element-ui'; import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'; import 'element-ui/lib/theme-chalk/index.css';
import axios from "axios"; import axios from "axios";
import Cookies from 'js-cookie';
// axios.defaults.withCredentials = true; // axios.defaults.withCredentials = true;
let config = { let config = {
@ -16,6 +15,33 @@ let config = {
const axiosInstance = axios.create(config); const axiosInstance = axios.create(config);
axiosInstance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; axiosInstance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axiosInstance.interceptors.request.use(config => {
if (sessionStorage.getItem("token")) {
config.headers.Authorization = `${sessionStorage.getItem("token")}`;
}
return config;
}, err => {
return Promise.reject(err);
})
axiosInstance.interceptors.response.use(
response => {
return response;
},
error => { //默认除了2XX之外的都是错误的就会走这里
if(error.response){
switch(error.response.status){
case 401:
sessionStorage.clear()
router.push({ //跳转到登录页面
path: '/login',
query: { message: error.response.data.message } // 将跳转的路由path作为参数登录成功后跳转到该路由
});
}
}
return Promise.reject(error.response.data);
}
);
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.use(ElementUI); Vue.use(ElementUI);

@ -9,6 +9,7 @@ const routes = [
{ {
path: '/login', path: '/login',
name: 'login', name: 'login',
props: true,
component: login component: login
}, },
{ {
@ -91,16 +92,15 @@ const router = new VueRouter({
export default router export default router
router.beforeEach((to, from, next) => { // router.beforeEach((to, from, next) => {
if (to.path === "/login") { // if (to.path === "/login") {
next() // next()
}else { // }else {
if (sessionStorage.getItem("username") && sessionStorage.getItem("type")) { // if (sessionStorage.getItem("username") && sessionStorage.getItem("type")) {
const _type = sessionStorage.getItem("type") // const _type = sessionStorage.getItem("type")
next() // next()
}else{ // }else{
console.log("fdsafd") // next({path: "/login"})
next({path: "/login"}) // }
} // }
} // })
})

@ -56,7 +56,7 @@ export default {
}, },
methods: { methods: {
getSelectCourse() { getSelectCourse() {
this.$axios.get("/course/getCourseById?username="+sessionStorage.getItem("username")).then(resp => { this.$axios.get("/course/getCourseById").then(resp => {
if (resp.data.code === 0){ if (resp.data.code === 0){
this.tableData = resp.data.data this.tableData = resp.data.data
}else{ }else{

@ -60,7 +60,7 @@ export default {
}, },
methods: { methods: {
getGrade(){ getGrade(){
this.$axios.get("/student/getGrade?username="+sessionStorage.getItem("username")).then(resp => { this.$axios.get("/student/getGrade").then(resp => {
if (resp.data.code === 0){ if (resp.data.code === 0){
this.tableData = resp.data.data this.tableData = resp.data.data
}else { }else {

@ -68,7 +68,7 @@ export default {
} }
}, },
mounted() { mounted() {
this.$axios.get("/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { this.$axios.get("/userinfo").then(resp => {
if (resp.data.code === 0 ){ if (resp.data.code === 0 ){
const data = resp.data.data const data = resp.data.data
this.sid = data.sid this.sid = data.sid

@ -45,7 +45,12 @@
methods: { methods: {
out() { out() {
sessionStorage.clear(); sessionStorage.clear();
this.$router.push('/login') this.$router.push({
path: "/login",
query: {
message: "退出登录!"
}
})
} }
} }
} }

@ -70,7 +70,7 @@ export default {
} }
}, },
mounted() { mounted() {
this.$axios("/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { this.$axios("/userinfo").then(resp => {
if (resp.data.code === 0 ){ if (resp.data.code === 0 ){
const data = resp.data.data const data = resp.data.data
this.form.sid = data.sid this.form.sid = data.sid

@ -1,13 +1,248 @@
<template> <template>
<h1>课程管理</h1> <div>
<el-card class="box-card">
<el-form ref="form" :model="form" label-width="80px" size="mini" class="demo-form-inline" :inline="true">
<el-form-item label="学生姓名">
<el-input v-model="form.sname" ></el-input>
</el-form-item>
<el-form-item label="班级">
<el-input v-model="form.className" ></el-input>
</el-form-item>
<el-form-item label="课程名称">
<el-input v-model="form.courseName" ></el-input>
</el-form-item>
<el-form-item label="课程类型">
<el-input v-model="form.courseType" ></el-input>
</el-form-item>
<el-form-item size="large">
<el-button type="primary" @click="search"></el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="box-card" style="margin-top: 10px;">
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
label="学号"
width="80">
<template slot-scope="scope">
<i class="el-icon-time"></i>
<span style="margin-left: 10px">{{ scope.row.sid }}</span>
</template>
</el-table-column>
<el-table-column
label="姓名"
width="120">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.sname }}</span>
</template>
</el-table-column>
<el-table-column
label="班级"
width="200">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.className }}</span>
</template>
</el-table-column>
<el-table-column
label="课程名称"
width="200">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.cname }}</span>
</template>
</el-table-column>
<el-table-column
label="课程类型"
width="150">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.ctype }}</span>
</template>
</el-table-column>
<el-table-column
label="平时成绩"
width="150">
<template slot-scope="scope">
<div slot="reference" class="name-wrapper">
<el-tag size="medium" :type="scope.row.middleGrade > 60 ? 'success' : 'error'">{{ scope.row.middleGrade }}</el-tag>
</div>
</template>
</el-table-column>
<el-table-column
label="期末成绩"
width="150">
<template slot-scope="scope">
<div slot="reference" class="name-wrapper">
<el-tag size="medium" :type="scope.row.endGrade > 60 ? 'success' : 'error'">{{ scope.row.endGrade }}</el-tag>
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="200">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit(scope.$index, scope.row)">编辑</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
style="text-align: center;margin-top: 10px;"
hide-on-single-page
background
:current-page="currentPage"
:page-size="10"
@current-change="handleCurrentChange"
layout="prev, pager, next, total"
:total="total">
</el-pagination>
</el-card>
<el-drawer
title="录入成绩"
:before-close="handleClose"
:visible.sync="dialog"
direction="rtl"
custom-class="demo-drawer"
ref="drawer"
>
<div class="demo-drawer__content">
<el-form ref="addForm" :model="addForm" label-width="80px" size="mini">
<el-form-item label="学号" >
<el-input v-model="addForm.sid" disabled></el-input>
</el-form-item>
<el-form-item label="姓名">
<el-input v-model="addForm.sname" disabled></el-input>
</el-form-item>
<el-form-item label="课程名称">
<el-input v-model="addForm.cname" disabled></el-input>
</el-form-item>
<el-form-item label="平时成绩">
<el-input-number v-model="addForm.middleGrade" :min="0" :max="100" label="平时成绩"></el-input-number>
</el-form-item>
<el-form-item label="最终成绩">
<el-input-number v-model="addForm.endGrade" :min="0" :max="100" label="最终成绩"></el-input-number>
</el-form-item>
</el-form>
<div class="demo-drawer__footer">
<el-button @click="cancelForm"> </el-button>
<el-button type="primary" @click="$refs.drawer.closeDrawer()" :loading="loading">{{ loading ? '提交中 ...' : "保存" }}</el-button>
</div>
</div>
</el-drawer>
</div>
</template> </template>
<script> <script>
export default { export default {
data() {
} return {
currentPage: 1,
total: 0,
dialog: false,
loading: false,
title: "新增学生",
tableData: [{
sid: "",
sname: "",
className: "",
cname: "",
ctype: "",
endGrade: "",
middleGrade: "",
cid: ""
}],
form: {
sname: '',
className: '',
courseName: '',
courseType: '',
},
addForm: {
sid: "",
sname: "",
className: "",
cname: "",
ctype: "",
endGrade: "",
middleGrade: "",
cid: "",
}
}
},
methods: {
handleEdit(index, row) {
console.log(row)
this.addForm = new Object(row)
this.dialog = true
this.isAdd = false
this.loading = false
},
handleCurrentChange(val){
this.currentPage = val
this.getAllStudent()
},
getAllStudent() {
this.$axios.post("/course/getStudentCourse?currentPage="+this.currentPage, this.form).then(resp => {
console.log(resp.data)
if (resp.data.code === 0) {
this.total = resp.data.pageTotal
this.tableData = resp.data.data
}
})
},
search(){
this.getAllStudent()
},
handleClose(done) {
if (this.loading) {
return;
}
this.$confirm('确定要提交表单吗?')
.then(_ => {
this.loading = true;
this.timer = setTimeout(() => {
done();
this.$axios.post("/course/editGrade", this.addForm).then(resp => {
if(resp.data.code === 0){
this.$message({message: resp.data.message, type: "success"})
this.getAllStudent()
this.loading = false
this.addForm = {
sid: "",
sname: "",
className: "",
cname: "",
ctype: "",
endGrade: "",
middleGrade: "",
cid: ""
}
}else{
this.$message({message: resp.data.message, type: "error"})
}
})
}, 1000);
})
.catch(_ => {});
console.log("close")
},
cancelForm() {
this.loading = false;
this.dialog = false;
this.addForm = {
sid: "",
sname: "",
className: "",
cname: "",
ctype: "",
endGrade: "",
middleGrade: "",
cid: ""
}
clearTimeout(this.timer);
}
},
mounted() {
this.getAllStudent()
}
}
</script> </script>
<style>
</style>

@ -19,7 +19,7 @@
<el-menu-item index="/teacher/home"><template slot="title"><i class="el-icon-info"></i>老师主页</template></el-menu-item> <el-menu-item index="/teacher/home"><template slot="title"><i class="el-icon-info"></i>老师主页</template></el-menu-item>
<el-menu-item index="/teacher/teacherInfo"><template slot="title"><i class="el-icon-setting"></i>信息编辑</template></el-menu-item> <el-menu-item index="/teacher/teacherInfo"><template slot="title"><i class="el-icon-setting"></i>信息编辑</template></el-menu-item>
<el-menu-item index="/teacher/studentManage"><template slot="title"><i class="el-icon-menu"></i>学生管理</template></el-menu-item> <el-menu-item index="/teacher/studentManage"><template slot="title"><i class="el-icon-menu"></i>学生管理</template></el-menu-item>
<el-menu-item index="/teacher/courseManage"><template slot="title"><i class="el-icon-tickets"></i>课管理</template></el-menu-item> <el-menu-item index="/teacher/courseManage"><template slot="title"><i class="el-icon-tickets"></i>管理</template></el-menu-item>
</el-menu> </el-menu>
</el-aside> </el-aside>
<el-main> <el-main>

@ -3,6 +3,9 @@ module.exports = defineConfig({
transpileDependencies: true, transpileDependencies: true,
lintOnSave: false, lintOnSave: false,
devServer: { devServer: {
proxy: "http://127.0.0.1:8000" proxy: "http://127.0.0.1:8000",
client: {
overlay: false
}
} }
}) })

Loading…
Cancel
Save