旅游教育出版社-数字教材移动端
QYF-GitLab1
12 小时以前 8e3ee81b6ed824866734b7034604121f370f4201
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<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>