refactor(登录): 重写登录模块,接入oauth2.0(pc)、welink(mobile)
This commit is contained in:
+46
-452
@@ -9,7 +9,6 @@ import 'element-ui/lib/theme-chalk/index.css'
|
||||
import $ from 'jquery'
|
||||
// vuex
|
||||
import store from './store'
|
||||
import Axios from 'axios'
|
||||
// 复制
|
||||
import VueClipboard from 'vue-clipboard2'
|
||||
// 全局样式文件
|
||||
@@ -32,7 +31,6 @@ import dragDialogWidth from '@/common/dragDialogWidth'
|
||||
// 自定义按钮显示指令
|
||||
import btnPermission from '@/common/btnPermission' // eslint-disable-line
|
||||
import VueI18n from 'vue-i18n' // 国际化
|
||||
// import * as echarts from 'echarts'
|
||||
import { simpleUploadPath } from '@/sysConfig'
|
||||
// 时间转换
|
||||
import moment from 'moment'
|
||||
@@ -50,480 +48,76 @@ import tool from './utils/tool'
|
||||
Vue.use(tool)
|
||||
// 引入路由器
|
||||
import router from './router'
|
||||
// 路由解析器
|
||||
import Re from 'path-to-regexp'
|
||||
|
||||
import { get_verify_by_instance,loginIdm,getMenu,loginMobile } from 'api/process'
|
||||
import hwh5 from 'api/hwh5-cloudonline.js';
|
||||
import { webLoginType } from '@/sysConfig'
|
||||
|
||||
import { ssoLoginUrlDev,ssoLoginUrl,webLoginType,devWebUrl } from '@/sysConfig'
|
||||
|
||||
import { mapMutations, mapActions } from 'vuex'
|
||||
import VConsole from 'vuex'
|
||||
|
||||
|
||||
import isMobile from "./store/isMobile";
|
||||
import { Loading } from 'element-ui';
|
||||
import { getCode, toIdmLoginPage, loginInIdm, loginInPhone, close } from '@/utils/login'
|
||||
|
||||
// 路由拦截
|
||||
router.beforeEach(function (to, from, next) {
|
||||
closeLoading()
|
||||
if (isMobile()){
|
||||
var loading = Loading.service({
|
||||
text: '加载中...',
|
||||
background: '#fff'
|
||||
});
|
||||
}
|
||||
function closeLoading(){
|
||||
if (loading) {
|
||||
setTimeout(() => {
|
||||
loading.close()
|
||||
loading = null
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
let fromName = from.name
|
||||
if(fromName === undefined || fromName === null){
|
||||
window.sessionStorage.clear()
|
||||
}
|
||||
let toName = to.name
|
||||
if (toName === 'CheckPage' || toName === 'loginStandDetails' || toName === 'error'
|
||||
|| toName === 'LoginVerifyPhone') {
|
||||
next()
|
||||
closeLoading()
|
||||
return
|
||||
}
|
||||
|
||||
if(webLoginType === 'idm' && toName === 'Login'){
|
||||
window.location.href = ssoLoginUrlDev
|
||||
}
|
||||
|
||||
let token = store.state.token
|
||||
let path = to.path;
|
||||
let userName = ""
|
||||
/*
|
||||
if((fromName === undefined || fromName === null) && (path.indexOf("/standardSearch/All&userName=") !== -1 || (path.indexOf("/standardSearch/All") !== -1 && to.query.userName !== undefined))){
|
||||
if((path.indexOf("/standardSearch/All") !== -1 && to.query.userName !== undefined)){
|
||||
userName = to.query.userName
|
||||
}else {
|
||||
userName = path.split("&")[1].split("=")[1]
|
||||
}
|
||||
window.sessionStorage.clear()
|
||||
}else {
|
||||
*/
|
||||
if(fromName === 'Home2'){
|
||||
localStorage.removeItem("external")
|
||||
}
|
||||
/*
|
||||
}
|
||||
*/
|
||||
let requireAuth = to.meta.requireAuth;
|
||||
let taskId = to.query.taskIds;
|
||||
let prcId = to.query.prcId;
|
||||
let prcNum = to.query.prcNum;
|
||||
let prcName = to.query.prcName;
|
||||
let prcType = to.query.prcType;
|
||||
let routerType = to.query.routerType;
|
||||
let unShowReceipt = to.query.unShowReceipt;
|
||||
let param = "taskIds=" + taskId + "&prcId=" + prcId
|
||||
+ "&prcNum=" + prcNum + "&prcName=" + prcName + "&prcType=" + prcType;
|
||||
if (unShowReceipt) {
|
||||
param += "&unShowReceipt=" + unShowReceipt
|
||||
}
|
||||
let param4 = {
|
||||
path: path,
|
||||
token: token,
|
||||
taskId: taskId,
|
||||
prcId: prcId,
|
||||
prcNum: prcNum,
|
||||
prcName: prcName,
|
||||
prcType: prcType,
|
||||
toName: toName
|
||||
}
|
||||
let url = window.location.search
|
||||
let code = "";
|
||||
if(url){
|
||||
url = url.substr(1);
|
||||
url = url.split('&');
|
||||
let info = [];
|
||||
let obj = {};
|
||||
for (let i = 0,len = url.length; i < len; i++) {
|
||||
info = url[i].split('=')
|
||||
obj[info[0]] = decodeURI(info[1]);
|
||||
url[i] = obj;
|
||||
}
|
||||
code = url[0].code
|
||||
}
|
||||
|
||||
function extractedLocalStorage(url,param,param4) {
|
||||
localStorage.removeItem("external")
|
||||
localStorage.removeItem("routerUrl")
|
||||
localStorage.setItem('routerUrl', url)
|
||||
localStorage.removeItem("routerParam")
|
||||
localStorage.setItem('routerParam', param)
|
||||
}
|
||||
// 返回值为登录状态
|
||||
// 单点登录
|
||||
/** 判断是不是在手机端操作 */
|
||||
if (isMobile()) {
|
||||
if(toName === 'phoneHome' && (token === undefined || token === null || token === '')){
|
||||
localStorage.removeItem('token')
|
||||
token = localStorage.getItem("token")
|
||||
window.sessionStorage.clear()
|
||||
localStorage.setItem("routerName","phoneHome")
|
||||
next('/loginVerifyPhone')
|
||||
closeLoading()
|
||||
}else if(toName === 'phoneHome' && token != null && (fromName === undefined || fromName === null)){
|
||||
localStorage.removeItem('token')
|
||||
token = localStorage.getItem("token")
|
||||
window.sessionStorage.clear()
|
||||
next()
|
||||
closeLoading()
|
||||
}else if(toName === 'phoneHome' && token != null){
|
||||
next()
|
||||
closeLoading()
|
||||
} else if(toName === 'processCenter'){
|
||||
// hwh5.close();
|
||||
//关闭当前窗口
|
||||
let userAgent = navigator.userAgent;
|
||||
if (userAgent.indexOf("Firefox") !== -1 || userAgent.indexOf("Chrome") !==-1) {
|
||||
window.location.href="about:blank";
|
||||
}else if(userAgent.indexOf('Android') > -1 || userAgent.indexOf('Linux') > -1){
|
||||
window.opener=null;window.open('about:blank','_self','').close();
|
||||
}else {
|
||||
window.opener = null;
|
||||
window.open("about:blank", "_self");
|
||||
window.close();
|
||||
router.beforeEach((to, from, next) => {
|
||||
const token = store.state.token
|
||||
if (to.query.taskIds && to.query.taskIds !== '' && to.query.prcId && to.query.prcId !== '') {
|
||||
const fullPath = to.fullPath.slice(1)
|
||||
if (isMobile()) {
|
||||
if (fullPath.indexOf('phone') !== 0) {
|
||||
let path = fullPath.replace(fullPath.charAt(0), fullPath.charAt(0).toUpperCase())
|
||||
path = '/phone' + path
|
||||
next({ path: path })
|
||||
}
|
||||
//如果是微信打开,关闭当前微信窗口
|
||||
weixinClosePage()
|
||||
}else {
|
||||
if (!to.name) { // 不存在路由
|
||||
next('/blankPage')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((token === null || token === '' ) && toName !== 'Login') {
|
||||
if(toName !== 'phoneIndex'){
|
||||
if(toName === 'phoneHome'){
|
||||
// 手机端 首页 首次进入系统 清除 缓存, 防止 跳转 oa 的页面, 问题追溯 #55852
|
||||
localStorage.removeItem('token')
|
||||
token = localStorage.getItem("token")
|
||||
window.sessionStorage.clear()
|
||||
localStorage.setItem("routerName","phoneHome")
|
||||
next('/loginVerifyPhone')
|
||||
closeLoading()
|
||||
}else if(toName === 'databaseSearch' || toName === 'standDynamics' ||
|
||||
toName === 'domesticStand' || toName === 'domesticDetails' || toName === 'zlzxDetails'){
|
||||
localStorage.setItem("routerName",toName)
|
||||
next('/loginVerifyPhone')
|
||||
closeLoading()
|
||||
}else {
|
||||
if(fromName === 'phoneHome'){
|
||||
next()
|
||||
closeLoading()
|
||||
}else {
|
||||
localStorage.removeItem("param");
|
||||
localStorage.setItem('param',JSON.stringify(param4))
|
||||
next('/phoneIndex')
|
||||
closeLoading()
|
||||
}
|
||||
}
|
||||
}else {
|
||||
// 区分手机端首页 单独逻辑处理 token 为空 跳回验证页面重新验证
|
||||
if(fromName === 'databaseSearch' || fromName === 'standDynamics' ||
|
||||
fromName === 'domesticStand' || fromName === 'domesticDetails' || toName === 'zlzxDetails'){
|
||||
localStorage.setItem("routerName",toName)
|
||||
next('/loginVerifyPhone')
|
||||
closeLoading()
|
||||
}else {
|
||||
next()
|
||||
closeLoading()
|
||||
}
|
||||
}
|
||||
if (token && token !== '') {
|
||||
if (to.path === '/') {
|
||||
if (isMobile()) {
|
||||
next('/phoneHome')
|
||||
} else {
|
||||
if(toName === 'databaseSearch' || toName === 'standDynamics' || toName === 'zlzxDetails' ||
|
||||
toName === 'domesticStand' || toName === 'domesticDetails'){
|
||||
next()
|
||||
closeLoading()
|
||||
}else if (toName.slice(0,5) !== 'phone') {
|
||||
if(toName === 'LoginVerify'){
|
||||
if(toName === 'phoneHome'){
|
||||
// 手机端 首页 首次进入系统 清除 缓存, 防止 跳转 oa 的页面, 问题追溯 #55852
|
||||
localStorage.removeItem('token')
|
||||
token = localStorage.getItem("token")
|
||||
window.sessionStorage.clear()
|
||||
localStorage.setItem("routerName","phoneHome")
|
||||
next('/loginVerifyPhone')
|
||||
closeLoading()
|
||||
}else{
|
||||
next('/blankPage')
|
||||
closeLoading()
|
||||
}
|
||||
}else {
|
||||
if(toName === 'blankPage' || toName === 'processedPage') {
|
||||
next()
|
||||
closeLoading()
|
||||
}else {
|
||||
|
||||
console.log('-pc端-')
|
||||
extractedVerify()
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if(toName !== 'blankPage'){
|
||||
if(to.matched.length === 0){
|
||||
if(toName === 'phoneHome'){
|
||||
// 手机端 首页 首次进入系统 清除 缓存, 防止 跳转 oa 的页面, 问题追溯 #55852
|
||||
localStorage.removeItem('token')
|
||||
token = localStorage.getItem("token")
|
||||
window.sessionStorage.clear()
|
||||
localStorage.setItem("routerName","phoneHome")
|
||||
next('/loginVerifyPhone')
|
||||
closeLoading()
|
||||
}else{
|
||||
next('/blankPage')
|
||||
closeLoading()
|
||||
}
|
||||
}else {
|
||||
console.log('-phone端-')
|
||||
next()
|
||||
closeLoading()
|
||||
}
|
||||
}else {
|
||||
next()
|
||||
closeLoading()
|
||||
}
|
||||
}
|
||||
next('/home2')
|
||||
}
|
||||
}
|
||||
next()
|
||||
} else {
|
||||
localStorage.removeItem("routerUrl")
|
||||
localStorage.setItem('routerUrl', 'home2')
|
||||
localStorage.removeItem("routerParam")
|
||||
localStorage.setItem('routerParam', '')
|
||||
if ((token === null || token === '' ) && toName === 'OtherStandardDetails') {
|
||||
if (document.cookie) {
|
||||
if (to.path === '/login') {
|
||||
if (webLoginType === 'idm') { // webLoginType === "idm"时不会进入login路由
|
||||
// let href = window.location.href.replace('code=' + getCode(), '')
|
||||
// toIdmLoginPage(href)
|
||||
}
|
||||
if (webLoginType === 'dev') {
|
||||
next()
|
||||
closeLoading()
|
||||
return
|
||||
}
|
||||
}
|
||||
if ((token === null || token === '' ) && toName !== 'Login') {
|
||||
if(webLoginType != null && webLoginType === 'idm' ){
|
||||
if(code){
|
||||
next()
|
||||
closeLoading()
|
||||
}else {
|
||||
if (taskId !== undefined && taskId !== null && prcId !== undefined && prcId !== null) {
|
||||
extractedVerify(token)
|
||||
}else {
|
||||
/*
|
||||
if((fromName === undefined || fromName === null) && (path.indexOf("/standardSearch/All&userName") !== -1 || (path.indexOf("/standardSearch/All") !== -1 && userName !== undefined))){
|
||||
extractedLocalStorage("standardSearch/All",userName)
|
||||
localStorage.setItem('external', "external")
|
||||
next('/LoginVerifyNoEncryption')
|
||||
closeLoading()
|
||||
}else {
|
||||
*/
|
||||
if (toName === 'LoginVerifyNoEncryption') {
|
||||
next()
|
||||
closeLoading()
|
||||
}else {
|
||||
/*
|
||||
if(path === '/standardSearch/All'){
|
||||
extractedLocalStorage('standardSearch/All','');
|
||||
}else {
|
||||
*/
|
||||
extractedLocalStorage('home2','');
|
||||
/*
|
||||
}
|
||||
*/
|
||||
// ssoLoginUrlDev 默认sso 地址
|
||||
window.location.href = ssoLoginUrlDev
|
||||
}
|
||||
/*
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}else if(webLoginType != null && webLoginType === 'dev'){
|
||||
if (isMobile()) {
|
||||
extractedVerify(token)
|
||||
} else {
|
||||
next('/Login')
|
||||
closeLoading()
|
||||
}
|
||||
|
||||
}
|
||||
}else {
|
||||
extractedVerify(token)
|
||||
}
|
||||
}
|
||||
function weixinClosePage() {
|
||||
if (typeof WeixinJSBridge == "undefined") {
|
||||
if (document.addEventListener) {
|
||||
document.addEventListener('WeixinJSBridgeReady', weixin_ClosePage, false);
|
||||
} else if (document.attachEvent) {
|
||||
document.attachEvent('WeixinJSBridgeReady', weixin_ClosePage);
|
||||
document.attachEvent('onWeixinJSBridgeReady', weixin_ClosePage);
|
||||
}
|
||||
} else {
|
||||
weixin_ClosePage();
|
||||
}
|
||||
}
|
||||
function weixin_ClosePage() {
|
||||
WeixinJSBridge.call('closeWindow');
|
||||
}
|
||||
function extractedVerify() {
|
||||
if (taskId !== undefined && taskId !== null && prcId !== undefined && prcId !== null) {
|
||||
get_verify_by_instance({
|
||||
taskId: taskId, // 任务id
|
||||
pId: prcId // 流程实例
|
||||
}).then(res => {
|
||||
let hisCount = res.hisCount === undefined ? 0 : res.hisCount;
|
||||
let commitStatus = res.commitStatus === undefined ? 0 : res.commitStatus;
|
||||
let isNotFinished = res.isNotFinished === undefined ? 0 : res.isNotFinished;
|
||||
if ((hisCount && hisCount > 0)) { // 业务系统 当前节点已完成
|
||||
if(isMobile()){
|
||||
next('/processedPage')
|
||||
closeLoading()
|
||||
}else {
|
||||
next()
|
||||
closeLoading()
|
||||
}
|
||||
} else { // 业务系统 当前节点未完成
|
||||
// commitStatus 大于0 表示当前节点存在未完成干活流程
|
||||
// isNotFinished OA 系统显示接受任务 已置为已办
|
||||
if (routerType && routerType === 'oa' &&isNotFinished && isNotFinished > 0 && commitStatus && commitStatus > 0) {
|
||||
if(isMobile()) {
|
||||
extractedIphone()
|
||||
}else if (prcType === '3') {
|
||||
//标准征求意见 接受节点 未完成 oa已办 跳转详情页面
|
||||
if (path === '/bzzqyjStep3') {
|
||||
extracted2("processAcceptDetail","prcNum=" + prcNum + "&tabsName=AlreadyProcess");
|
||||
}
|
||||
}else if (prcType === '5') {
|
||||
if (path === '/xmpgStep4') {
|
||||
extracted2("processAcceptDetail","prcNum=" + prcNum + "&tabsName=AlreadyProcess");
|
||||
}
|
||||
}else if (prcType === '2') {
|
||||
if (path === '/bzdyStep3') {
|
||||
extracted2("processAcceptDetail","prcNum=" + prcNum + "&tabsName=AlreadyProcess");
|
||||
}
|
||||
}else if (prcType === '9') {
|
||||
if (path === '/bzjdStep3') {
|
||||
extracted2("processAcceptDetail","prcNum=" + prcNum + "&tabsName=AlreadyProcess");
|
||||
}
|
||||
}else if (prcType === '6') {
|
||||
if (path === '/xmpg2Step6') {
|
||||
extracted2("processAcceptDetail","prcNum=" + prcNum + "&tabsName=AlreadyProcess");
|
||||
}
|
||||
}else if (prcType === '10') {
|
||||
if (path === '/xmqdqrStep2') {
|
||||
extracted2("processAcceptDetail","prcNum=" + prcNum + "&tabsName=AlreadyProcess");
|
||||
}
|
||||
}else if (prcType === '8') {
|
||||
if (path === '/wfhxzgStep4') {
|
||||
extracted2("processAcceptDetail","prcNum=" + prcNum + "&tabsName=AlreadyProcess");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(isMobile()) {
|
||||
extractedIphone()
|
||||
}else{
|
||||
extracted3()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
function extracted(routerPath) {
|
||||
if (token === null || token === '') {
|
||||
extractedLocalStorage(routerPath,param);
|
||||
// ssoLoginUrlDev 默认sso 地址
|
||||
window.location.href = ssoLoginUrlDev
|
||||
} else {
|
||||
next({path: routerPath + '?' +param})
|
||||
closeLoading()
|
||||
}
|
||||
}
|
||||
|
||||
function extracted3() {
|
||||
if (token === null || token === '') {
|
||||
extractedLocalStorage(toName,param);
|
||||
// ssoLoginUrlDev 默认sso 地址
|
||||
window.location.href = ssoLoginUrlDev
|
||||
} else {
|
||||
if (webLoginType === 'idm') {
|
||||
if (isMobile()) {
|
||||
loginInPhone().then(() => {
|
||||
next()
|
||||
closeLoading()
|
||||
}
|
||||
}
|
||||
|
||||
function extractedIphone() {
|
||||
let paramPhone = 'taskIds=' + taskId + '&prcId=' + prcId + '&prcNum=' + prcNum +
|
||||
'&taskAssignee=' + toName + '&prcName=' + prcName + '&prcType=' + prcType
|
||||
let phoneRouter = 'phone' + toName.charAt(0).toUpperCase() + toName.slice(1)
|
||||
console.log(phoneRouter);
|
||||
next({path: phoneRouter + '?' + paramPhone})
|
||||
closeLoading()
|
||||
}
|
||||
function extracted2(routerPath,param2) {
|
||||
if (token === null || token === '') {
|
||||
extractedLocalStorage(routerPath,param2);
|
||||
// ssoLoginUrlDev 默认sso 地址
|
||||
window.location.href = ssoLoginUrlDev
|
||||
})
|
||||
} else {
|
||||
if (getCode()) {
|
||||
loginInIdm(getCode()).then(() => {
|
||||
let path = to.fullPath.replace('code=' + getCode(), '')
|
||||
next({ path })
|
||||
})
|
||||
} else {
|
||||
next({path: routerPath + '?' + param2})
|
||||
closeLoading()
|
||||
toIdmLoginPage(window.location.href)
|
||||
}
|
||||
}
|
||||
function extracted4(routerPath,param4) {
|
||||
if (token === null || token === '') {
|
||||
extractedLocalStorage(routerPath,param4);
|
||||
// ssoLoginUrlDev 默认sso 地址
|
||||
window.location.href = ssoLoginUrlDev
|
||||
} else {
|
||||
next({path: routerPath + '?' + param4})
|
||||
closeLoading()
|
||||
}
|
||||
}
|
||||
if (webLoginType === 'dev') {
|
||||
if (isMobile()) {
|
||||
next('/login')
|
||||
} else {
|
||||
next('/login')
|
||||
}
|
||||
})
|
||||
}
|
||||
if(path === '/loginVerify'){
|
||||
if(webLoginType != null && webLoginType === 'dev'){
|
||||
next('/Login')
|
||||
closeLoading()
|
||||
}else {
|
||||
next()
|
||||
closeLoading()
|
||||
}
|
||||
}else {
|
||||
/*
|
||||
if((fromName === undefined || fromName === null) && (path.indexOf("/standardSearch/All&userName") !== -1 || (path.indexOf("/standardSearch/All") !== -1 && userName !== undefined))) {
|
||||
extractedLocalStorage("standardSearch/All",userName)
|
||||
localStorage.setItem('external', "external")
|
||||
next('/LoginVerifyNoEncryption')
|
||||
closeLoading()
|
||||
}else {
|
||||
*/
|
||||
next()
|
||||
closeLoading()
|
||||
/*
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 设置用户信息
|
||||
function setUserInfo (userInfo) {
|
||||
const timeStamp = new Date().getTime().toString()
|
||||
const _USERINFO = JSON.parse(userInfo)
|
||||
_USERINFO.userId = _USERINFO.userId || _USERINFO.usId
|
||||
_USERINFO.userName = _USERINFO.userName || _USERINFO.uName
|
||||
try {
|
||||
localStorage.setItem('userInfo', JSON.stringify(_USERINFO))
|
||||
localStorage.setItem('userInfoModifyTime', timeStamp)
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
|
||||
Vue.config.productionTip = false
|
||||
// jquery
|
||||
Vue.prototype.$ = $
|
||||
@@ -537,7 +131,7 @@ Vue.use(Contextmenu)
|
||||
Vue.use(animate)
|
||||
Vue.use(vant)
|
||||
|
||||
// Vue.prototype.$echarts = echarts
|
||||
Vue.prototype.$close = close
|
||||
// 原生axios
|
||||
Vue.prototype.axios = axios
|
||||
// 封装后的axios
|
||||
|
||||
Reference in New Issue
Block a user