|
@@ -5,118 +5,113 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
-import axios from "axios";
|
|
|
|
|
|
+import axios from 'axios'
|
|
export default {
|
|
export default {
|
|
- name: "App",
|
|
|
|
|
|
+ name: 'App',
|
|
components: {},
|
|
components: {},
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- appid: "dingrucgsnt8p13rfbgd",
|
|
|
|
- redirectUrl: "https://localhost:5001/login",
|
|
|
|
- apiUrl: "/common/login/DingLogin",
|
|
|
|
|
|
+ appid: 'dingrucgsnt8p13rfbgd',
|
|
|
|
+ redirectUrl: 'https://bitest.teammodel.cn/login',
|
|
|
|
+ apiUrl: '/common/login/DingLogin',
|
|
dingCodeConfig: {
|
|
dingCodeConfig: {
|
|
- id: "login_container",
|
|
|
|
- style: "background-color:#FFFFFF;",
|
|
|
|
- width: "300",
|
|
|
|
- height: "350",
|
|
|
|
|
|
+ id: 'login_container',
|
|
|
|
+ style: 'background-color:#FFFFFF;',
|
|
|
|
+ width: '300',
|
|
|
|
+ height: '350',
|
|
},
|
|
},
|
|
- };
|
|
|
|
|
|
+ }
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
getRedirectUrl() {
|
|
getRedirectUrl() {
|
|
- return encodeURIComponent(this.redirectUrl);
|
|
|
|
|
|
+ return encodeURIComponent(this.redirectUrl)
|
|
},
|
|
},
|
|
getAuthUrl() {
|
|
getAuthUrl() {
|
|
- return `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${this.appid}&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${this.getRedirectUrl}`;
|
|
|
|
|
|
+ return `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${this.appid}&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${this.getRedirectUrl}`
|
|
},
|
|
},
|
|
getGoto() {
|
|
getGoto() {
|
|
- return encodeURIComponent(this.getAuthUrl);
|
|
|
|
|
|
+ return encodeURIComponent(this.getAuthUrl)
|
|
},
|
|
},
|
|
getDingCodeConfig() {
|
|
getDingCodeConfig() {
|
|
- return { ...this.dingCodeConfig, goto: this.getGoto };
|
|
|
|
|
|
+ return { ...this.dingCodeConfig, goto: this.getGoto }
|
|
},
|
|
},
|
|
},
|
|
},
|
|
created() {
|
|
created() {
|
|
- this.initDingJs();
|
|
|
|
|
|
+ this.initDingJs()
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
- this.addDingListener();
|
|
|
|
- this.initDingLogin();
|
|
|
|
- this.getUser();
|
|
|
|
|
|
+ this.addDingListener()
|
|
|
|
+ this.initDingLogin()
|
|
|
|
+ this.getUser()
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
initDingJs() {
|
|
initDingJs() {
|
|
!(function (window, document) {
|
|
!(function (window, document) {
|
|
function d(a) {
|
|
function d(a) {
|
|
var e,
|
|
var e,
|
|
- c = document.createElement("iframe"),
|
|
|
|
- d =
|
|
|
|
- "https://login.dingtalk.com/login/qrcode.htm?goto=" +
|
|
|
|
- a.goto;
|
|
|
|
- (d += a.style
|
|
|
|
- ? "&style=" + encodeURIComponent(a.style)
|
|
|
|
- : ""),
|
|
|
|
- (d += a.href ? "&href=" + a.href : ""),
|
|
|
|
|
|
+ c = document.createElement('iframe'),
|
|
|
|
+ d = 'https://login.dingtalk.com/login/qrcode.htm?goto=' + a.goto
|
|
|
|
+ ;(d += a.style ? '&style=' + encodeURIComponent(a.style) : ''),
|
|
|
|
+ (d += a.href ? '&href=' + a.href : ''),
|
|
(c.src = d),
|
|
(c.src = d),
|
|
- (c.frameBorder = "0"),
|
|
|
|
- (c.allowTransparency = "true"),
|
|
|
|
- (c.scrolling = "no"),
|
|
|
|
- (c.width = a.width ? a.width + "px" : "365px"),
|
|
|
|
- (c.height = a.height ? a.height + "px" : "400px"),
|
|
|
|
|
|
+ (c.frameBorder = '0'),
|
|
|
|
+ (c.allowTransparency = 'true'),
|
|
|
|
+ (c.scrolling = 'no'),
|
|
|
|
+ (c.width = a.width ? a.width + 'px' : '365px'),
|
|
|
|
+ (c.height = a.height ? a.height + 'px' : '400px'),
|
|
(e = document.getElementById(a.id)),
|
|
(e = document.getElementById(a.id)),
|
|
- (e.innerHTML = ""),
|
|
|
|
- e.appendChild(c);
|
|
|
|
|
|
+ (e.innerHTML = ''),
|
|
|
|
+ e.appendChild(c)
|
|
}
|
|
}
|
|
|
|
|
|
- window.DDLogin = d;
|
|
|
|
- })(window, document);
|
|
|
|
|
|
+ window.DDLogin = d
|
|
|
|
+ })(window, document)
|
|
},
|
|
},
|
|
addDingListener() {
|
|
addDingListener() {
|
|
- let self = this;
|
|
|
|
|
|
+ let self = this
|
|
|
|
|
|
let handleLoginTmpCode = function (loginTmpCode) {
|
|
let handleLoginTmpCode = function (loginTmpCode) {
|
|
- window.location.href =
|
|
|
|
- self.getAuthUrl + `&loginTmpCode=${loginTmpCode}`;
|
|
|
|
- };
|
|
|
|
|
|
+ window.location.href = self.getAuthUrl + `&loginTmpCode=${loginTmpCode}`
|
|
|
|
+ }
|
|
|
|
|
|
let handleMessage = function (event) {
|
|
let handleMessage = function (event) {
|
|
- if (event.origin == "https://login.dingtalk.com") {
|
|
|
|
- handleLoginTmpCode(event.data);
|
|
|
|
|
|
+ if (event.origin == 'https://login.dingtalk.com') {
|
|
|
|
+ handleLoginTmpCode(event.data)
|
|
}
|
|
}
|
|
- };
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- 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)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
initDingLogin() {
|
|
initDingLogin() {
|
|
- window.DDLogin(this.getDingCodeConfig);
|
|
|
|
|
|
+ window.DDLogin(this.getDingCodeConfig)
|
|
},
|
|
},
|
|
getUser() {
|
|
getUser() {
|
|
let getQueryString = function (name) {
|
|
let getQueryString = function (name) {
|
|
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
|
|
|
|
- var r = window.location.search.substr(1).match(reg);
|
|
|
|
|
|
+ var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
|
|
|
|
+ var r = window.location.search.substr(1).match(reg)
|
|
if (r != null) {
|
|
if (r != null) {
|
|
- return unescape(r[2]);
|
|
|
|
|
|
+ return unescape(r[2])
|
|
}
|
|
}
|
|
- return null;
|
|
|
|
- };
|
|
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
|
|
|
|
- let code = getQueryString("code");
|
|
|
|
|
|
+ let code = getQueryString('code')
|
|
|
|
|
|
if (code !== null) {
|
|
if (code !== null) {
|
|
axios
|
|
axios
|
|
.get(`${this.apiUrl}?code=${code}`)
|
|
.get(`${this.apiUrl}?code=${code}`)
|
|
.then((response) => {
|
|
.then((response) => {
|
|
- console.log(response);
|
|
|
|
|
|
+ console.log(response)
|
|
})
|
|
})
|
|
.catch((error) => {
|
|
.catch((error) => {
|
|
- console.log(error);
|
|
|
|
- });
|
|
|
|
|
|
+ console.log(error)
|
|
|
|
+ })
|
|
}
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
-};
|
|
|
|
|
|
+}
|
|
</script>
|
|
</script>
|