diff --git a/package.json b/package.json index ea02532..7600d35 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "element-ui": "^2.15.14", "jquery": "^3.7.1", "vue": "^2.6.14", - "vue-router": "^3.5.1" + "vue-router": "^3.5.1", + "vuex": "^3.6.2" }, "devDependencies": { "@babel/core": "^7.12.16", @@ -20,6 +21,7 @@ "@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-eslint": "~5.0.0", "@vue/cli-plugin-router": "~5.0.0", + "@vue/cli-plugin-vuex": "~5.0.0", "@vue/cli-service": "~5.0.0", "eslint": "^7.32.0", "eslint-plugin-vue": "^8.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d453d4f..d621237 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ importers: vue-router: specifier: ^3.5.1 version: 3.6.5(vue@2.7.16) + vuex: + specifier: ^3.6.2 + version: 3.6.2(vue@2.7.16) devDependencies: '@babel/core': specifier: ^7.12.16 @@ -39,6 +42,9 @@ importers: '@vue/cli-plugin-router': specifier: ~5.0.0 version: 5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.13)(lodash@4.17.21)(vue-template-compiler@2.7.16)(vue@2.7.16)(webpack-sources@3.2.3)) + '@vue/cli-plugin-vuex': + specifier: ~5.0.0 + version: 5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.13)(lodash@4.17.21)(vue-template-compiler@2.7.16)(vue@2.7.16)(webpack-sources@3.2.3)) '@vue/cli-service': specifier: ~5.0.0 version: 5.0.8(@vue/compiler-sfc@3.5.13)(lodash@4.17.21)(vue-template-compiler@2.7.16)(vue@2.7.16)(webpack-sources@3.2.3) @@ -3617,6 +3623,11 @@ packages: resolution: {integrity: sha512-4gCtFXaAA3zYZdTp5s4Hl2sozuySsgz4jy1EnpBHNfpMa9dK1ZCG7viqBPCwXtmgc8nHqUsAu3G4gtmXkkY3Sw==} deprecated: Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details. + vuex@3.6.2: + resolution: {integrity: sha512-ETW44IqCgBpVomy520DT5jf8n0zoCac+sxWnn+hMe/CzaSejb/eVw2YToiXYX+Ex/AuHHia28vWTq4goAexFbw==} + peerDependencies: + vue: ^2.0.0 + watchpack@2.4.2: resolution: {integrity: sha512-TnbFSbcOCcDgjZ4piURLCbJ3nJhznVh9kw6F6iokjiFPl8ONxe9A6nMDVXDiNbrSfLILs6vB07F7wLBrwPYzJw==} engines: {node: '>=10.13.0'} @@ -7750,6 +7761,10 @@ snapshots: '@vue/compiler-sfc': 2.7.16 csstype: 3.1.3 + vuex@3.6.2(vue@2.7.16): + dependencies: + vue: 2.7.16 + watchpack@2.4.2: dependencies: glob-to-regexp: 0.4.1 diff --git a/src/App.vue b/src/App.vue index c1ca4f5..430308a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -53,6 +53,8 @@ export default { } }, methods: { + }, + mounted:()=>{ } } diff --git a/src/apiConfig.js b/src/apiConfig.js index 86169b9..93ca137 100644 --- a/src/apiConfig.js +++ b/src/apiConfig.js @@ -1,5 +1,5 @@ export default { install(Vue) { - Vue.prototype.$apiUrl = 'http://localhost:8080/learn02_war_exploded'; + Vue.prototype.$apiUrl = 'http://localhost:8080'; } }; \ No newline at end of file diff --git a/src/main.js b/src/main.js index 153417d..51eaabb 100644 --- a/src/main.js +++ b/src/main.js @@ -9,11 +9,14 @@ Vue.use(ElementUI); //引入配置作为插件 import apiConfig from './apiConfig'; + +import store from './store' Vue.use(apiConfig); Vue.config.productionTip = false new Vue({ router, + store, render: h => h(App) }).$mount('#app') diff --git a/src/router/index.js b/src/router/index.js index c32aa00..f4ff8ab 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,15 +5,21 @@ import VueRouter from 'vue-router' Vue.use(VueRouter) const routes = [ - // { - // path: '/', - // name: 'root', - // component: () => import('../App.vue') - // }, + { + path: '/', + name: 'home', + component: () => import('../App.vue') + }, { path: '/course', name: 'course', - component: () => import('../views/course/CourseList.vue') + component: () => import('../views/course/CourseList.vue'), + meta: { requiresAuth: true } + }, + { + path: '/login', + name: 'login', + component: () => import('../views/login/loginView.vue'), } ] @@ -21,4 +27,14 @@ const router = new VueRouter({ routes }) +router.beforeEach((to, _, next) => { + const isLoggedIn = localStorage.getItem('user'); + if (!to.meta.requiresAuth || isLoggedIn) { + next(); + } + else { + next({ path: '/login', query: { redirect: to.fullPath } }); + } +}); + export default router diff --git a/src/store/index.js b/src/store/index.js new file mode 100644 index 0000000..ceffa8e --- /dev/null +++ b/src/store/index.js @@ -0,0 +1,17 @@ +import Vue from 'vue' +import Vuex from 'vuex' + +Vue.use(Vuex) + +export default new Vuex.Store({ + state: { + }, + getters: { + }, + mutations: { + }, + actions: { + }, + modules: { + } +}) diff --git a/src/views/course/CourseList.vue b/src/views/course/CourseList.vue index 4ec44c7..a3d1794 100644 --- a/src/views/course/CourseList.vue +++ b/src/views/course/CourseList.vue @@ -111,13 +111,13 @@ - - + + - + - + - + - + - + - + - + @@ -151,7 +151,7 @@ @@ -184,6 +184,29 @@ export default { courseEditDialogVisible: false, courseEditForm: { id: -1, name: "", type: "", credit: "", grade: "", major: "", detail: "" }, courseAddDialogVisible: false, + courseRules:{ + name:[ + { required: true, message: '请输入课程名称', trigger: 'blur' }, + { min: 4, max: 25, message: '长度在 4 到 25 个字符', trigger: 'blur' } + ], + type: [ + { required: true, message: '课程性质不能为空' }, + ], + credit:[ + { required: true, message: '课程学分不能为空' }, + { type: 'number', message: 'invalid' } + ], + grade:[ + { required: true, message: '课程年级不能为空' }, + { type: 'number', message: 'invalid' } + ], + major:[ + { required: true, message: '课程专业不能为空' }, + ], + detail:[ + { max: 200, message: '长度应小于 200 个字符', trigger: 'blur' } + ] + }, }; }, methods: { @@ -215,7 +238,7 @@ export default { type: 'warning' }).then(() => { $.ajax({ - url: this.$apiUrl + "/courseAction/update", + url: this.$apiUrl + "/courseAction/edit", method: "POST", data: this.courseEditForm, success: (data) => { @@ -274,7 +297,7 @@ export default { message: '添加成功', showClose: true }); - this.courseEditDialogVisible = false; + this.courseAddDialogVisible = false; } this.courseListGet(); }, @@ -338,7 +361,7 @@ export default { }, courseListGet() { $.ajax({ - url: this.$apiUrl + "/courseAction/list", + url: this.$apiUrl + "/courseAction/get", method: "GET", data: { page: this.courseList.page, @@ -348,7 +371,8 @@ export default { }, success: (data) => { console.log(data); - this.courseList = data; + this.courseList.data = data.data; + this.courseList.total = data.count; }, error: (xhr) => { this.$message({ diff --git a/src/views/login/loginView.vue b/src/views/login/loginView.vue new file mode 100644 index 0000000..043baed --- /dev/null +++ b/src/views/login/loginView.vue @@ -0,0 +1,66 @@ + + + + + + + + + + + + 登录 + + + + + + + + + \ No newline at end of file diff --git a/src/views/student/studentList.vue b/src/views/student/studentList.vue new file mode 100644 index 0000000..5ebfbbc --- /dev/null +++ b/src/views/student/studentList.vue @@ -0,0 +1,12 @@ + + + + + + +