Commit da2ebda6 by yancanhua

fix: 页面授权加载优化

1 parent 5586b988
......@@ -11,7 +11,7 @@
</transition>
</div>
<div v-show="!isShowWindow">
<div style="text-align: center;font-size: 14px;height: 48px;line-height: 48px;">{{ windowTitle }}</div>
<div style="text-align: center;font-size: 14px;height: 48px;line-height: 48px;">无权限访问</div>
</div>
</div>
</template>
......@@ -21,7 +21,6 @@ export default {
data() {
return {
isShowWindow: false,
windowTitle: ''
}
},
watch: {
......@@ -38,12 +37,7 @@ export default {
}
},
mounted() {
const that = this
setTimeout(() => {
that.windowTitle = '无权限访问'
}, 2000);
},
mounted() {},
methods: {}
}
......
......@@ -30,21 +30,13 @@ function createRouter () {
})
}
var isLoginTimer = null;
router.beforeEach((to, from, next) => {
/* 路由发生变化修改页面title */
store.dispatch('setPageMeta', to.meta)
/* 路由发生变化修改页面背景色 */
document.documentElement.style.backgroundColor = to.meta.backgroundColor || '#fff'
to.matched.forEach(recode => {
//设置防抖,避免重复登录
if (!isLoginTimer) {
isLoginTimer = 1
setTimeout(() => {
store.dispatch('login')
isLoginTimer = null
}, 1200);
}
// store.dispatch('login')
})
if (to.matched.some(recode => recode.meta.noAuth)) {
console.log('noAuth')
......
......@@ -7,14 +7,16 @@
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { util } from 'utils'
import { util } from 'utils'
import { Http } from 'glsx-common'
import { Notify } from 'vant'
import { ssoApi } from '@/api'
import store from '@/store'
const state = {
showWindow: false,
lastPath: ''
lastPath: '',
authorizePage: false,
}
import router from '@/router'
......@@ -25,32 +27,39 @@ const mutations = {
},
SET_LAST_PATH(state, path) {
state.lastPath = path
},
SET_SHOW_WINDOW(state, showWindow) {
state.showWindow = showWindow
},
SET_AUTHORIZE_PAGE(state, authorizePage) {
state.authorizePage = authorizePage
}
}
const actions = {
setPageMeta ({ commit }, meta) {
setPageMeta({ commit }, meta) {
document.title = meta.title || '企微通知模板'
commit('SET_PAGE_META', meta)
},
registerHttp ({ }, sessionId = '') {
let { scrmRequest, djRequest } = window.$fetchConfig
registerHttp({ }, sessionId = '') {
let { scrmRequest, djRequest } = window.$fetchConfig
window.$SCRM_HTTP = new Http({ ...scrmRequest, alert: Notify })
window.$HTTP = new Http({ ...djRequest, alert: Notify, headers: { token: sessionId } })
window.$HTTP = new Http({ ...djRequest, alert: Notify, headers: { token: sessionId } })
// window.$HTTP = new Http({ ...window.$fetchConfig, alert: Notify, headers: { token: sessionId } })
},
login({ dispatch, state }) {
login({ dispatch, commit, state }) {
//获取当前路由路径
const currentPath = window.location.href;
const pathKeywords = ['/department', '/personage', '/company'];
const isTargetPath = pathKeywords.some(keyword => currentPath.includes(keyword));
const pushId = getParams('pushId');
const pushId = util.getQuery('pushId');
if (isTargetPath && (pushId && (pushId * 1) > 744)) {
state.showWindow = false
commit('SET_SHOW_WINDOW', false)
try {
let { corpId, agentId } = getParams();
const wwCode = getParams('code');
let { corpId, agentId } = util.getQuery();
const wwCode = util.getQuery('code');
let { loginUrl } = window.$fetchConfig;
let userInfo = util.getLocalStorage('ww_userInfo') || '';
if (userInfo && userInfo.timestamp) {
......@@ -59,14 +68,16 @@ const actions = {
console.log('用户登录过期');
} else {
console.log('用户已经登录');
return state.showWindow = true;
commit('SET_AUTHORIZE_PAGE', true);
return commit('SET_SHOW_WINDOW', true);
}
}
if (wwCode) {
ssoApi.login({ code: wwCode, corpId, getUserInfoFlag: false }).then(res => {
const { code, data, message } = res;
if (code == "0") {
state.showWindow = true;
commit('SET_AUTHORIZE_PAGE', true);
commit('SET_SHOW_WINDOW', true);
const hrefUrl = window.location.href;
const newUrl = hrefUrl.replace(/([?&])code=[^&]*/, (match, prefix) => { return prefix === '?' ? '?' : ''; });
window.history.replaceState({}, '', newUrl);
......@@ -83,26 +94,25 @@ const actions = {
} else throw ''
} else {
Notify({ message: message })
state.showWindow = false
commit('SET_SHOW_WINDOW', false);
commit('SET_AUTHORIZE_PAGE', false);
}
})
} else {
commit('SET_AUTHORIZE_PAGE', false);
window.location.href = `${loginUrl}?redirect_uri=${encodeURIComponent(window.location.href)}&corpId=${corpId}&agentId=${agentId}&backLoginCode=BACKCODE`
}
} catch (error) {
if (!error) error = '登录失败或无权限'
if (error) Notify(typeof error === 'string' ? error : error.toString())
}
} else {
commit('SET_AUTHORIZE_PAGE', true);
commit('SET_SHOW_WINDOW', true);
}
// else {
// state.showWindow = true
// const { corpId, agentId } = util.getLocalStorage('ww_storage_info'),
// { loginUrl } = window.$fetchConfig;
// window.location.href = `${loginUrl}?redirect_uri=${encodeURIComponent(window.location.href)}&corpId=${corpId}&agentId=${agentId}`
// }
},
navigation({ dispatch }, to) {
let { corpId, agentId, phone, name,id } = getParams(),
navigation({ dispatch, commit }, to) {
let { corpId, agentId, phone, name, id } = util.getQuery(),
userInfo = util.getLocalStorage('ww_userInfo')
if (phone) util.setLocalStorage('ww_params_phone', phone)
if (name) util.setLocalStorage('ww_params_name', name)
......@@ -115,24 +125,13 @@ const actions = {
util.setLocalStorage('ww_storage_info', ww_storage_info)
}
if (userInfo) {
state.showWindow = true
commit('SET_SHOW_WINDOW', true)
} else {
util.showLoading()
dispatch('login')
}
}
}
const getParams = name => {
let [url, paramsList] = window.location.href.split('?')
if (!paramsList) return name ? null : {}
let param = paramsList.split('&')
let obj = {}
param.map(e => {
let [key, value] = e.split('=')
obj[key] = value
})
return name ? obj[name] : obj
}
export default {
state,
mutations,
......
<!-- 公司月度总结 -->
<template>
<div class="evection-wrapper">
<div>
<div v-show="$store.state.app.authorizePage" class="evection-wrapper">
<div class="container">
<div class="header">
<div class="title">{{ infoData.monthValue }}月美团线上消费分析报告</div>
......@@ -132,6 +133,8 @@
</div>
</div>
</div>
<div v-show="!$store.state.app.authorizePage" class="loadingBox" >正在授权中...</div>
</div>
</template>
<script>
......@@ -142,6 +145,8 @@ import DataItem from './components/DataItem.vue'
import pieChart from './components/pieChart.vue'
import evectionApi from '@/api/evection'
import { formatNum, formatRatio, formatIsRatio, getIconSrc, getRatioColor } from '@/utils/tools.js'
import store from '@/store'
export default {
components: { StatisticCard, SectionTitle, DataItem, pieChart },
data() {
......@@ -269,6 +274,7 @@ export default {
},
created() {
this.getData()
store.dispatch('login')
},
methods: {
insertBurialPointRecordBatch() {
......@@ -546,4 +552,11 @@ $boxWidth: 351;
// width: formatWidth(145, $boxWidth);
// }
}
.loadingBox{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
<!-- 部门月度总结 -->
<template>
<div class="evection-wrapper">
<div>
<div v-show="$store.state.app.authorizePage" class="evection-wrapper">
<div class="container">
<div class="header">
<div class="title">{{ infoData.directOrgName }}{{ infoData.reportDetail && infoData.reportDetail.monthValue }}月美团线上消费分析报告</div>
......@@ -115,6 +116,8 @@
</div>
</div>
</div>
<div v-show="!$store.state.app.authorizePage" class="loadingBox" >正在授权中...</div>
</div>
</template>
<script>
......@@ -125,6 +128,8 @@ import DataItem from './components/DataItem.vue'
import pieChart from './components/pieChart.vue'
import evectionApi from '@/api/evection'
import { formatNum, formatRatio, formatIsRatio, getIconSrc, getRatioColor } from '@/utils/tools.js'
import store from '@/store'
export default {
components: { StatisticCard, SectionTitle, DataItem, pieChart },
data() {
......@@ -258,6 +263,7 @@ export default {
},
created() {
this.getData()
store.dispatch('login')
},
methods: {
......@@ -523,4 +529,11 @@ $boxWidth: 351;
}
}
}
.loadingBox{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
<!--个人月度总结 -->
<template>
<div class="evection-wrapper">
<div>
<div v-show="$store.state.app.authorizePage" class="evection-wrapper">
<div class="header">
<div class="title">【{{ infoData.reportDetail.monthValue }}月线上消费明细】您的专属账单已生成</div>
<div class="sub-title">尊敬的{{ infoData.staffName }},您上月美团线上消费情况如下:</div>
......@@ -69,6 +70,8 @@
<div class="tip" style="color: #ff8d1a" v-if="infoData.reportDetail.exceedCount > 0">温馨提示:您本月已超标1次,当月超标3次将有可能暂停招待权!</div>
</div>
</div>
<div v-show="!$store.state.app.authorizePage" class="loadingBox" >正在授权中...</div>
</div>
</template>
<script>
......@@ -77,6 +80,7 @@ import SectionTitle from './components/SectionTitle.vue'
import DataItem from './components/DataItem.vue'
import evectionApi from '@/api/evection'
import { parseTime } from '@/utils/tools.js'
import store from '@/store'
export default {
components: { StatisticCard, SectionTitle, DataItem },
data() {
......@@ -159,6 +163,7 @@ export default {
},
created() {
this.getData()
store.dispatch('login')
},
methods: {
getData() {
......@@ -309,4 +314,11 @@ $boxWidth: 351;
text-align: center;
}
}
.loadingBox{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!