Commit da2ebda6 by yancanhua

fix: 页面授权加载优化

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