Compare commits

...
2 Commits
Author SHA1 Message Date
Seven c9dce2c828 注册接口联调完成 2026-08-30 18:15:21 +08:00
Seven 9931de77de 登录接口联调完成 2026-08-30 15:24:27 +08:00
5 changed files with 35 additions and 5 deletions
+5 -2
View File
@@ -50,7 +50,10 @@ export default {
// 登录接口接入后在这里提交账号和密码 // 登录接口接入后在这里提交账号和密码
// 这里模拟登录成功,直接跳转到聊天页面 // 这里模拟登录成功,直接跳转到聊天页面
if (this.username && this.password) { if (this.username && this.password) {
login(this.username, this.password) login({
username: this.username,
password: this.password,
})
.then((response) => { .then((response) => {
const token = response.data.token; const token = response.data.token;
this.$store.commit("SET_TOKEN", token); this.$store.commit("SET_TOKEN", token);
@@ -59,7 +62,7 @@ export default {
}) })
.catch((error) => { .catch((error) => {
console.error(error); console.error(error);
this.$message.error("登录失败,请检查账号和密码"); this.$message.error("账号或密码错误");
}); });
} else { } else {
this.$message.error("请输入账号和密码"); this.$message.error("请输入账号和密码");
+11 -1
View File
@@ -44,6 +44,7 @@
</template> </template>
<script> <script>
import { register } from "@/utils/user";
export default { export default {
name: "RegisterPage", name: "RegisterPage",
data() { data() {
@@ -60,7 +61,16 @@ export default {
return return
} }
// 注册接口接入后在这里提交账号和密码。 register({
username: this.username,
password: this.password
}).then(() => {
this.$message.success('注册成功,请登录')
this.$router.push('/login')
}).catch((error) => {
console.error(error)
this.$message.error('注册失败,请重试')
})
} }
} }
}; };
+1 -1
View File
@@ -15,7 +15,7 @@ request.interceptors.request.use(
// 在请求头中添加token // 在请求头中添加token
const token = store.state.token; const token = store.state.token;
if (token) { if (token) {
config.headers['Authorization'] = `Bearer ${token}`; config.headers['Authorization'] = `${token}`;
} }
return config; return config;
}, },
+9
View File
@@ -16,3 +16,12 @@ export function getUserInfo() {
method: 'get' method: 'get'
}) })
} }
// 注册账号
export function register(data) {
return request({
url: '/register',
method: 'post',
data
})
}
+9 -1
View File
@@ -1,4 +1,12 @@
const { defineConfig } = require('@vue/cli-service') const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({ module.exports = defineConfig({
transpileDependencies: true transpileDependencies: true,
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true
}
}
}
}) })