添加统一门户登录功能,包含授权跳转和回调处理
This commit is contained in:
parent
0c4083c50f
commit
c7851b683c
|
|
@ -1,3 +1,4 @@
|
|||
import process from 'process'
|
||||
import child_process from 'child_process'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
|
@ -58,6 +59,34 @@ function getBranchName() {
|
|||
}
|
||||
return branchName
|
||||
}
|
||||
function openFolderBySystem(folderPath) {
|
||||
try {
|
||||
if (process.platform === 'win32') {
|
||||
child_process.spawn('cmd', ['/c', 'start', '', folderPath], {
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
child_process.spawn('open', [folderPath], {
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
child_process.spawn('xdg-open', [folderPath], {
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
})
|
||||
} catch (e) {
|
||||
console.log('------------------打开输出目录失败---------------')
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
function getVersion(date, mode) {
|
||||
return `${parseTime(date, 'yyyy-MM-dd hh:mm:ss')} branch:${getBranchName()} ${getHash()} mode:${mode}`
|
||||
}
|
||||
|
|
@ -149,6 +178,7 @@ export default function codeVersion() {
|
|||
console.error(err)
|
||||
})
|
||||
}
|
||||
openFolderBySystem(distPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -505,6 +505,57 @@ export function sysRsaPublic() {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} 内蒙古统一服务门户SSO登录返回信息
|
||||
* @property {string} authorizeUrl - 跳转URL
|
||||
* @property {string} companyName - 企业名称
|
||||
* @property {string} errorCode - 错误码,为空表示成功
|
||||
* @property {string} errorMsg - 错误信息
|
||||
* @property {string} phone - 手机号
|
||||
* @property {string} uniscid - 统一社会信用代码
|
||||
* @property {string} userId - 用户ID(统一服务门户)
|
||||
* @property {string} userName - 用户名
|
||||
*/
|
||||
/**
|
||||
* 1、获取统一服务门户授权跳转地址
|
||||
* 内蒙古统一服务门户单点登录接口
|
||||
* @param {string} params.redirectUri - 回调地址
|
||||
* @return {Promise<内蒙古统一服务门户SSO登录返回信息>}
|
||||
*/
|
||||
export function sysNmgSsoAuthorizeUrl(params) {
|
||||
return request({
|
||||
method: 'get',
|
||||
url: `/sys/nmg/sso/authorize/url`,
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} 内蒙古统一服务门户SSO登录返回信息
|
||||
* @property {string} authorizeUrl - 跳转URL
|
||||
* @property {string} companyName - 企业名称
|
||||
* @property {string} errorCode - 错误码,为空表示成功
|
||||
* @property {string} errorMsg - 错误信息
|
||||
* @property {string} phone - 手机号
|
||||
* @property {string} uniscid - 统一社会信用代码
|
||||
* @property {string} userId - 用户ID(统一服务门户)
|
||||
* @property {string} userName - 用户名
|
||||
*/
|
||||
/**
|
||||
* 2、统一服务门户授权回调
|
||||
* 内蒙古统一服务门户单点登录接口
|
||||
* @required @param {string} params.code - 授权码
|
||||
* @param {string} params.state - 状态码
|
||||
* @return {Promise<内蒙古统一服务门户SSO登录返回信息>}
|
||||
*/
|
||||
export function sysNmgSsoCallback(params) {
|
||||
return request({
|
||||
method: 'get',
|
||||
url: `/sys/nmg/sso/callback`,
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,10 +4,39 @@ import { getToken, setToken, removeToken } from '@/utils/auth'
|
|||
import { callMessage } from '@/utils/ui-merge'
|
||||
import { entRegisterInfoCurrent } from '@/api/市场主体信息相关'
|
||||
import { oauthLogin, oauthLoginByCerno } from '@/api/user'
|
||||
import { sysNmgSsoCallback } from '@/api/系统支撑'
|
||||
|
||||
const StartRoute = '/login'
|
||||
const skipToken = []
|
||||
const skipPortalCode = []
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.query.code && to.query.state2 === 'portal') {
|
||||
const portalCode = to.query.code
|
||||
if (!skipPortalCode.includes(portalCode)) {
|
||||
skipPortalCode.push(portalCode)
|
||||
await sysNmgSsoCallback({
|
||||
code: to.query.code,
|
||||
state: to.query.state
|
||||
}).then(() => {
|
||||
setToken('token')
|
||||
next({
|
||||
path: '/business',
|
||||
replace: true
|
||||
})
|
||||
}).catch((error) => {
|
||||
removeToken()
|
||||
callMessage({
|
||||
type: 'error',
|
||||
message: error?.message || '统一门户登录失败'
|
||||
})
|
||||
next({
|
||||
path: StartRoute,
|
||||
replace: true
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
if (to.path === '/oauth' && !skipToken.includes(to.query.token)) {
|
||||
skipToken.push(to.query.token)
|
||||
if (to.query.cerno && to.query.tel) {
|
||||
|
|
|
|||
|
|
@ -77,6 +77,15 @@ const constantRoutes = [
|
|||
showNavBack: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/login/unified',
|
||||
component: () => handlerImport(import('@/views/user/unified.vue')),
|
||||
meta: {
|
||||
roles: ['guest'],
|
||||
title: '统一门户登录',
|
||||
showNavBack: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/liaisonsRegister',
|
||||
component: () => handlerImport(import('@/views/user/LiaisonsRegister.vue')),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<script>
|
||||
import { entRegisterLogin, entRegisterLoginInfo, entRegisterLoginVerifyCode } from '@/api/市场主体信息相关'
|
||||
import { sysRsaPublic } from '@/api/系统支撑'
|
||||
import { sysNmgSsoAuthorizeUrl, sysRsaPublic } from '@/api/系统支撑'
|
||||
import JSEncrypt from 'jsencrypt'
|
||||
import { setToken } from '@/utils/auth'
|
||||
export default {
|
||||
|
|
@ -130,6 +130,14 @@ export default {
|
|||
labelPosition: 'top'
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
type: 'primary',
|
||||
plain: true,
|
||||
label: '统一门户登录',
|
||||
handler: () => {
|
||||
return this.$router.push({ path: '/login/unified' })
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'primary',
|
||||
label: '登录',
|
||||
|
|
@ -161,6 +169,20 @@ export default {
|
|||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
openUnifiedPortal() {
|
||||
return sysNmgSsoAuthorizeUrl({
|
||||
redirectUri: `${window.location.origin}${window.location.pathname}#/login?state2=portal`
|
||||
}).then((data) => {
|
||||
const authorizeUrl = data?.authorizeUrl || data?.data?.authorizeUrl
|
||||
if (authorizeUrl) {
|
||||
window.location.href = authorizeUrl
|
||||
return
|
||||
}
|
||||
throw new Error('获取统一门户授权地址失败')
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
label="进入填报前,请先成为办事企业的法人代表或者联络员"
|
||||
@click="onHandleClickToLogin"
|
||||
/>
|
||||
<van-cell
|
||||
<!-- <van-cell
|
||||
v-if="!$store.getters.userInfo.userId"
|
||||
title="联络员注册"
|
||||
is-link
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
label="联络员发生变化,请先完成【联络员变更】"
|
||||
style="border-bottom:0"
|
||||
@click="onHandleClickToChange"
|
||||
/>
|
||||
/> -->
|
||||
</van-cell-group>
|
||||
<van-cell-group
|
||||
:border="false"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<template>
|
||||
<div />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { sysNmgSsoAuthorizeUrl } from '@/api/系统支撑'
|
||||
|
||||
export default {
|
||||
name: 'UnifiedPortalLogin',
|
||||
created() {
|
||||
sysNmgSsoAuthorizeUrl({
|
||||
redirectUri: `${window.location.origin}${window.location.pathname}#/login?state2=portal`
|
||||
}).then((data) => {
|
||||
const authorizeUrl = data?.authorizeUrl || data?.data?.authorizeUrl
|
||||
if (authorizeUrl) {
|
||||
window.location.href = authorizeUrl
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Loading…
Reference in New Issue