UNPKG

xlb-main-login

Version:

``` yarn install ```

192 lines (185 loc) 6.19 kB
import axios from 'axios' import Message from 'ant-design-vue/es/message' import Modal from 'ant-design-vue/es/modal' import registerHint from './registerhint' import state from '../store/index' import { weihomeURL } from './config' const warning = Modal.warning axios.interceptors.request.use( (config) => { //不需要添加access_token的白名单 const arr = [ 'login', 'demo-user-role/oauth/register', 'demo-user-role/oauth/login', 'demo-user-role/oauth/phone/login', 'demo-user-role/oauth/code', 'demo-user-role/oauth/code/tel', 'demo-user-role/oauth/reset', 'demo-user-role/v2/front/source', ] let donotAdd = false arr.forEach((item) => { if (config.url.indexOf(item) > 0) { donotAdd = true return } }) const token = state.getters.token if (token && !donotAdd) { if (config.params && !config.params.access_token) { config.params.access_token = token } else if (!config.params) { const params = new Object() config.params = params config.params.access_token = token } } if (config.url.indexOf('shop/write/off/qr') > 0) { state.commit('wxSpinning', false) } else { state.commit('wxSpinning', true) } return config }, (error) => { state.commit('wxSpinning', false) return Promise.reject(error) } ) axios.interceptors.response.use( function (response) { //对响应数据做些事 state.commit('wxSpinning', false) return response }, function (error) { state.commit('wxSpinning', false) //请求错误时做些事 const url = window.location.href if (!localStorage.getItem('time')) { localStorage.setItem('time', 'time') if (error.response.status === 401) { if (error.response.data.code === 50003) { //权限到期 if (url.indexOf('homereport') > 0) { } else if (url.indexOf('login') > 0) { } else { warning({ title: '', content: '权限到期,请联系客服处理', width: 390, centered: true, maskClosable: true, closable: true, class: 'windows', }) } } else { //token setTimeout(function () { registerHint('invalid_token') }, 2000) } } else if (error.response.status === 400) { if (error.response.data.code === 50102) { if (url.indexOf('program') > 0) { warning({ title: '提示', content: '请先授权小程序', width: 390, centered: true, maskClosable: true, closable: true, class: 'windows', }) } else if (url.indexOf('wechatwx') > 0) { } else if (url.indexOf('wechatwxs') > 0) { } else if (url.indexOf('wxverificationd') > 0) { } else if (url.indexOf('wechatspreed') > 0) { } else if (url.indexOf('wechatredpacketspeed') > 0) { } else if (url.indexOf('weChatHolidaylistelse') > 0) { } else if (url.indexOf('wechath5spreed') > 0) { } else if (url.indexOf('wxverificationspeed') > 0) { } else { } } else if (error.response.data.code === 50005) { //参数错误 } else if (error.response.data.code === 60001) { //企业微信未接入 } else if (error.response.data.code === 60012) { } else if (error.response.data.code === 500 && error.response.data.msg == 'empty') { } else if (error.response.data.code === 50003) { if (url.indexOf('login') > 0) { } else { warning({ title: '提示', content: '权限到期,请联系客服处理', width: 390, centered: true, maskClosable: true, closable: true, class: 'windows', }) } } else if (error.response.data.code === 50135) { warning({ title: '提示', content: '请先进行店铺设置', width: 390, centered: true, maskClosable: true, closable: true, class: 'windows', }) } else if (error.response.data.code === 50159) { if (url.indexOf('wechatanalysisinfo') > 0) { } else if (url.indexOf('homereport') > 0) { } else if (url.indexOf('analysispandectwxwechat') > 0) { } else if (url.indexOf('analysispandectwxwechat') > 0) { } else { warning({ title: '提示', content: '请先进行店铺设置', width: 390, centered: true, maskClosable: true, closable: true, class: 'windows', }) } } else if (error.response.data.code === 60030) { if (url.indexOf('homereport') > 0) { } else if (url.indexOf('analysispandectwxwechat') > 0) { } else { warning({ title: '提示', content: '企业微信品牌未设置,请前往【基础功能-品牌设置】进行设置', width: 390, centered: true, maskClosable: true, closable: true, class: 'windows', onOk: () => onOk(), }) } } else { Message.warning({ content: error.response.data.msg, }) } } return Promise.reject(error) } } ) function onOk() { const newpeo = state.getters.newpeo state.state.left_token = 1 if (newpeo == 1) { window.location.href = weihomeURL + '#/wechatshopinfos' } else { window.location.href = weihomeURL + '#/wechatshopinfo' } } export default axios