|
|
@@ -0,0 +1,52 @@
|
|
|
+<template>
|
|
|
+
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: "loginByUserName",
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ };
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.handleLoginByUser();
|
|
|
+ console.log('组件创建成功');
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleLoginByUser() {
|
|
|
+ // 从URL参数中获取username(关键步骤)
|
|
|
+ const userName = this.$route.query.username;
|
|
|
+ console.log('用户名参数:', userName);
|
|
|
+ // //检查username是否存在,不存在则不发起登录(可根据需求处理错误)
|
|
|
+ // if (!userName) {
|
|
|
+ // console.error("URL中未包含username参数");
|
|
|
+ // this.loading = false;
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ this.loading = true;
|
|
|
+
|
|
|
+ // 调用login2接口,传递URL中获取的username(POST请求由Vuex的Login2处理)
|
|
|
+ this.$store
|
|
|
+ .dispatch("login2", userName)
|
|
|
+ .then((response) => {
|
|
|
+ // 可以接收 action 返回的数据
|
|
|
+ console.log("登录成功,用户信息:", response);
|
|
|
+ this.$router.push({ path: this.redirect || "/" });
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("登录失败:", error);
|
|
|
+ this.$message.error(error.message); // 显示错误提示
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|