|
@@ -1,15 +1,13 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <!-- <el-upload></el-upload> -->
|
|
|
+ <el-upload></el-upload>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { decrypt } from "@/utils/jsencrypt.js";
|
|
|
-import { loginRequest, Login } from "/@/api/api.js";
|
|
|
+import { JSEncrypt } from "jsencrypt";
|
|
|
+import { loginRequest, getPublickey } from "/@/api/api.js";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
-import store from "@/store/index.js";
|
|
|
-import router from "@/router/index.js";
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -19,67 +17,57 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
created() {
|
|
|
- this.checkUser();
|
|
|
+ this.getKey();
|
|
|
},
|
|
|
methods: {
|
|
|
//先获取密钥,再去认证username和mark
|
|
|
- // async getKey() {
|
|
|
- // this.publickey = await getPublickey();
|
|
|
- // sessionStorage.setItem("publicKey", this.publickey);
|
|
|
- // this.checkUser();
|
|
|
- // },
|
|
|
+ async getKey() {
|
|
|
+ this.publickey = await getPublickey();
|
|
|
+ sessionStorage.setItem("publicKey", this.publickey);
|
|
|
+ this.checkUser();
|
|
|
+ },
|
|
|
|
|
|
- async checkUser() {
|
|
|
- const username = this.$route.query.username;
|
|
|
- const a = decodeURIComponent(this.$route.query.jiami).replace(/\s/g, "+");
|
|
|
- // console.log(a);
|
|
|
- const password = decrypt(a);
|
|
|
+ checkUser() {
|
|
|
+ const userName = this.$route.query.userName;
|
|
|
+ const mark = this.$route.query.mark;
|
|
|
//判断传过来的username和mark是否为空值,如果是,则弹出身份验证不合法
|
|
|
- if (username == null || password == null) {
|
|
|
+ if (userName == null || mark == null){
|
|
|
ElMessage.error("身份验证不合法!");
|
|
|
} else {
|
|
|
- const {
|
|
|
- data: res,
|
|
|
- msg,
|
|
|
- code,
|
|
|
- } = await loginRequest({ username, password });
|
|
|
- if (code == 0) {
|
|
|
- store.commit("user/SET_TOKEN", res);
|
|
|
+ const params = {
|
|
|
+ publicKey: this.publickey,
|
|
|
+ data: this.encryptionByPublickey({
|
|
|
+ // mark: "80a7916eef8f096d4d8b64f14b99c697",
|
|
|
+ userName,
|
|
|
+ mark,
|
|
|
+ }),
|
|
|
+ };
|
|
|
|
|
|
- Login({ userId: res.userId, token: res.accessToken }).then((res) => {
|
|
|
- if (res.code == 200) {
|
|
|
- ElMessage.success("登录成功");
|
|
|
- router.push("/");
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- ElMessage.error(msg);
|
|
|
- }
|
|
|
+ loginRequest(params).then((res) => {
|
|
|
+ if (res.status !== 20000) {
|
|
|
+ ElMessage.error("单点登录错误:" + res.msg);
|
|
|
+ } else {
|
|
|
+ ElMessage.success("登录成功");
|
|
|
+ sessionStorage.setItem("ms_username", res.data.userName);
|
|
|
+ sessionStorage.setItem("ms_chinesename", res.data.chineseName);
|
|
|
+ sessionStorage.setItem("ms_id", res.data.id);
|
|
|
+ sessionStorage.setItem("token", res.token);
|
|
|
+ sessionStorage.setItem("identity", res.data.identity);
|
|
|
+ this.$router.replace("/");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- // const params = {
|
|
|
- // publicKey: this.publickey,
|
|
|
- // data: this.encryptionByPublickey({
|
|
|
- // // mark: "80a7916eef8f096d4d8b64f14b99c697",
|
|
|
- // userName,
|
|
|
- // mark,
|
|
|
- // }),
|
|
|
- // };
|
|
|
+ // 利用jsencrypt.js进行RSA加密
|
|
|
+ encryptionByPublickey(formData) {
|
|
|
+ let key = sessionStorage.getItem("publicKey");
|
|
|
+ var encrypt = new JSEncrypt();
|
|
|
+ encrypt.setPublicKey(key);
|
|
|
|
|
|
- // loginRequest(params).then((res) => {
|
|
|
- // if (res.status !== 20000) {
|
|
|
- // ElMessage.error("单点登录错误:" + res.msg);
|
|
|
- // } else {
|
|
|
- // ElMessage.success("登录成功");
|
|
|
- // sessionStorage.setItem("ms_username", res.data.userName);
|
|
|
- // sessionStorage.setItem("ms_chinesename", res.data.chineseName);
|
|
|
- // sessionStorage.setItem("ms_id", res.data.id);
|
|
|
- // sessionStorage.setItem("token", res.token);
|
|
|
- // sessionStorage.setItem("identity", res.data.identity);
|
|
|
- // this.$router.replace("/");
|
|
|
- // }
|
|
|
- // });
|
|
|
- }
|
|
|
+ var result = encrypt.encrypt(JSON.stringify(formData));
|
|
|
+ return result;
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
-</script>
|
|
|
+</script>
|