Commit b101b417 by liwk

commit

1 parent 4249e5f4
......@@ -21,7 +21,6 @@ import { bus, tools, store as local } from './utils'
import './utils/util'
import 'components'
import { components } from '@/plugins/vant'
import { Http } from 'glsx-common'
components.forEach(component => Vue.use(component))
Vue.prototype.api = api
Vue.prototype.bus = bus
......@@ -45,10 +44,8 @@ fetchConfig(!isMock).then(res => {
// 从配置服务器获取动态配置
// 设置 js中可以访问 $cdn
Vue.use(cfg)
window.$baseUrl = res.request.baseURL
window.$HTTP = new Http({...res, alert: components.Notify })
/**登录过期 重新登录 */
window.$fetchConfig = res
/**登录过期 重新登录 */
window.reLogin = () => {
console.log(123)
}
......
......@@ -7,8 +7,9 @@
* @LastEditTime: 2021-07-06 12:02:21
*/
import { ssoApi } from '@/api'
import { store } from 'utils'
import util from '@/utils/util'
import { store, util } from 'utils'
import { Http } from 'glsx-common'
import { Notify } from 'vant'
const state = {
pageMeta: '',
keepAlives: [],
......@@ -61,11 +62,14 @@ const actions = {
removeKeep({ commit }, names) {
commit('REMOVE_KEEP', names)
},
registerHttp({}, sessionId = '') {
window.$HTTP = new Http({...window.$fetchConfig, alert: Notify, headers: { token: sessionId } })
},
login() {
let [redirectUrl] = window.location.href.split('?')
const code = getParams('code')
if (code) {
const corpId = util.getLocalStorage('dj_scrm_corpId')
const { corpId } = util.getLocalStorage('dj_scrm_corpId')
ssoApi.login({
code,
corpId
......@@ -82,7 +86,8 @@ const actions = {
} else {
let [userInfo] = data.loginList
util.setLocalStorage('dj_scrm_userInfo', userInfo)
util.setLocalStorage('dj_scrm_session_id', userInfo.sessionId)
util.setSessionId(userInfo.sessionId)
dispatch('registerHttp', userInfo.sessionId)
// 只有一个账号 history.back()
window.location.replace(`${url}${route}`)
}
......@@ -100,7 +105,7 @@ const actions = {
util.showLoading()
let corpId = getParams('corpId') //从链接获取
if (!corpId) corpId = 'ww7ee69c648ae1b7e6'
util.setLocalStorage('dj_scrm_corpId', corpId)
util.setLocalStorage('dj_scrm_corpId', { corpId })
// 'ww657a2d4ae89a4424'
const wxUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize'
window.location.replace(`${wxUrl}?appid=${corpId}&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`)
......@@ -111,6 +116,7 @@ const actions = {
let loginToken = util.getLocalStorage('dj_scrm_loginToken')
let userInfo = util.getLocalStorage('dj_scrm_userInfo')
let accountList = util.getLocalStorage('dj_scrm_accountList')
dispatch('registerHttp')
if (!userInfo) {
if (loginToken && accountList) {
state.showWindow = true
......
......@@ -7,8 +7,9 @@
* @LastEditTime: 2021-06-20 12:49:11
*/
import bus from './eventBus'
import util from './util'
import * as tool from './tools'
const { debounce, throttle, ...tools } = tool
import * as constants from './constants'
import store from './store'
export { bus, tools, debounce, throttle, constants, store }
\ No newline at end of file
export { bus, tools, debounce, throttle, constants, store, util }
\ No newline at end of file
......@@ -83,6 +83,12 @@ const touchstart = e => {
const touchend = e => {
e.target.classList.remove('btn-on-leave')
}
const setSessionId = val => {
window.localStorage.setItem('dj_scrm_session_id', val)
}
const getSessionId = () => {
return window.localStorage.getItem('dj_scrm_session_id')
}
const setLocalStorage = (key, item) => {
window.localStorage.setItem(key, JSON.stringify(item))
// sessionStorage.setItem(key, JSON.stringify(item))
......@@ -166,6 +172,8 @@ const utils = {
getLocalStorage,
makePhoneCall,
isFullSucreen,
setSessionId,
getSessionId,
showLoading,
hideLoading,
refreshPage,
......
......@@ -59,12 +59,12 @@ export default {
this.hideLoading()
this.removeLocalStorage('dj_scrm_loginToken')
this.removeLocalStorage('dj_scrm_accountList')
if (code == '0') {
if (data) {
let { lastPath, redirect_uri } = this.getQuery()
this.setLocalStorage('dj_scrm_userInfo', data)
this.setLocalStorage('dj_scrm_session_id', data.sessionId)
this.setSessionId(data.sessionId)
store.dispatch('registerHttp', data.sessionId)
this.showLoading('登录成功', () => {
if (redirect_uri) window.location.replace(decodeURIComponent(`${redirect_uri}?sessionId=${data.sessionId}`))
else this.$router.replace({ name: lastPath || 'home' })
......
......@@ -70,7 +70,7 @@ export default {
list: [
{
name: '我要发券',
link: '/dj-scrm-wx-work-attachment-activity/#/coupon'
link: '/dj-scrm-wx-work-main/attachment-activity/#/coupon'
},
{
name: '秒杀活动',
......@@ -88,9 +88,9 @@ export default {
},
methods: {
jump (e) {
let sessionId = this.getLocalStorage('dj_scrm_session_id')
let sessionId = this.getSessionId()
let { link, params } = e
let url = `${window.$baseUrl}${link}?sessionId=${sessionId}`
let url = `${link}?sessionId=${sessionId}`
if (params)`${url}&${params}`
window.location.replace(url)
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!