微信单点登录
This commit is contained in:
parent
0e58c1db47
commit
f07322ab1f
|
@ -12,6 +12,7 @@
|
|||
import { WeChatSSO } from "@/api/login.js";
|
||||
import logo from "@/static/logo.png";
|
||||
import localStorage from "@/utils/localStorage";
|
||||
import { authApi } from "@/api/login";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
@ -27,7 +28,7 @@ export default {
|
|||
if (code == "" || code == null || code == undefined) {
|
||||
//重定向回当前页面
|
||||
var redirect = encodeURIComponent(
|
||||
"http://ufidahz.com.cn:9085/app/index.html#/pages/loginAuthen/authenWeChat"
|
||||
"http://ufidahz.com.cn:9067/V3/app/index.html#/pages/loginAuthen/authenWeChat"
|
||||
);
|
||||
var url =
|
||||
"https://open.weixin.qq.com/connect/oauth2/authorize" +
|
||||
|
@ -57,27 +58,41 @@ export default {
|
|||
async WXLogin(code) {
|
||||
let params = {
|
||||
code: code,
|
||||
appType: "weChat", //移动端类型
|
||||
appId: "800046", //请求的APIID 默认
|
||||
userApiCode: "8000460000", //请求认证的API编码 默认
|
||||
corpid: "wwb46c3f5e6ffe3e2b", //企业微信企业id
|
||||
corpsecret: "oON2ELxNVyl7wc37LeA9bNOsv_jyuFXdrvD9e0yogbQ", //企业微信密钥
|
||||
};
|
||||
let res = await WeChatSSO(params);
|
||||
if (res.code == 1) {
|
||||
localStorage.set("MIDDLEGROUND-TOKEN", res.data[0]);
|
||||
localStorage.set("MIDDLEGROUND-USERINFO", res.data[1]);
|
||||
this.$nextTick(()=>{
|
||||
uni.reLaunch({
|
||||
url: "/pages/loginAuthen/selectCompany",
|
||||
let res = await authApi("loginService", "", "appDoLogin", "", params);
|
||||
if (res.status === "200") {
|
||||
localStorage.set("MIDDLEGROUND-TOKEN", res.attribute.token);
|
||||
localStorage.set("MIDDLEGROUND-USERINFO", res.attribute.userInfo);
|
||||
uni.switchTab({
|
||||
url: "/pages/homePage/index",
|
||||
});
|
||||
})
|
||||
} else if (res.code == "1005") {
|
||||
} else if (res.status == "1005") {
|
||||
if (
|
||||
res.attribute.userid == "" ||
|
||||
res.attribute.userid == null ||
|
||||
res.attribute.userid == undefined
|
||||
) {
|
||||
this.$refs.uToast.show({
|
||||
type: "warning",
|
||||
message: "登录时获取的 code 为空, 请联系管理员处理!",
|
||||
});
|
||||
} else {
|
||||
this.$refs.uToast.show({
|
||||
type: "warning",
|
||||
message: "您尚未进行登录认证,请先认证!",
|
||||
});
|
||||
setTimeout(() => {
|
||||
localStorage.set("MIDDLEGROUND-USERID", res.data[0]);
|
||||
localStorage.set("MIDDLEGROUND-USERID", res.attribute.userid);
|
||||
uni.reLaunch({
|
||||
url: "/pages/loginAuthen/loginWeChat",
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
} else {
|
||||
localStorage.remove("MIDDLEGROUND-TOKEN");
|
||||
localStorage.remove("MIDDLEGROUND-USERINFO");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<view class="loginBox">
|
||||
<view class="logo-content">
|
||||
<image style="width: 250rpx" :src="globalConfig" mode="widthFix"></image>
|
||||
<img :src="globalConfig" alt="" class="logo" style="width: 250rpx" />
|
||||
</view>
|
||||
<u-form
|
||||
:model="userform"
|
||||
|
@ -14,7 +14,7 @@
|
|||
v-model="userform.loginCode"
|
||||
:border="'none'"
|
||||
:placeholder="'请输入账号'"
|
||||
prefixIcon="MIDDLEGROUND"
|
||||
prefixIcon="account"
|
||||
prefixIconStyle="font-size: 22px;color: #909399"
|
||||
></u--input>
|
||||
</u-form-item>
|
||||
|
@ -42,8 +42,8 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { WeChatAuthen } from "@/api/login.js";
|
||||
import logo from "@/static/logo.png";
|
||||
import { authApi } from "@/api/login";
|
||||
import logo from "@/static/logo1.png";
|
||||
import localStorage from "@/utils/localStorage";
|
||||
export default {
|
||||
data() {
|
||||
|
@ -72,16 +72,14 @@ export default {
|
|||
userid: "",
|
||||
};
|
||||
},
|
||||
onReady() {
|
||||
this.$ddFunction.setTitle("钉钉免登录认证");
|
||||
},
|
||||
methods: {
|
||||
handlerSubmit() {
|
||||
this.$refs.loginForm
|
||||
.validate()
|
||||
.then((res) => {
|
||||
let params = {
|
||||
...this.userform,
|
||||
loginCode: this.userform.loginCode,
|
||||
password: this.userform.loginPwd,
|
||||
userID: localStorage.get("MIDDLEGROUND-USERID"),
|
||||
};
|
||||
this.submit(params);
|
||||
|
@ -89,14 +87,24 @@ export default {
|
|||
.catch((errors) => {});
|
||||
},
|
||||
async submit(params) {
|
||||
let res = await WeChatAuthen(params);
|
||||
if (res.code == 1) {
|
||||
let res = await authApi(
|
||||
"loginService",
|
||||
"sysTestjdbc",
|
||||
"doLogin",
|
||||
"",
|
||||
params
|
||||
);
|
||||
if (res.status === "200") {
|
||||
this.$refs.uToast.show({
|
||||
type: "success",
|
||||
message: "认证成功!",
|
||||
});
|
||||
setTimeout(() => {
|
||||
window.location.href = "http://ufidahz.com.cn:9085/app/index.html#/pages/loginAuthen/authenWeChat"
|
||||
localStorage.set("MIDDLEGROUND-TOKEN", res.attribute.token);
|
||||
localStorage.set("MIDDLEGROUND-USERINFO", res.attribute.userInfo);
|
||||
uni.switchTab({
|
||||
url: "/pages/homePage/index",
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
|
@ -105,24 +113,19 @@ export default {
|
|||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.logo-content {
|
||||
background: #c73b26;
|
||||
border-radius: 10px;
|
||||
padding: 15px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 310rpx;
|
||||
text-align: center;
|
||||
margin: auto;
|
||||
}
|
||||
.loginBox {
|
||||
background: #ffffff;
|
||||
|
||||
.logo-content {
|
||||
width: 100%;
|
||||
font-size: 25px;
|
||||
text-align: center;
|
||||
padding-top: 20%;
|
||||
|
||||
image {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin-left: 10px;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
.loginForm {
|
||||
padding: 70rpx 80rpx;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue