| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import service from './newRequest.js'
- import store from '../store';
- import md5 from './md5.js'
- import sha1 from './sha1.js'
- import {
- saveUrl,
- interceptor
- } from '@/utils/loginUtils.js';
- // 请求完成后拦截
- service.interceptors.response(
- response => {
- try {
- let res = response.data;
- // 解析字符串为数字
- if (res.status !== 200) {
- if (res.status == 410000) {
- // 存储当前地址
- saveUrl()
- // 调用退出登录方法清空用户信息
- store.commit('user/logout');
- // 判断是否开启强制登录
- // 跳转页面
- interceptor()
- uni.showModal({
- title: "您未登录!是否马上登录?",
- success: (e) => {
- if (e.confirm) {
- // 保存当前页面地址
-
- }
- }
- })
- } else {
- if(res.msg!='系统出现异常'){
- uni.showToast({
- title: res.msg,
- duration: 1500,
- mask: false,
- icon: 'none',
- })
- }
- }
- console.log(res);
- //return Promise.reject(new Error(res.msg || 'Error'))
- } 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') || '';
- let timestamp = new Date().getTime();
- let appSecret = 'c86fec63e23217b38f817b3e94dfdc33';
- let Appid = 'wx7f2fc8ec64602d06';
- let Sign = md5(sha1(Appid + timestamp + appSecret + timestamp + Appid + appSecret))
-
- console.log(Sign,Sign.length,'md5+++++++++++')
- console.log(timestamp,'timestamp')
- if (!config.header) {
- config.header = {
- "Authori-zation": 'Bearer ' + token,
- "App-id": Appid,
- "Sign": Sign,
- "Sign-time": timestamp
- }
- } else {
- // 添加key请求头
- config.header["Authori-zation"] = 'Bearer ' + token;
- config.header["App-id"] = Appid;
- config.header['Sign-time'] = timestamp;
- config.header['Sign'] = Sign;
- }
- return config
- },
- error => {
- // 错误处理
- console.log(error)
- return Promise.reject(error)
- }
- )
- let upFilse = service.upFilse;
- export {
- upFilse
- };
- export default service.open;
|