Commit ca7f4783 by liwk

commit

1 parent ddedb36e
...@@ -50,8 +50,8 @@ fetchConfig(!isMock).then(res => { ...@@ -50,8 +50,8 @@ fetchConfig(!isMock).then(res => {
/**登录过期 重新登录 */ /**登录过期 重新登录 */
window.reLogin = () => { window.reLogin = () => {
console.log('重新登录') console.log('重新登录')
util.clearSessionId() // util.clearSessionId()
store.dispatch('navigation') // store.dispatch('navigation')
} }
window.vm = new Vue({ window.vm = new Vue({
el: '#app', el: '#app',
......
const pages = [{ const pages = {
name: 'customerGroup', customerGroup: [{
}, name: 'index',
{ }],
name: 'activity', }
meta: { const redirect = 'customerGroup'
isTab: true, let routes = []
keepAlive: true
},
children: [
]
},
]
const keepAlives = [] const keepAlives = []
const setChildren = (e, parent) => { Object.keys(pages).map(parent => {
let arr = [] pages[parent].map(val => {
e.children.map(child => { const isIndex = parent == redirect && val.name == 'index'
const { children, meta } = child let childrenPath = `${parent}/${val.name}`
let url = `${parent}/${child.name}` let meta = val
let name = url.replace(/\//g, '.') const path = isIndex ?
let route = { '/' :
path: `/${url}`, `/${val.name == 'index' ? parent : childrenPath}`
name, const name = val.name == 'index' ? parent : childrenPath.replace('/', '.')
meta: meta || {}, delete meta.name
component: resolve => require([`views/${url}.vue`], resolve)
}
if (meta && meta.keepAlive) keepAlives.push(name) if (meta && meta.keepAlive) keepAlives.push(name)
if (children) route.children = setChildren(child, url)
arr.push(route)
})
return arr
}
const getPages = _ => {
let router = {
path: '/',
name: 'home',
redirect: '/customerGroup',
component: resolve => require([`views/home.vue`], resolve),
}
router.children = pages.map(e => {
let name = `${e.name}`
let route = { let route = {
path: `/${name}`, component: resolve => require([`views/${childrenPath}.vue`], resolve),
path,
name, name,
meta: e.meta || {}, meta
component: resolve => require([`views/${name}/index.vue`], resolve)
} }
if (e.children) route.children = setChildren(e, name) routes.push(route)
if (e.meta && e.meta.keepAlive) keepAlives.push(name)
return route
}) })
return [router] })
}
console.log(getPages()) console.log(routes)
export const keeps = keepAlives export const keeps = keepAlives
export default getPages()
\ No newline at end of file \ No newline at end of file
export default routes
\ No newline at end of file \ No newline at end of file
...@@ -72,8 +72,11 @@ const actions = { ...@@ -72,8 +72,11 @@ const actions = {
code, code,
corpId corpId
}).then(({ code, data, message }) => { }).then(({ code, data, message }) => {
let url = `${window.$baseUrl}/dj-scrm-wx-work-main/#/` // const { baseURL } = window.$fetchConfig.request
let route = state.lastPath == 'home' ? '' : state.lastPath const [baseURL] = redirectUrl.split('/dj-scrm-wx-work-main/')
let url = `${baseURL}/dj-scrm-wx-work-main/#/`
let route = state.lastPath == 'coupon' ? '' : state.lastPath || ''
route = route.replace('.', '/')
state.showWindow = true state.showWindow = true
if (code == '0') { if (code == '0') {
if (data.loginList.length) { if (data.loginList.length) {
...@@ -81,9 +84,11 @@ const actions = { ...@@ -81,9 +84,11 @@ const actions = {
util.setLocalStorage('dj_scrm_loginToken', data.loginToken) util.setLocalStorage('dj_scrm_loginToken', data.loginToken)
util.setLocalStorage('dj_scrm_accountList', data.loginList) util.setLocalStorage('dj_scrm_accountList', data.loginList)
let redirect_uri = encodeURI(`${redirectUrl}${route}`) let redirect_uri = encodeURI(`${redirectUrl}${route}`)
// window.location.replace(`${url}common/accountList?redirect_uri=${redirect_uri}`) // 先注释
//以下是 本地调试 console.log('回调', `${url}common/accountList?redirect_uri=${redirect_uri}`)
let [userInfo] = data.loginList // window.location.href = `${url}common/accountList?redirect_uri=${redirect_uri}`
// 以下是 本地调试多账号
let userInfo = data.loginList[0]
let { merchantId, accountName } = userInfo let { merchantId, accountName } = userInfo
let loginAccount = accountName let loginAccount = accountName
ssoApi.selectAccount({ ssoApi.selectAccount({
...@@ -98,13 +103,13 @@ const actions = { ...@@ -98,13 +103,13 @@ const actions = {
util.setLocalStorage('dj_scrm_userInfo', res.data) util.setLocalStorage('dj_scrm_userInfo', res.data)
util.setSessionId(res.data.sessionId) util.setSessionId(res.data.sessionId)
dispatch('registerHttp', res.data.sessionId) dispatch('registerHttp', res.data.sessionId)
window.location.replace(`${redirectUrl}${route}`) window.location.replace(`${url}${route}`)
}) })
} else { } else {
let [userInfo] = data.loginList let [userInfo] = data.loginList
util.setLocalStorage('dj_scrm_userInfo', userInfo) util.setLocalStorage('dj_scrm_userInfo', userInfo)
util.setSessionId(userInfo.sessionId) util.setSessionId(userInfo.sessionId)
registerHttp(userInfo.sessionId) dispatch('registerHttp', userInfo.sessionId)
// 只有一个账号 history.back() // 只有一个账号 history.back()
console.log(`${redirectUrl}${route}`) console.log(`${redirectUrl}${route}`)
window.location.replace(`${redirectUrl}${route}`) window.location.replace(`${redirectUrl}${route}`)
...@@ -124,6 +129,7 @@ const actions = { ...@@ -124,6 +129,7 @@ const actions = {
let appid = getParams('corpId') //从链接获取 let appid = getParams('corpId') //从链接获取
let dj_scrm = util.getLocalStorage('dj_scrm_corpId') let dj_scrm = util.getLocalStorage('dj_scrm_corpId')
if (!appid) appid = dj_scrm && dj_scrm.corpId || 'ww7ee69c648ae1b7e6' if (!appid) appid = dj_scrm && dj_scrm.corpId || 'ww7ee69c648ae1b7e6'
//
util.setLocalStorage('dj_scrm_corpId', { corpId: appid }) util.setLocalStorage('dj_scrm_corpId', { corpId: appid })
// 'ww657a2d4ae89a4424' // 'ww657a2d4ae89a4424'
const wxUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize' const wxUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize'
...@@ -131,24 +137,23 @@ const actions = { ...@@ -131,24 +137,23 @@ const actions = {
} }
}, },
navigation({ dispatch }) { navigation({ dispatch }) {
util.showLoading()
const sessionId = getParams('sessionId') const sessionId = getParams('sessionId')
const storage_sessionId = util.getSessionId() const storage_sessionId = util.getSessionId()
if (sessionId || storage_sessionId) { if (sessionId || storage_sessionId) {
state.showWindow = true state.showWindow = true
util.setSessionId(sessionId || storage_sessionId) util.setSessionId(sessionId || storage_sessionId)
registerHttp(sessionId || storage_sessionId) dispatch('registerHttp', sessionId || storage_sessionId)
} else { } else {
registerHttp() util.showLoading()
dispatch('registerHttp')
dispatch('login') dispatch('login')
return return
} }
state.showWindow = true state.showWindow = true
} },
} registerHttp({}, sessionId = '') {
const registerHttp = sessionId => {
window.$HTTP = new Http({...window.$fetchConfig, alert: Notify, headers: { token: sessionId } }) window.$HTTP = new Http({...window.$fetchConfig, alert: Notify, headers: { token: sessionId } })
console.log(window.$HTTP) }
} }
const getParams = name => { const getParams = name => {
let [url, paramsList] = window.location.href.split('?') let [url, paramsList] = window.location.href.split('?')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!