1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import service from './newRequest.js'
- import store from '../store';
- import {
- saveUrl,
- interceptor
- } from '@/utils/loginUtils.js';
- // 请求完成后拦截
- service.interceptors.response(
- response => {
- try {
- let res = response.data;
- // 解析字符串为数字
- if (res.status !== 200) {
- console.log(res.status);
- if (res.status == 410000) {
- // 调用退出登录方法清空用户信息
- store.commit('user/logout');
- saveUrl();
- uni.navigateTo({
- url:"/pages/public/login"
- })
- } else {
- uni.showToast({
- title: res.msg,
- duration: 1500,
- mask: false,
- icon: 'none',
- })
- }
- return Promise.reject(res)
- } else {
- return res
- }
- } catch (e) {
- console.log(e);
- }
- },
- error => {
- uni.showToast({
- title: "当前用户量过多,请稍后重试",
- duration: 1500,
- mask: false,
- icon: 'none',
- })
- return Promise.reject(error)
- }
- )
- // 请求前拦截器
- service.interceptors.request(
- config => {
- let token = uni.getStorageSync('token') || '';
- // console.log(config);
- if (!config.header) {
- config.header = {
- "Authori-zation": 'Bearer ' + token,
- }
- } else {
- // 添加key请求头
- config.header["Authori-zation"] = 'Bearer ' + token;
- }
- return config
- },
- error => {
- // 错误处理
- console.log(error)
- return Promise.reject(error)
- }
- )
- let upFilse = service.upFilse;
- export {
- upFilse
- };
- export default service.open;
|