From 4908ad640820fd6ca5de6153599636585fc98272 Mon Sep 17 00:00:00 2001 From: 2991692032 Date: Tue, 25 Mar 2025 15:54:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E7=9A=84/users/code=E6=94=B9?= =?UTF-8?q?=E6=88=90post=E6=96=B9=E6=B3=95,=E4=BC=A0=E9=80=92json=E6=94=B9?= =?UTF-8?q?=E6=88=90=E6=AD=A3=E7=A1=AE=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/vue-unilife/src/components/LogPage.vue | 10 +--------- .../main/java/com/unilife/config/WebMvcConfig.java | 11 +++++++++++ unilife-server/src/main/resources/application.yml | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Front/vue-unilife/src/components/LogPage.vue b/Front/vue-unilife/src/components/LogPage.vue index c341fa4..72eed6b 100644 --- a/Front/vue-unilife/src/components/LogPage.vue +++ b/Front/vue-unilife/src/components/LogPage.vue @@ -186,10 +186,8 @@ const password = computed(()=>register_password.value ?? login_password.value) const vericode = computed(()=>register_vericode.value ?? login_vericode.value) //发送邮箱验证码 async function emailcode(){ - const res = await request.get('/users/code', { - data:{ + const res = await request.post('/users/code', { email: email.value - } }) console.log("success") @@ -198,10 +196,8 @@ async function emailcode(){ //验证邮箱验证码 async function testcode() { const res = await request.post('/users/login/code', { - data: { email: email.value, code: vericode.value - } }) return res.data; @@ -209,7 +205,6 @@ async function testcode() { async function register(){ const res = await request.post('/users/register', { - data:{ email: email.value, password: password.value, username:null, @@ -218,17 +213,14 @@ async function register(){ department:null, major:null, grade:null, - } }) return res.data; } async function login(){ const res = await request.post('/users/login', { - data:{ email: email.value, password: password.value - } }) return res.data; } diff --git a/unilife-server/src/main/java/com/unilife/config/WebMvcConfig.java b/unilife-server/src/main/java/com/unilife/config/WebMvcConfig.java index a4d0d0b..e59ecf6 100644 --- a/unilife-server/src/main/java/com/unilife/config/WebMvcConfig.java +++ b/unilife-server/src/main/java/com/unilife/config/WebMvcConfig.java @@ -3,6 +3,7 @@ package com.unilife.config; import com.unilife.interceptor.JwtInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -26,4 +27,14 @@ public class WebMvcConfig implements WebMvcConfigurer { ); } + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") // 允许所有来源,生产环境建议限制为特定域名 + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") + .allowedHeaders("*") + .allowCredentials(true) + .maxAge(3600); + } + } diff --git a/unilife-server/src/main/resources/application.yml b/unilife-server/src/main/resources/application.yml index 5d0dc2f..c803148 100644 --- a/unilife-server/src/main/resources/application.yml +++ b/unilife-server/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8084 + port: 8080 spring: datasource: url: jdbc:mysql://localhost:3306/UniLife?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8