企微登录,禁止网页登录

main
jwg 7 months ago
parent 405cad3d97
commit 93ef3ffb6a

@ -13,5 +13,5 @@ VUE_APP_API= '/'
# 请求环境 # 请求环境
# 方楠 # 方楠
VUE_APP_BASE_API = 'http://expense-h5.lyrfp.com' VUE_APP_BASE_API = 'http://one-h5.lyrfp.com'
# VUE_APP_BASE_API = 'http://60.204.223.58:8080' # VUE_APP_BASE_API = 'http://60.204.223.58:8080'

@ -22,7 +22,8 @@ export function Wxlogin(query) {
params: query params: query
}) })
} }
// 通过code 后端获取访问用户身份
// 通过code 后端获取访问用户身份token
export function sendCode(query) { export function sendCode(query) {
return request({ return request({
url: '/system/auth/social-WeCom-login', url: '/system/auth/social-WeCom-login',
@ -30,6 +31,22 @@ export function sendCode(query) {
params: query params: query
}) })
} }
// 是否隐藏账号密码登录
export function isProhibited(query) {
return request({
url: '/system/auth/isProhibited',
method: 'get',
params: query
})
}
// 账号密码登录 绑定企业微信
export function userBind(data) {
return request({
url: '/system/social-user/bind',
method: 'POST',
data
})
}
// 获取个人权限信息 // 获取个人权限信息
export function getUserInfo() { export function getUserInfo() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -1,6 +1,17 @@
<template> <template>
<div class="layout-contain"> <div v-if="qw">
<div class="layout-view" :style="`padding-bottom: ${isTabeRouter ? safeHeight : 0 }px;`"> <div style="padding-top: 150px; text-align: center">
<img style="width: 100px; height: 100px" src="@/assets/chahao.png" />
</div>
<div style="padding-top: 20px; text-align: center">
<h4>请在客户端打开链接</h4>
</div>
</div>
<div v-else class="layout-contain">
<div
class="layout-view"
:style="`padding-bottom: ${isTabeRouter ? safeHeight : 0}px;`"
>
<transition :name="transitionActive ? 'fade' : ''" mode="out-in"> <transition :name="transitionActive ? 'fade' : ''" mode="out-in">
<keep-alive :include="isTabeRouter ? homeArr : aliveArr"> <keep-alive :include="isTabeRouter ? homeArr : aliveArr">
<router-view /> <router-view />
@ -48,24 +59,41 @@ import { mapState } from 'vuex'
export default { export default {
components: { components: {
Feedback: () => import('./components/Feedback') Feedback: () => import('./components/Feedback'),
}, },
data() { data() {
return { return {
qw: false,
safeHeight: 0, safeHeight: 0,
active: 'home-index', active: 'home-index',
aliveArr: [], aliveArr: [],
tabArr: [], tabArr: [],
homeArr: ['home-consultation', 'home-handover', 'home-index', 'home-orderManage', 'home-stat'], homeArr: [
isTabeRouter: false 'home-consultation',
'home-handover',
'home-index',
'home-orderManage',
'home-stat',
],
isTabeRouter: false,
} }
}, },
computed: { computed: {
...mapState('common', { ...mapState('common', {
transitionActive: state => state.setting.active, transitionActive: (state) => state.setting.active,
}) }),
}, },
created() { created() {
/* if (/wxwork/i.test(navigator.userAgent)) {
//
} else {
//
this.qw = true
alert('请在企业微信中打开此页面!')
//
return
// window.location.href = 'https://your-company-wechat-url'
} */
this.handleInit() this.handleInit()
this.handleAlive() this.handleAlive()
}, },
@ -78,8 +106,8 @@ export default {
this.isTabeRouter = true this.isTabeRouter = true
} }
}, },
immediate: true immediate: true,
} },
}, },
mounted() { mounted() {
if (this.$refs.layoutTab) { if (this.$refs.layoutTab) {
@ -100,13 +128,15 @@ export default {
}, },
methods: { methods: {
handleInit() { handleInit() {
const homeRoute = this.$router.options.routes.find(item => item.name === 'Home') const homeRoute = this.$router.options.routes.find(
(item) => item.name === 'Home'
)
this.tabArr = homeRoute ? homeRoute.children : [] this.tabArr = homeRoute ? homeRoute.children : []
}, },
// //
handleHomeAliveReset(obj) { handleHomeAliveReset(obj) {
if (this.homeArr.includes(obj.name)) { if (this.homeArr.includes(obj.name)) {
this.homeArr = this.homeArr.filter(item => item !== obj.name) this.homeArr = this.homeArr.filter((item) => item !== obj.name)
this.$nextTick(() => { this.$nextTick(() => {
obj.fn() obj.fn()
this.homeArr.push(obj.name) this.homeArr.push(obj.name)
@ -122,14 +152,14 @@ export default {
if (!this.aliveArr.includes(name)) this.aliveArr.push(name) if (!this.aliveArr.includes(name)) this.aliveArr.push(name)
}, },
handleRemoveLive(name) { handleRemoveLive(name) {
let index = this.aliveArr.findIndex(item => item == name) let index = this.aliveArr.findIndex((item) => item == name)
if (index > -1) { if (index > -1) {
this.aliveArr.splice(index, 1) this.aliveArr.splice(index, 1)
} }
}, },
handleAliveSet(routerArr) { handleAliveSet(routerArr) {
routerArr.forEach(el => { routerArr.forEach((el) => {
if (el.meta && el.meta.cache) { if (el.meta && el.meta.cache) {
this.aliveArr.push(el.name) this.aliveArr.push(el.name)
} }
@ -139,14 +169,14 @@ export default {
}) })
}, },
handleResetLive(name) { handleResetLive(name) {
const num = this.aliveArr.findIndex(item => item === name) const num = this.aliveArr.findIndex((item) => item === name)
if (num > -1) { if (num > -1) {
this.aliveArr.splice(num, 1) this.aliveArr.splice(num, 1)
this.$nextTick(() => { this.$nextTick(() => {
this.aliveArr.push(name) this.aliveArr.push(name)
}) })
} }
} },
} },
} }
</script> </script>

@ -143,7 +143,8 @@ export default {
// } // }
// } // }
window.localStorage.setItem('out', 1) window.localStorage.setItem('out', 1)
router.replace('/login') router.replace({path:'/login',query: {}})
// window.location.href = process.env.VUE_APP_BASE_API
}) })
}, },

@ -77,6 +77,9 @@ export default {
return JSON.parse(window.localStorage.getItem('userInfo') || { dept: {} }) return JSON.parse(window.localStorage.getItem('userInfo') || { dept: {} })
}, },
}, },
created() {
console.log(this.$route.query, 'this.$router.query')
},
mounted() { mounted() {
this.$forceCloseLoading() this.$forceCloseLoading()
this.handleFilterList() this.handleFilterList()

@ -1,5 +1,13 @@
<template> <template>
<div class="login-mobile-contain"> <div v-if="qw">
<div style="padding-top: 150px; text-align: center">
<img style="width: 100px; height: 100px" src="@/assets/chahao.png" />
</div>
<div style="padding-top: 20px; text-align: center">
<h4>请在客户端打开链接</h4>
</div>
</div>
<div v-else class="login-mobile-contain">
<div class="login-contaion flex-c flex-c-center"> <div class="login-contaion flex-c flex-c-center">
<div class="contain-topbg flex flex-center flex-c flex-c-center"> <div class="contain-topbg flex flex-center flex-c flex-c-center">
<img class="logo-img" src="@/assets/logo.png" alt="" /> <img class="logo-img" src="@/assets/logo.png" alt="" />
@ -69,12 +77,15 @@
import { mapGetters, mapActions } from 'vuex' import { mapGetters, mapActions } from 'vuex'
import { getCaptchaEnable, getTenantEnable } from '@/utils/ruoyi' import { getCaptchaEnable, getTenantEnable } from '@/utils/ruoyi'
import { getTenantIdByName } from '@/api/system/tenant' import { getTenantIdByName } from '@/api/system/tenant'
import { Wxlogin, sendCode } from '@/api/login' import { Wxlogin, sendCode, userBind, isProhibited } from '@/api/login'
import { setTenantId } from '@/utils/auth' import { setTenantId, setToken } from '@/utils/auth'
import { Toast } from 'vant' import { Toast } from 'vant'
import { getUserProfile } from '@/api/system/user'
import { setAccessToken, setLocalStorage } from '@/utils'
export default { export default {
data() { data() {
return { return {
qw: false,
loginForm: { loginForm: {
loginType: '', loginType: '',
username: '', // admin username: '', // admin
@ -91,6 +102,8 @@ export default {
captchaEnable: false, captchaEnable: false,
isRemeber: false, isRemeber: false,
firstLogin: true, firstLogin: true,
code: '',
state: '',
} }
}, },
components: { components: {
@ -100,10 +113,27 @@ export default {
...mapGetters(['devSystemList', 'devUserList']), ...mapGetters(['devSystemList', 'devUserList']),
}, },
created() { created() {
//
isProhibited().then((res) => {
if (res.data) {
console.log(res.data, 'isProhibited')
if (/wxwork/i.test(navigator.userAgent)) {
//
} else {
//
this.qw = true
this.$nextTick(() => {
alert('请在企业微信中打开此页面!')
})
return
}
}
})
// //
// this.tenantEnable = getTenantEnable(); // this.tenantEnable = getTenantEnable();
// if (this.tenantEnable) { // if (this.tenantEnable) {
// } // }
if (window.localStorage.getItem('isRemeber')) { if (window.localStorage.getItem('isRemeber')) {
this.isRemeber = true this.isRemeber = true
} else { } else {
@ -114,6 +144,51 @@ export default {
// //
// this.captchaEnable = getCaptchaEnable(); // this.captchaEnable = getCaptchaEnable();
}, },
mounted() {
// token
if (window.location.href.includes('code')) {
this.$loading(true)
let urlParams = new URLSearchParams(window.location.href.split('?')[1])
this.code = urlParams.get('code')
this.state = urlParams.get('state')
// // code
sendCode({ code: this.code, state: this.state, type: 40 })
.then(async (res) => {
if (res.data.code == 500) {
/* Toast.loading({
duration: 3, // toast
forbidClick: false,
message: res.data.msg,
}) */
this.firstLogin = true
return
}
await setToken(res.data)
await this.$store.dispatch(
'common/user/setAuthorization',
res.data.accessToken,
{
root: true,
}
)
await setAccessToken(res.data.accessToken).then(async () => {
await setLocalStorage('isOutLimit', false).then(() => {
this.$store.dispatch('common/user/outLimit', null, { root: true })
})
await getUserProfile().then((info) => {
setLocalStorage('userInfo', JSON.stringify(info.data))
})
})
this.$loading(false)
//访
// this.$router.replace('/home')
window.location.href = process.env.VUE_APP_BASE_API + '/#/home'
})
.catch((error) => {
console.log(error, 'error')
})
}
},
methods: { methods: {
handleWxLogin() { handleWxLogin() {
// //
@ -123,41 +198,20 @@ export default {
// scope: 'snsapi_privateinfo', // scope: 'snsapi_privateinfo',
// agentid: '1000002', // agentid: '1000002',
// type: 30, // type: 30,
redirectUri: 'http://expense-h5.lyrfp.com/#/login', redirectUri: process.env.VUE_APP_BASE_API + '/#/login',
}).then((res) => { }).then((res) => {
// URL
window.location.href = res.data window.location.href = res.data
Toast.loading({ /* this.$nextTick(() => {
duration: 1.5, // toast Toast.loading({
forbidClick: true, duration: 3, // toast
message: res.data + '1次', forbidClick: true,
}) message: res.data + ,
let urlParams = new URLSearchParams(window.location.href.split('?')[1])
let code = urlParams.get('code')
let state = urlParams.get('state')
// // code
sendCode({ code, state, type: 40 })
.then((res) => {
Toast.loading({
duration: 1.5, // toast
forbidClick: true,
message: res.code + 'code200',
})
//访
console.log(res, '用户敏感信息')
})
.catch((error) => {
Toast.loading({
duration: 1.5, // toast
forbidClick: true,
message: res.code + 'error500',
})
if (error.code == 500) {
this.$fm('首次登录请先账号密码登录绑定')
this.firstLogin = true
}
}) })
}) */
}) })
}, },
//
handleSetLoginInfo() { handleSetLoginInfo() {
if (this.isRemeber) { if (this.isRemeber) {
const { tenantName, username, password } = JSON.parse( const { tenantName, username, password } = JSON.parse(
@ -236,6 +290,12 @@ export default {
} }
window.localStorage.setItem('loginInfo', JSON.stringify(obj)) window.localStorage.setItem('loginInfo', JSON.stringify(obj))
} }
//
if (window.location.href.includes('code')) {
userBind({ code: this.code, state: this.state, type: 40 })
.then((res) => [console.log(res, 'userBind res')])
.catch((err) => [console.log(err, 'userBind err')])
}
this.$router.replace('/home') this.$router.replace('/home')
}) })
.catch(() => { .catch(() => {

Loading…
Cancel
Save