From 30697a8483256e3c93d739011ec25f6cf7074f19 Mon Sep 17 00:00:00 2001 From: bettleChen <2207153529@qq.com> Date: Mon, 11 Sep 2023 17:58:29 +0800 Subject: [PATCH] update code --- front/package-lock.json | 9 ++ front/package.json | 1 + front/src/components/login.vue | 2 +- front/src/main.js | 15 +- front/src/plugins/axios.js | 53 +------ front/src/views/student/courseInfo.vue | 69 +++++++-- front/src/views/student/courseSelect.vue | 163 ++++++++++++++++------ front/src/views/student/grade.vue | 27 ++-- front/src/views/student/home.vue | 2 +- front/src/views/student/studentInfo.vue | 4 +- front/src/views/teacher/home.vue | 2 +- front/src/views/teacher/studentManage.vue | 6 +- front/src/views/teacher/teacherInfo.vue | 4 +- front/vue.config.js | 6 +- 14 files changed, 239 insertions(+), 124 deletions(-) diff --git a/front/package-lock.json b/front/package-lock.json index 860ee45..5accabd 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -11,6 +11,7 @@ "axios": "^1.5.0", "core-js": "^3.8.3", "element-ui": "^2.15.14", + "js-cookie": "^3.0.5", "vue": "^2.6.14", "vue-router": "^3.0.2" }, @@ -6782,6 +6783,14 @@ "@sideway/pinpoint": "^2.0.0" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmmirror.com/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "engines": { + "node": ">=14" + } + }, "node_modules/js-message": { "version": "1.0.7", "resolved": "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz", diff --git a/front/package.json b/front/package.json index f7470e1..603a86a 100644 --- a/front/package.json +++ b/front/package.json @@ -11,6 +11,7 @@ "axios": "^1.5.0", "core-js": "^3.8.3", "element-ui": "^2.15.14", + "js-cookie": "^3.0.5", "vue": "^2.6.14", "vue-router": "^3.0.2" }, diff --git a/front/src/components/login.vue b/front/src/components/login.vue index f758df7..8695df5 100644 --- a/front/src/components/login.vue +++ b/front/src/components/login.vue @@ -67,7 +67,7 @@ const that = this this.$refs[formName].validate((valid) => { if (valid) { - this.$axios.post("http://127.0.0.1:8000/login", { + this.$axios.post("/login", { username: this.ruleForm.username, password: this.ruleForm.password, type: this.ruleForm.type diff --git a/front/src/main.js b/front/src/main.js index 76419f5..b414a76 100644 --- a/front/src/main.js +++ b/front/src/main.js @@ -3,10 +3,23 @@ import App from './App.vue' import router from './router' import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; -import './plugins/axios' +import axios from "axios"; +import Cookies from 'js-cookie'; + +// axios.defaults.withCredentials = true; +let config = { + baseURL: "http://127.0.0.1:8080", + withCredentials: true, // Check cross-site Access-Control, +}; + + +const axiosInstance = axios.create(config); +axiosInstance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; + Vue.config.productionTip = false Vue.use(ElementUI); +Vue.prototype.$axios = axiosInstance new Vue({ router, diff --git a/front/src/plugins/axios.js b/front/src/plugins/axios.js index ffd6512..5d09221 100644 --- a/front/src/plugins/axios.js +++ b/front/src/plugins/axios.js @@ -1,4 +1,3 @@ -import Vue from 'vue'; import axios from "axios"; // Full config: https://github.com/axios/axios#request-config @@ -6,56 +5,16 @@ import axios from "axios"; // axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; +axios.defaults.withCredentials = true; let config = { - // bashURL: "http://127.0.0.1:8000", - // timeout: 60 * 1000, // Timeout - withCredentials: true, // Check cross-site Access-Control + baseURL: "http://127.0.0.1:8080", + withCredentials: true, // Check cross-site Access-Control, }; -const _axios = axios.create(config); -_axios.defaults.withCredentials = true; +const axiosInstance = axios.create(config); +axiosInstance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; -_axios.interceptors.request.use( - function(config) { - // Do something before request is sent - return config; - }, - function(error) { - // Do something with request error - return Promise.reject(error); - } -); -// Add a response interceptor -_axios.interceptors.response.use( - function(response) { - // Do something with response data - return response; - }, - function(error) { - // Do something with response error - return Promise.reject(error); - } -); +export default axiosInstance; -Plugin.install = function(Vue, options) { - Vue.axios = _axios; - window.axios = _axios; - Object.defineProperties(Vue.prototype, { - axios: { - get() { - return _axios; - } - }, - $axios: { - get() { - return _axios; - } - }, - }); -}; - -Vue.use(Plugin) - -export default Plugin; \ No newline at end of file diff --git a/front/src/views/student/courseInfo.vue b/front/src/views/student/courseInfo.vue index bb64e1e..c7d5def 100644 --- a/front/src/views/student/courseInfo.vue +++ b/front/src/views/student/courseInfo.vue @@ -1,46 +1,93 @@ diff --git a/front/src/views/student/courseSelect.vue b/front/src/views/student/courseSelect.vue index 9b3b26a..ec94d07 100644 --- a/front/src/views/student/courseSelect.vue +++ b/front/src/views/student/courseSelect.vue @@ -1,53 +1,134 @@ diff --git a/front/src/views/student/grade.vue b/front/src/views/student/grade.vue index b1cb322..e95b217 100644 --- a/front/src/views/student/grade.vue +++ b/front/src/views/student/grade.vue @@ -4,23 +4,23 @@ :data="tableData" style="width: 100%"> @@ -55,17 +55,22 @@ export default { data() { return { tableData: [{ - c_name: 'python', - c_type: '计算机科学与技术', - credit: 10, - t_name: "乔布斯", - middle_grade: 80, - end_grade: 50 }] } }, methods: { - + getGrade(){ + this.$axios.get("/student/getGrade?username="+sessionStorage.getItem("username")).then(resp => { + if (resp.data.code === 0){ + this.tableData = resp.data.data + }else { + this.$message({message: resp.data.message, type: "error"}) + } + }) + } + }, + mounted() { + this.getGrade() } } diff --git a/front/src/views/student/home.vue b/front/src/views/student/home.vue index 9d54ddf..1ca61e9 100644 --- a/front/src/views/student/home.vue +++ b/front/src/views/student/home.vue @@ -68,7 +68,7 @@ export default { } }, mounted() { - axios("http://127.0.0.1:8000/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { + this.$axios.get("/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { if (resp.data.code === 0 ){ const data = resp.data.data this.sid = data.sid diff --git a/front/src/views/student/studentInfo.vue b/front/src/views/student/studentInfo.vue index 97273e0..f5dac32 100644 --- a/front/src/views/student/studentInfo.vue +++ b/front/src/views/student/studentInfo.vue @@ -58,7 +58,7 @@ export default { }, methods: { onSubmit() { - axios.post("http://127.0.0.1:8000/student/", this.form).then(resp => { + this.$axios.post("/student/", this.form).then(resp => { if (resp.data.code === 0 ){ this.$message({message: resp.data.message, type: "success"}) sessionStorage.clear() @@ -70,7 +70,7 @@ export default { } }, mounted() { - axios("http://127.0.0.1:8000/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { + this.$axios("/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { if (resp.data.code === 0 ){ const data = resp.data.data this.form.sid = data.sid diff --git a/front/src/views/teacher/home.vue b/front/src/views/teacher/home.vue index f3d0ea5..738332d 100644 --- a/front/src/views/teacher/home.vue +++ b/front/src/views/teacher/home.vue @@ -70,7 +70,7 @@ } }, mounted() { - axios("http://127.0.0.1:8000/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { + this.$axios("/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { if (resp.data.code === 0 ){ this.info = resp.data.data }else { diff --git a/front/src/views/teacher/studentManage.vue b/front/src/views/teacher/studentManage.vue index a57b959..b4eb2ba 100644 --- a/front/src/views/teacher/studentManage.vue +++ b/front/src/views/teacher/studentManage.vue @@ -220,7 +220,7 @@ import axios from 'axios'; cancelButtonText: '取消', type: 'warning' }).then(() => { - axios.get("http://127.0.0.1:8000/student/delete?sid=" + row.pk).then(resp => { + this.$axios.get("/student/delete?sid=" + row.pk).then(resp => { if (resp.data.code === 0){ this.$message({ type: 'success', @@ -247,7 +247,7 @@ import axios from 'axios'; this.getAllStudent() }, getAllStudent() { - axios.post("http://127.0.0.1:8000/student/search?currentPage="+this.currentPage+"&pageSize=10", this.form).then(resp => { + this.$axios.post("/student/search?currentPage="+this.currentPage+"&pageSize=10", this.form).then(resp => { if (resp.data.code === 0) { this.total = resp.data.pageTotal this.tableData = resp.data.data @@ -266,7 +266,7 @@ import axios from 'axios'; this.loading = true; this.timer = setTimeout(() => { done(); - axios.post(this.addForm.sid === '' ? "http://127.0.0.1:8000/student/add" : "http://127.0.0.1:8000/student/", this.addForm).then(resp => { + this.$axios.post(this.addForm.sid === '' ? "/student/add" : "/student/", this.addForm).then(resp => { if(resp.data.code === 0){ this.$message({message: resp.data.message, type: "sucess"}) this.getAllStudent() diff --git a/front/src/views/teacher/teacherInfo.vue b/front/src/views/teacher/teacherInfo.vue index d921d0c..69a62b3 100644 --- a/front/src/views/teacher/teacherInfo.vue +++ b/front/src/views/teacher/teacherInfo.vue @@ -57,7 +57,7 @@ export default { }, methods: { onSubmit() { - axios.post("http://127.0.0.1:8000/teacher/", this.form).then(resp => { + this.$axios.post("/teacher/", this.form).then(resp => { if (resp.data.code === 0 ){ this.$message({message: resp.data.message, type: "success"}) sessionStorage.clear() @@ -69,7 +69,7 @@ export default { } }, mounted() { - axios("http://127.0.0.1:8000/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { + this.$axios("/userinfo?username="+sessionStorage.getItem('username')+"&type="+sessionStorage.getItem("type")).then(resp => { if (resp.data.code === 0 ){ this.form = resp.data.data }else { diff --git a/front/vue.config.js b/front/vue.config.js index 2e3b81d..4678fc9 100644 --- a/front/vue.config.js +++ b/front/vue.config.js @@ -2,7 +2,7 @@ const { defineConfig } = require('@vue/cli-service') module.exports = defineConfig({ transpileDependencies: true, lintOnSave: false, - // devServer: { - // proxy: "http://127.0.0.1:8000" - // } + devServer: { + proxy: "http://127.0.0.1:8000" + } })