wl_management_vue/src/views/common/dingtalkluck.vue
2020-09-29 18:27:32 +08:00

102 lines
2.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div>
<div>
<div>
<div
v-loading='hasSendCode'>
<h2 class="brand-info__text">{{ dataForm.verify }}</h2>
</div>
</div>
</div>
</div>
</template>
<script>
import {apiDingtalkLuck} from '@/api/api_staff'
import * as dd from 'dingtalk-jsapi'
var dingCode = null
export default {
data () {
return {
isloading: false,
dataForm: {
userName: '',
password: '',
uuid: '',
// captcha: ''
verify: '霖梓2020七夕抽奖登记中...,请勿离开!'
},
// captchaPath: '' // 图像验证码请求地址
time: 0,
timer: true,
hasSendCode: true
}
},
created () {
// this.handleGetImgCaptcha()
},
mounted () {
if (this.isDingtalk()) {
console.log('走钉钉免登流程')
this.dingtalkLogin()
this.checkDingTalkLogin()
} else {
this.verify = '请使用手机钉钉扫码打开'
}
},
methods: {
checkDingTalkLogin () {
if (dingCode === null) {
setTimeout(() => {
this.checkDingTalkLogin()
}, 300)
} else {
this.loginWtihCode(dingCode)
}
},
isDingtalk () {
if (/(DingTalk)/i.test(navigator.userAgent)) {
return true
} else {
return false
}
},
dingtalkLogin () {
dd.runtime.permission.requestAuthCode({
corpId: 'ding267474e759bbca1c35c2f4657eb6378f',
onSuccess (result) {
dingCode = result
console.log(dingCode)
},
onFail (err) {
console.log(err)
dingCode = err
}
})
},
loginWtihCode (result) {
console.log('免登流程')
console.log(result)
apiDingtalkLuck(result).then(res => {
console.log('获取登录结果')
console.log(res)
this.hasSendCode = false
if (res && res.code === 0) {
console.log('获取token')
this.dataForm.verify = '已经登记祝您好运七夕下午5点20分员工新天地现场开奖'
console.log('跳转')
} else {
this.dataForm.verify = '无法登记。' + res.msg
this.$message.error(res.msg)
}
})
}
}
}
</script>