102 lines
2.4 KiB
Vue
102 lines
2.4 KiB
Vue
<template>
|
|
<div id="app">
|
|
<router-view class="main"/>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapState, mapActions, mapMutations } from 'vuex'
|
|
import * as dd from 'dingtalk-jsapi'
|
|
import { apiDingtalkLogin, apiUserInfo } from '@/api/login'
|
|
|
|
import VConsole from 'vconsole'
|
|
|
|
export default {
|
|
name: 'App',
|
|
data () {
|
|
return {
|
|
active: true,
|
|
fullPage: true,
|
|
dingCode: '',
|
|
dataForm: {
|
|
verify: ''
|
|
}
|
|
}
|
|
},
|
|
components: {
|
|
},
|
|
computed: {
|
|
...mapState(['user'])
|
|
},
|
|
async created () {
|
|
// if (!dd.other) {
|
|
// var vConsole = new VConsole({
|
|
// vConsole_switch_x: 0,
|
|
// vConsole_switch_y: 0
|
|
// })
|
|
// await this.handleGetDingtalkCode()
|
|
// await this.handleDingtalkLogin()
|
|
// }
|
|
|
|
this.GET_DEPLIST()
|
|
},
|
|
methods: {
|
|
onCancel () {
|
|
|
|
},
|
|
...mapActions(['GET_DEPLIST']),
|
|
...mapMutations(['SET_USER_INFO']),
|
|
// 获取钉钉鉴权码
|
|
handleGetDingtalkCode () {
|
|
return new Promise((resolve, reject) => {
|
|
let _this = this
|
|
dd.runtime.permission.requestAuthCode({
|
|
corpId: 'ding267474e759bbca1c35c2f4657eb6378f',
|
|
onSuccess (res) {
|
|
console.log('result===', res)
|
|
_this.dingCode = res
|
|
resolve()
|
|
},
|
|
onFail (err) {
|
|
console.log('err===', err)
|
|
_this.dingCode = err
|
|
resolve()
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// 钉钉免登录
|
|
async handleDingtalkLogin (val = this.dingCode) {
|
|
const res = await apiDingtalkLogin(val)
|
|
console.log('钉钉免登录res: ', res)
|
|
if (res && res.code === 200) {
|
|
this.$cookies.set('token', res.token)
|
|
await this.handleInfo()
|
|
this.dataForm.verify = '登录成功,跳转中...'
|
|
// window.open(window.location.protocol + '//' + window.location.host + '/digitization/kpi/workbench/home?code=' + this.dingCode.code)
|
|
} else {
|
|
this.dataForm.verify = '身份验证失败' + res.msg
|
|
this.$message.error(this.dataForm.verify)
|
|
this.$router.replace({ name: 'dingTalkLogin' })
|
|
}
|
|
},
|
|
// 获取用户信息
|
|
async handleInfo () {
|
|
let res = await apiUserInfo()
|
|
console.log('获取用户信息res: ', res)
|
|
if (res.code === 200) {
|
|
this.SET_USER_INFO(res.user)
|
|
this.SET_USER_AUTH(res.data)
|
|
} else {
|
|
this.$message.error(res.msg0)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
#app {
|
|
}
|
|
</style>
|