企微登录,禁止网页登录

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'

@ -22,7 +22,8 @@ export function Wxlogin(query) {
params: query
})
}
// 通过code 后端获取访问用户身份
// 通过code 后端获取访问用户身份token
export function sendCode(query) {
return request({
url: '/system/auth/social-WeCom-login',
@ -30,6 +31,22 @@ export function sendCode(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() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

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

@ -143,7 +143,8 @@ export default {
// }
// }
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: {} })
},
},
created() {
console.log(this.$route.query, 'this.$router.query')
},
mounted() {
this.$forceCloseLoading()
this.handleFilterList()

@ -1,5 +1,13 @@
<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="contain-topbg flex flex-center flex-c flex-c-center">
<img class="logo-img" src="@/assets/logo.png" alt="" />
@ -69,12 +77,15 @@
import { mapGetters, mapActions } from 'vuex'
import { getCaptchaEnable, getTenantEnable } from '@/utils/ruoyi'
import { getTenantIdByName } from '@/api/system/tenant'
import { Wxlogin, sendCode } from '@/api/login'
import { setTenantId } from '@/utils/auth'
import { Wxlogin, sendCode, userBind, isProhibited } from '@/api/login'
import { setTenantId, setToken } from '@/utils/auth'
import { Toast } from 'vant'
import { getUserProfile } from '@/api/system/user'
import { setAccessToken, setLocalStorage } from '@/utils'
export default {
data() {
return {
qw: false,
loginForm: {
loginType: '',
username: '', // admin
@ -91,6 +102,8 @@ export default {
captchaEnable: false,
isRemeber: false,
firstLogin: true,
code: '',
state: '',
}
},
components: {
@ -100,10 +113,27 @@ export default {
...mapGetters(['devSystemList', 'devUserList']),
},
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();
// if (this.tenantEnable) {
// }
if (window.localStorage.getItem('isRemeber')) {
this.isRemeber = true
} else {
@ -114,6 +144,51 @@ export default {
//
// 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: {
handleWxLogin() {
//
@ -123,41 +198,20 @@ export default {
// scope: 'snsapi_privateinfo',
// agentid: '1000002',
// type: 30,
redirectUri: 'http://expense-h5.lyrfp.com/#/login',
redirectUri: process.env.VUE_APP_BASE_API + '/#/login',
}).then((res) => {
// URL
window.location.href = res.data
Toast.loading({
duration: 1.5, // toast
forbidClick: true,
message: res.data + '1次',
})
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
}
/* this.$nextTick(() => {
Toast.loading({
duration: 3, // toast
forbidClick: true,
message: res.data + ,
})
}) */
})
},
//
handleSetLoginInfo() {
if (this.isRemeber) {
const { tenantName, username, password } = JSON.parse(
@ -236,6 +290,12 @@ export default {
}
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')
})
.catch(() => {

Loading…
Cancel
Save