0.1.22 • Published 5 months ago

@ecoding/helper.request v0.1.22

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

import axios from 'axios'; import { getCookie } from '@ecoding/helper.cookie'; import { Loading, Toast, http } from '@ecoding/components.antd'; import R from '@ecoding/helper.request'; import { getAppCode } from "@sciecomm/portal.global"; import { localLocale } from '@/locales'; export const ignoreTokenInterFace: string[] = [];

const originPrefix = { "localhost:8081": "http://192.168.2.29:8302", // 本地纯前端环境 'local': 'http://api.sciecomm.cn', //本地环境bff 'test': 'http://192.168.2.139:8302', //测试环境 'prod': 'http://api.sciecomm.cn', //线上环境 };

const request = new R(axios); request.setFinallyHook(() => { Loading.hide(); }); request.setResTranslateHook((out, res) => { if (res.code == -10001) { // 登录失效 setTimeout(() => { // window.location.href = /user/login?redirect=${encodeURIComponent(window.location.href)}; }, 1500); } return { success: res.successed, code: res.code, msg: res.message, message: res.message, data: res.model, }; }); request.setReqHook(async (options) => { const url = options.url; const host = location.host; let domain; if (/^\/api?\//.test(url)) { domain = originPrefixhost || originPrefixwindow.PRELOAD_STATE?.ctxEnv || process.env.NODE_ENV; } else { domain = ""; } if (!ignoreTokenInterFace.includes(url)) { const token = getCookie('accessToken'); if (token) { options.headers = Object.assign(options.headers || {}, { accessToken: token, appCode: getAppCode(url) }); } else { // Toast.error({ // title: '登录信息失效,请重新登录' // }); // setTimeout(() => { // // location.href = "/user/login"; // }, 1500); } } options.headers = Object.assign(options.headers || {}, { language: localLocale }); options.url = ${domain}${url}; // options.params = Object.assign(options.params || {}, { locale: localLocale }); return Promise.resolve(options); }); request.setErrorUiHook((err) => { Toast.error({ mask: true, duration: 20000, title: String(err.message || err.msg) }); }); http.setOutRequest(request); export const r = request;

0.1.22

5 months ago

0.1.15

10 months ago

0.1.20

8 months ago

0.1.21

6 months ago

0.1.16

10 months ago

0.1.17

10 months ago

0.1.18

9 months ago

0.1.19

8 months ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

12 months ago

0.1.13

11 months ago

0.1.14

11 months ago

0.1.8

1 year ago

0.1.9

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.12

1 year ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago