|
@@ -11,12 +11,17 @@
|
|
label-width="0px"
|
|
label-width="0px"
|
|
class="demo-loginForm login-container"
|
|
class="demo-loginForm login-container"
|
|
>
|
|
>
|
|
- <h3 class="title">欢迎登录</h3>
|
|
|
|
|
|
+ <h3 class="title">{{ isBindDing ? '绑定手机号' : '欢迎登录'}}</h3>
|
|
<el-form-item prop="username">
|
|
<el-form-item prop="username">
|
|
<el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="账号"></el-input>
|
|
<el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="账号"></el-input>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
<el-form-item prop="password" v-show="isLoginByPsw">
|
|
<el-form-item prop="password" v-show="isLoginByPsw">
|
|
- <el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="密码"></el-input>
|
|
|
|
|
|
+ <el-input
|
|
|
|
+ type="password"
|
|
|
|
+ v-model="loginForm.password"
|
|
|
|
+ auto-complete="off"
|
|
|
|
+ placeholder="密码"
|
|
|
|
+ ></el-input>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
<el-row>
|
|
<el-row>
|
|
<el-col :span="12">
|
|
<el-col :span="12">
|
|
@@ -52,29 +57,40 @@
|
|
:loading="isLoginLoading"
|
|
:loading="isLoginLoading"
|
|
>登录</el-button>
|
|
>登录</el-button>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
- <el-form-item style="width:100%">
|
|
|
|
|
|
+ <el-form-item style="width:100%" v-show="!isBindDing">
|
|
<el-button
|
|
<el-button
|
|
type="primary"
|
|
type="primary"
|
|
style="width:100%;background:#258489;border:none;"
|
|
style="width:100%;background:#258489;border:none;"
|
|
@click="isLoginByPsw = !isLoginByPsw"
|
|
@click="isLoginByPsw = !isLoginByPsw"
|
|
>{{ isLoginByPsw ? '验证码登录' : '密码登录'}}</el-button>
|
|
>{{ isLoginByPsw ? '验证码登录' : '密码登录'}}</el-button>
|
|
<div class="ding-box">
|
|
<div class="ding-box">
|
|
- <img src="@/assets/img/ding.png" alt="" width="40" style="cursor:pointer" @click="isDingLogin = !isDingLogin">
|
|
|
|
|
|
+ <img
|
|
|
|
+ src="@/assets/img/ding.png"
|
|
|
|
+ alt
|
|
|
|
+ width="40"
|
|
|
|
+ style="cursor:pointer"
|
|
|
|
+ @click="isDingLogin = !isDingLogin"
|
|
|
|
+ />
|
|
<span style="color:#6d6d6d">第三方登录</span>
|
|
<span style="color:#6d6d6d">第三方登录</span>
|
|
</div>
|
|
</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
</el-form>
|
|
</el-form>
|
|
<div class="login-container ding-login-container" v-show="isDingLogin">
|
|
<div class="login-container ding-login-container" v-show="isDingLogin">
|
|
- <p style="font-weight:bold;font-size:18px">钉钉扫码登录</p>
|
|
|
|
- <div id="login_container"></div>
|
|
|
|
- <p style="font-weight:bold;font-size:16px;margin-bottom:20px;cursor:pointer" @click="isDingLogin = !isDingLogin"><u>账号密码登录</u></p>
|
|
|
|
|
|
+ <p style="font-weight:bold;font-size:18px">钉钉扫码登录</p>
|
|
|
|
+ <div id="login_container"></div>
|
|
|
|
+ <p
|
|
|
|
+ style="font-weight:bold;font-size:16px;margin-bottom:20px;cursor:pointer"
|
|
|
|
+ @click="isDingLogin = !isDingLogin"
|
|
|
|
+ >
|
|
|
|
+ <u>账号密码登录</u>
|
|
|
|
+ </p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
- <BaseRegister v-else :ticket="curTicket" :user="newUser" :smsCode="curSmsCode"></BaseRegister>
|
|
|
|
|
|
+ <BaseRegister v-else :ticket="curTicket" :user="newUser" :smsCode="curSmsCode" :dingLoginCode="dingLoginCode"></BaseRegister>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
<script type="text/ecmascript-6">
|
|
<script type="text/ecmascript-6">
|
|
-import { init, sendSMS, phoneLogin } from "../api/loginMG";
|
|
|
|
|
|
+import { init, sendSMS, phoneLogin, dingLogin, bindDing } from "../api/loginMG";
|
|
import { setCookie, getCookie, delCookie } from "../utils/util";
|
|
import { setCookie, getCookie, delCookie } from "../utils/util";
|
|
import BaseRegister from "../components/BaseRegister";
|
|
import BaseRegister from "../components/BaseRegister";
|
|
import md5 from "js-md5";
|
|
import md5 from "js-md5";
|
|
@@ -83,7 +99,9 @@ export default {
|
|
components: { BaseRegister },
|
|
components: { BaseRegister },
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- isDingLogin:true,
|
|
|
|
|
|
+ dingLoginCode: "",
|
|
|
|
+ isDingLogin: true,
|
|
|
|
+ isBindDing:false,
|
|
timer: 10,
|
|
timer: 10,
|
|
curTicket: "",
|
|
curTicket: "",
|
|
curSmsCode: "",
|
|
curSmsCode: "",
|
|
@@ -129,13 +147,47 @@ export default {
|
|
// 获取图形验证码
|
|
// 获取图形验证码
|
|
this.getCode();
|
|
this.getCode();
|
|
|
|
|
|
|
|
+ this.getScanCode();
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- testDing() {
|
|
|
|
- const appid = 'dingoabikplouc0kaoq7io'
|
|
|
|
- var url = encodeURIComponent('http://localhost:9999/');
|
|
|
|
- var goto = encodeURIComponent(`https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${ appid }&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${ url }`)
|
|
|
|
-
|
|
|
|
|
|
+ getScanCode() {
|
|
|
|
+ // 获取钉钉扫码登录后返回的CODE
|
|
|
|
+ this.dingLoginCode = this.getQueryVariable("code");
|
|
|
|
+ if (!this.dingLoginCode) return;
|
|
|
|
+ dingLogin(this.dingLoginCode).then(res => {
|
|
|
|
+ let status = res.result.data.status
|
|
|
|
+ // 如果返回为1 则代表未绑定手机号 需要去进行手机号绑定
|
|
|
|
+ if(status === 1){
|
|
|
|
+ this.isDingLogin = false
|
|
|
|
+ this.isBindDing = true
|
|
|
|
+ }else{
|
|
|
|
+ // 其余返回则为用户身份信息 直接进行登录操作
|
|
|
|
+ this.onLoginSuccess(res.result.data)
|
|
|
|
+ }
|
|
|
|
+ }).catch(err => {
|
|
|
|
+ this.$message.error(err)
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getQueryVariable(variable) {
|
|
|
|
+ var query = window.location.search.substring(1);
|
|
|
|
+ var vars = query.split("&");
|
|
|
|
+ for (var i = 0; i < vars.length; i++) {
|
|
|
|
+ var pair = vars[i].split("=");
|
|
|
|
+ if (pair[0] == variable) {
|
|
|
|
+ return pair[1];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ onDingScan() {
|
|
|
|
+ const appid = "dingoabikplouc0kaoq7io";
|
|
|
|
+ var url = encodeURIComponent("http://localhost:9999/");
|
|
|
|
+ var goto = encodeURIComponent(
|
|
|
|
+ `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${appid}&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${url}`
|
|
|
|
+ );
|
|
|
|
+
|
|
var obj = DDLogin({
|
|
var obj = DDLogin({
|
|
id: "login_container",
|
|
id: "login_container",
|
|
goto: goto,
|
|
goto: goto,
|
|
@@ -144,20 +196,20 @@ export default {
|
|
height: "350"
|
|
height: "350"
|
|
});
|
|
});
|
|
|
|
|
|
- var handleMessage = function (event) {
|
|
|
|
|
|
+ var handleMessage = function(event) {
|
|
var origin = event.origin;
|
|
var origin = event.origin;
|
|
- if( origin == "https://login.dingtalk.com" ) { //判断是否来自ddLogin扫码事件。
|
|
|
|
- var loginTmpCode = event.data;
|
|
|
|
- const URL = `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${appid}&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${url}&loginTmpCode=${loginTmpCode}`
|
|
|
|
- window.location.href = URL
|
|
|
|
|
|
+ if (origin == "https://login.dingtalk.com") {
|
|
|
|
+ //判断是否来自ddLogin扫码事件。
|
|
|
|
+ var loginTmpCode = event.data;
|
|
|
|
+ const URL = `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${appid}&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${url}&loginTmpCode=${loginTmpCode}`;
|
|
|
|
+ window.location.href = URL;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- if (typeof window.addEventListener != 'undefined') {
|
|
|
|
- window.addEventListener('message', handleMessage, false);
|
|
|
|
- } else if (typeof window.attachEvent != 'undefined') {
|
|
|
|
- window.attachEvent('onmessage', handleMessage);
|
|
|
|
|
|
+ if (typeof window.addEventListener != "undefined") {
|
|
|
|
+ window.addEventListener("message", handleMessage, false);
|
|
|
|
+ } else if (typeof window.attachEvent != "undefined") {
|
|
|
|
+ window.attachEvent("onmessage", handleMessage);
|
|
}
|
|
}
|
|
-
|
|
|
|
},
|
|
},
|
|
|
|
|
|
/** 发送短信验证码 */
|
|
/** 发送短信验证码 */
|
|
@@ -212,18 +264,7 @@ export default {
|
|
this.newUser = res.result.data.user;
|
|
this.newUser = res.result.data.user;
|
|
this.isShowRegister = true;
|
|
this.isShowRegister = true;
|
|
} else {
|
|
} else {
|
|
- let tokenInfo = this.$jwtDecode(res.result.data.jwt.access_token);
|
|
|
|
- localStorage.setItem("token", res.result.data.jwt.access_token);
|
|
|
|
- localStorage.setItem("tokenInfo", JSON.stringify(tokenInfo));
|
|
|
|
- localStorage.setItem("user", JSON.stringify(res.result.data.user));
|
|
|
|
- this.$message.success("登录成功!");
|
|
|
|
- this.$store.commit("login", "true");
|
|
|
|
- this.$router.push({
|
|
|
|
- path: tokenInfo.role.includes("root")
|
|
|
|
- ? "/orgs/Orgs"
|
|
|
|
- : "/member/Member"
|
|
|
|
- });
|
|
|
|
- this.isLoginLoading = false;
|
|
|
|
|
|
+ this.onLoginSuccess(res.result.data)
|
|
}
|
|
}
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
@@ -231,6 +272,29 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ onLoginSuccess(data){
|
|
|
|
+ console.log(data)
|
|
|
|
+ let tokenInfo = this.$jwtDecode(data.jwt.access_token);
|
|
|
|
+ localStorage.setItem("token", data.jwt.access_token);
|
|
|
|
+ localStorage.setItem("tokenInfo", JSON.stringify(tokenInfo));
|
|
|
|
+ localStorage.setItem("user", JSON.stringify(data.user));
|
|
|
|
+ this.$message.success("登录成功!");
|
|
|
|
+ this.isBindDing && this.onBindDing()
|
|
|
|
+ this.$store.commit("login", "true");
|
|
|
|
+ this.$router.push({
|
|
|
|
+ path: tokenInfo.role.includes("root")
|
|
|
|
+ ? "/orgs/Orgs"
|
|
|
|
+ : "/member/Member"
|
|
|
|
+ });
|
|
|
|
+ this.isLoginLoading = false;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ onBindDing(){
|
|
|
|
+ bindDing(this.dingLoginCode).then(res => {
|
|
|
|
+ if(!res.error) this.$message.success('绑定成功!')
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
/** 初始化登录随机UUID */
|
|
/** 初始化登录随机UUID */
|
|
getUUID() {
|
|
getUUID() {
|
|
function S4() {
|
|
function S4() {
|
|
@@ -280,8 +344,8 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- mounted(){
|
|
|
|
- this.testDing();
|
|
|
|
|
|
+ mounted() {
|
|
|
|
+ this.onDingScan();
|
|
}
|
|
}
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|
|
@@ -295,7 +359,7 @@ export default {
|
|
cursor: pointer;
|
|
cursor: pointer;
|
|
}
|
|
}
|
|
|
|
|
|
-.login_qrcode_content{
|
|
|
|
|
|
+.login_qrcode_content {
|
|
width: 300px !important;
|
|
width: 300px !important;
|
|
height: 300px !important;
|
|
height: 300px !important;
|
|
margin-top: 50px !important;
|
|
margin-top: 50px !important;
|
|
@@ -317,7 +381,7 @@ export default {
|
|
background-size: 100%;
|
|
background-size: 100%;
|
|
font-family: 微軟正黑體, "Heiti TC" !important;
|
|
font-family: 微軟正黑體, "Heiti TC" !important;
|
|
}
|
|
}
|
|
-.ding-login-container{
|
|
|
|
|
|
+.ding-login-container {
|
|
display: flex;
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
justify-content: center;
|
|
@@ -363,8 +427,7 @@ export default {
|
|
user-select: none;
|
|
user-select: none;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-.ding-box{
|
|
|
|
|
|
+.ding-box {
|
|
margin-top: 20px;
|
|
margin-top: 20px;
|
|
display: flex;
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex-direction: column;
|