12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- module.exports = (vm) => {
-
- uni.$u.http.setConfig((config) => {
-
- config.baseURL = "https://cbec.hdlkeji.com";
- return config;
- });
-
- uni.$u.http.interceptors.request.use(
- (config) => {
-
-
- config.data = config.data || {};
-
-
-
- const token = localStorage.getItem("token");
- config.header.Authorization = "Bearer" + " " + token;
-
- return config;
- },
- (config) => {
-
- return Promise.reject(config);
- }
- );
-
- uni.$u.http.interceptors.response.use(
- (res) => {
-
- const data = res.data;
-
- const custom = res.config?.custom;
- if (data.code !== 10000) {
-
- if (custom.toast !== false) {
- uni.$u.toast(data.message);
- }
-
- if (custom?.catch) {
- return Promise.reject(data);
- } else {
-
- return new Promise(() => {});
- }
- }
- return data.data === undefined ? {} : data.data;
- },
- (res) => {
-
- return Promise.reject(res.msg);
- }
- );
- };
|