增加免登授权跳转到PC浏览器功能

This commit is contained in:
wulin 2020-08-25 14:24:59 +08:00
parent 12ecfd0f60
commit 9f0afd0561
5 changed files with 160 additions and 55 deletions

View File

@ -13,14 +13,14 @@ module.exports = {
assetsPublicPath: '/',
proxyTable: {
'/lz_management': {
target: 'http://localhost:8080',
target: 'http://192.168.43.94:8080',
changeOrigin: true
}
},
// Various Dev Server settings
// host: '192.168.43.94', // can be overwritten by process.env.HOST
host: IP, // can be overwritten by process.env.HOST
host: '192.168.43.94', // can be overwritten by process.env.HOST
port: 8001, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: true,
errorOverlay: true,

View File

@ -51,4 +51,9 @@ export const apiGetLuck = params => {
// 中将记录登记
export const apiUpdateLuck = data => {
return http({ url: '/lz_management/luck/updateLuck', method: 'post', data })
}
// 钉钉抽奖详情
export const apiDingtalkJump = params => {
return http({ url: '/lz_management/dtlg/jump', method: 'get', params })
}

View File

@ -9,6 +9,8 @@ import Router from 'vue-router'
import { apiGetMenuNav } from '@/api/api_menu'
import { isURL } from '@/utils/validate'
import { clearLoginInfo } from '@/utils'
import VConsole from 'vconsole';
let vConsole = new VConsole();
Vue.use(Router)
// 开发环境不使用懒加载, 因为懒加载页面太多的话会造成webpack热更新太慢, 所以只有生产环境使用懒加载
@ -16,6 +18,7 @@ const _import = require('./import-' + process.env.NODE_ENV)
// 全局路由(无需嵌套上左右整体布局)
const globalRoutes = [
{ path: '/dingtalklogin', component: _import('common/dingtalklogin'), name: 'dingtalklogin', meta: { title: '钉钉自动登录' } },
{ path: '/lzluck', component: _import('common/lzluck'), name: 'lzluck', meta: { title: '霖梓抽奖' } },
{ path: '/dingtalkluck', component: _import('common/dingtalkluck'), name: 'dingtalkluck', meta: { title: '钉钉抽奖登记' } },
{ path: '/404', component: _import('common/404'), name: '404', meta: { title: '404未找到' } },
@ -49,13 +52,8 @@ const mainRoutes = {
beforeEnter (to, from, next) {
let token = Vue.cookie.get('token')
if (!token || !/\S/.test(token)) {
if (isDingtalk()) {
console.log('钉钉免登测试')
next({ name: 'dingtalklogin' })
} else {
clearLoginInfo()
next({ name: 'login' })
}
clearLoginInfo()
next({ name: 'login' })
} else {
next()
}
@ -109,6 +107,18 @@ function fnCurrentRouteType (route, globalRoutes = []) {
return temp.length >= 1 ? fnCurrentRouteType(route, temp) : 'main'
}
/**
* 判断是否为钉钉打开
* @param {*} menuList
* @param {*} routes
*/
function isDingtalk () {
if (/(DingTalk)/i.test(navigator.userAgent)) {
return true
} else {
return false
}
}
/**
* 添加动态(菜单)路由
* @param {*} menuList 菜单列表

View File

@ -0,0 +1,136 @@
<template>
<div>
<div>
<div>
<div
v-loading='hasSendCode'>
<h2 class="brand-info__text">{{dataForm.verify}}</h2>
</div>
</div>
</div>
</div>
</template>
<script>
import { apiDingtalkLogin } from '@/api/api_staff'
import {apiDingtalkJump } 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: '身份验证中...'
},
req: {
code: ''
},
// captchaPath: '' //
time: 0,
timer: true,
hasSendCode: true,
tick: 1
}
},
created () {
// this.handleGetImgCaptcha()
},
mounted () {
if(this.isDingtalk()){
console.log('走钉钉免登流程')
this.dingtalkLogin()
this.checkDingTalkLogin()
} else {
this.dataForm.verify = '请在钉钉打开'
console.log(this.$route.query)
this.req.code = this.$route.query.code
apiDingtalkJump(this.req).then(res => {
console.log(res)
if (res && res.code === 0) {
console.log('获取token')
this.$cookie.set('token', res.token)
window.location.href=this.$route.query.url
//window.open(window.location.href + '&code=' + dingCode.code, "_blank")
console.log('跳转')
} else {
this.dataForm.verify='身份验证失败' + res.msg
this.$message.error(this.dataForm.verify)
this.$router.replace({ name: 'login' })
}
this.hasSendCode = false;
})
}
},
methods: {
checkDingTalkLogin () {
if(dingCode === null){
if(this.tick < 30){
this.isTick++
setTimeout(() =>{
this.checkDingTalkLogin()
}, 300)
}else{
this.$message.error('登录失败,请用账户和密码登录')
this.$router.replace({ name: 'login' })
}
} else {
this.loginWtihCode(dingCode)
}
},
isDingtalk () {
if (/(DingTalk)/i.test(navigator.userAgent)) {
return true
} else {
return false
}
},
dingtalkLogin () {
dd.runtime.permission.requestAuthCode({
corpId: 'ding02853c26606ba7d4a1320dcb25e91351',
onSuccess(result){
dingCode = result
},
onFail(err) {
console.log(err)
dingCode = err
}
})
},
loginWtihCode (result) {
console.log('免登流程')
console.log(result)
apiDingtalkLogin(result).then(res => {
console.log('获取登录结果')
console.log(res)
this.hasSendCode = false
if (res && res.code === 0) {
console.log('获取token')
this.$cookie.set('token', res.token)
this.dataForm.verify='登录成功,跳转中...'
window.open(window.location.href + '&code=' + dingCode.code, "_blank")
console.log('跳转')
} else {
this.dataForm.verify='身份验证失败' + res.msg
this.$message.error(this.dataForm.verify)
this.$router.replace({ name: 'login' })
}
})
}
}
}
</script>

View File

@ -95,14 +95,6 @@ export default {
// this.handleGetImgCaptcha()
},
mounted () {
if(this.isDingtalk()){
console.log('走钉钉免登流程')
this.dingtalkLogin()
setTimeout(() =>{
this.loginWtihCode(dingCode)
}, 3000)
}
},
methods: {
// //
@ -133,44 +125,6 @@ export default {
}
})
},
isDingtalk () {
if (/(DingTalk)/i.test(navigator.userAgent)) {
return true
} else {
return false
}
},
dingtalkLogin () {
dd.runtime.permission.requestAuthCode({
corpId: 'ding02853c26606ba7d4a1320dcb25e91351',
onSuccess: function (result) {
dingCode = result
},
onFail: function (err) {
this.$router.replace({ name: 'login' })
console.log(err)
}
})
},
loginWtihCode (result) {
console.log('免登流程')
console.log(result)
apiDingtalkLogin(result).then(res => {
console.log('获取登录结果')
console.log(res)
if (res && res.code === 0) {
console.log('获取token')
this.$cookie.set('token', res.token)
console.log('保存token')
this.$router.replace({ name: 'home' })
console.log('跳转')
} else {
this.$message.error(res.msg)
this.$router.replace({ name: 'login' })
}
})
},
//
handleVerify () {
this.dataForm.uuid = getUUID()