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