|
@@ -7,6 +7,7 @@
|
|
|
<script>
|
|
<script>
|
|
|
import encrypt from "@/utils/encrypt"; // 加密登录
|
|
import encrypt from "@/utils/encrypt"; // 加密登录
|
|
|
import { ElMessage, ElLoading } from "element-plus";
|
|
import { ElMessage, ElLoading } from "element-plus";
|
|
|
|
|
+import commonAPI from '@/api/common'
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
name: "AutoLogin",
|
|
name: "AutoLogin",
|
|
@@ -26,48 +27,81 @@ export default {
|
|
|
let that = this;
|
|
let that = this;
|
|
|
// 监听父页面发来的消息
|
|
// 监听父页面发来的消息
|
|
|
window.addEventListener('message', async (e) => {
|
|
window.addEventListener('message', async (e) => {
|
|
|
|
|
+ // console.log("校验发送来源:", e.origin);
|
|
|
// 校验发送来源,防止恶意页面跨域发送消息
|
|
// 校验发送来源,防止恶意页面跨域发送消息
|
|
|
- console.log("校验发送来源:", e.origin);
|
|
|
|
|
- if (e.origin !== 'http://localhost:5173' && e.origin !== 'http://121.43.55.7:2124') return
|
|
|
|
|
|
|
+ if(!e.origin.includes("localhost") && !e.origin.includes("121.43.55.7")) {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: "加载失败",
|
|
|
|
|
+ type: "error",
|
|
|
|
|
+ duration: 1500
|
|
|
|
|
+ });
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // that.showLoading();
|
|
|
const data = e.data
|
|
const data = e.data
|
|
|
if (data.type === 'AUTO_LOGIN') {
|
|
if (data.type === 'AUTO_LOGIN') {
|
|
|
- const { username, password } = data
|
|
|
|
|
- that.ruleForm.username = username;
|
|
|
|
|
- that.ruleForm.password = password;
|
|
|
|
|
|
|
+ // const { username, password } = data
|
|
|
|
|
+ // that.ruleForm.username = username;
|
|
|
|
|
+ // that.ruleForm.password = password;
|
|
|
// 执行登录
|
|
// 执行登录
|
|
|
- that.onAutoSubmit();
|
|
|
|
|
|
|
+ // that.onAutoSubmit();
|
|
|
|
|
+ const { token } = data
|
|
|
|
|
+ localStorage.setItem("token", token);
|
|
|
|
|
+ that.getUserByToken(token);
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
showLoading(){
|
|
showLoading(){
|
|
|
this.loginLoad = ElLoading.service({
|
|
this.loginLoad = ElLoading.service({
|
|
|
lock: true,
|
|
lock: true,
|
|
|
- text: 'Loading',
|
|
|
|
|
- background: 'rgba(0, 0, 0, 0.7)',
|
|
|
|
|
|
|
+ text: '加载地图中...',
|
|
|
|
|
+ background: '#1a2a3a',
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
+
|
|
|
|
|
+ getUserByToken(param){
|
|
|
|
|
+ // console.log(param,"getUserByToken");
|
|
|
|
|
+ let that = this;
|
|
|
|
|
+ sessionStorage.setItem("gisLoginType", "AUTO");//自动登录类型
|
|
|
|
|
+ // that.loginLoad.close();
|
|
|
|
|
+ that.$store.state.login = true;
|
|
|
|
|
+ that.$router.push("/index");
|
|
|
|
|
+ let params = {
|
|
|
|
|
+ serviceId: "0",
|
|
|
|
|
+ strUrl: "/api/user/getUserByToken",
|
|
|
|
|
+ token: param
|
|
|
|
|
+ }
|
|
|
|
|
+ commonAPI.getUserByToken(params).then((res) => {
|
|
|
|
|
+ // console.log(res,"==================");
|
|
|
|
|
+ that.$store.state.user = res.content;
|
|
|
|
|
+ // that.$router.push("/index");
|
|
|
|
|
+ }).catch((err) => {
|
|
|
|
|
+ that.$store.state.user = null;
|
|
|
|
|
+ that.$router.push("/login");
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
onAutoSubmit() {
|
|
onAutoSubmit() {
|
|
|
let that = this;
|
|
let that = this;
|
|
|
- console.log("进来了");
|
|
|
|
|
- this.showLoading();
|
|
|
|
|
encrypt(that.ruleForm).then((res) => {
|
|
encrypt(that.ruleForm).then((res) => {
|
|
|
- this.loginLoad.close();
|
|
|
|
|
|
|
+ that.loginLoad.close();
|
|
|
that.$store.state.login = true;
|
|
that.$store.state.login = true;
|
|
|
that.$store.state.user = res.content;
|
|
that.$store.state.user = res.content;
|
|
|
that.$router.push("/index");
|
|
that.$router.push("/index");
|
|
|
- ElMessage({
|
|
|
|
|
- message: "加载成功",
|
|
|
|
|
- type: "success",
|
|
|
|
|
- duration: 1500
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // ElMessage({
|
|
|
|
|
+ // message: "加载成功",
|
|
|
|
|
+ // type: "success",
|
|
|
|
|
+ // duration: 1500
|
|
|
|
|
+ // });
|
|
|
|
|
+ sessionStorage.setItem("gisLoginType", "AUTO");
|
|
|
}).catch((err) => {
|
|
}).catch((err) => {
|
|
|
- this.loginLoad.close();
|
|
|
|
|
- ElMessage({
|
|
|
|
|
- message: err,
|
|
|
|
|
- type: "error",
|
|
|
|
|
- duration: 1500
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ that.loginLoad.close();
|
|
|
|
|
+ // ElMessage({
|
|
|
|
|
+ // message: err,
|
|
|
|
|
+ // type: "error",
|
|
|
|
|
+ // duration: 1500
|
|
|
|
|
+ // });
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -78,8 +112,6 @@ export default {
|
|
|
.main {
|
|
.main {
|
|
|
height: 100%;
|
|
height: 100%;
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
- position: absolute;
|
|
|
|
|
- background-color: #fffbf0;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
</style>
|
|
</style>
|