<template>
|
<div class="loginBox">
|
<h1>需要登录</h1>
|
<van-cell-group style="margin-top:100px;">
|
<van-field v-model="username" label="账号" placeholder="请输入账号" />
|
<van-field v-model="password" type="password" label="密码" />
|
</van-cell-group>
|
<div style="margin: 60px;">
|
<van-button round block type="info" @click="login">登录</van-button>
|
</div>
|
<!-- <h1>需要登录</h1> -->
|
<!-- <div class="username">
|
<el-input v-model="username" type="text" />
|
</div>
|
<div class="password">
|
<el-input v-model="password" type="password" />
|
</div>-->
|
<!-- <button @click="login">登录</button> -->
|
</div>
|
</template>
|
|
<script>
|
export default {
|
name: "login",
|
data() {
|
return {
|
username: "qiyunfeng",
|
password: "xA123456"
|
// username: "guest",
|
// password: "guest"
|
};
|
},
|
created() {
|
if (this.tool.getCookie("token")) {
|
this.tool.delCookie("token");
|
}
|
},
|
methods: {
|
login() {
|
let that = this;
|
const data = {
|
loginName: this.username,
|
password: this.password,
|
appRefCode: this.config.appRefCode,
|
platform: "mobile"
|
};
|
that.MG.identity.loginByPassword(data).then(res => {
|
if (res.status == "Ok") {
|
let token = res.token;
|
this.tool.setCookie(this.config.tokenKey, token);
|
sessionStorage.token = token;
|
this.getUserRole();
|
that.$router.push({
|
path: "/"
|
});
|
} else {
|
this.$toast.fail(res.data.errorDescription);
|
}
|
});
|
},
|
// 获取登录用户身份
|
getUserRole() {
|
let that = this;
|
that.MG.identity.getCurrentAppUser().then(res => {
|
if (res) {
|
that.userId = res.userId;
|
let roleData = null;
|
let teacherInfo = res.infoList.find(
|
item => item.type == "teacherInfo"
|
);
|
let wechatInfo = res.infoList.find(item => item.type == "WeChat");
|
let studentInfo = res.infoList.find(item => item.type == "student");
|
let defaultInfo = res.infoList.find(item => item.type == "Default");
|
if (res.roleLinks.length > 0) {
|
roleData = res.roleLinks.find(item => item.role.type == "appRole");
|
}
|
if (teacherInfo) {
|
this.$store.dispatch("setUserInfo", {
|
...teacherInfo,
|
role: roleData ? "Teacher" : "Student",
|
roleId: roleData ? roleData.role.id : null
|
});
|
} else if (wechatInfo) {
|
this.$store.dispatch("setUserInfo", {
|
...wechatInfo,
|
role: "Student"
|
});
|
} else if (studentInfo) {
|
this.$store.dispatch("setUserInfo", {
|
...studentInfo,
|
role: "Student"
|
});
|
} else {
|
this.$store.dispatch("setUserInfo", {
|
...defaultInfo,
|
role: "Student"
|
});
|
}
|
} else {
|
// this.$router.push({
|
// path: "/login"
|
// });
|
}
|
});
|
},
|
getNormalUserInfo(icon, nickName, name) {
|
let that = this;
|
that.request
|
.post("/api/account/setDefaultRole", { appId: that.config.appId })
|
.then(res => {
|
that.getUserRole();
|
});
|
},
|
// 获取学生基本信息
|
getStudentInfo(icon, nickName, name) {
|
let that = this;
|
that.request
|
.post("/api/EduStudent/getStudentInfo", { appId: that.config.appId })
|
.then(res => {
|
if (res) {
|
var userInfo = {
|
phone: res.phone,
|
name: name,
|
nickName: nickName,
|
role: "Student",
|
icon: icon,
|
appUserId: res.appUserId
|
};
|
that.$store.dispatch("setUserInfo", userInfo);
|
that.$router.push({
|
path: "/"
|
});
|
}
|
});
|
}
|
}
|
};
|
</script>
|
<style scoped>
|
.loginBox {
|
padding-top: 50px;
|
}
|
.loginBox h1 {
|
text-align: center;
|
font-size: 18px;
|
font-weight: bold;
|
}
|
</style>
|