12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- module.exports = (vm) => {
-
- uni.$u.http.setConfig((config) => {
-
-
- config.baseURL = "https://cbec-test.hdlkeji.com";
- return config;
- });
-
- uni.$u.http.interceptors.request.use(
- (config) => {
-
-
- config.data = config.data || {};
-
-
-
- const token = uni.getStorageSync("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 && data.code !== 10011) {
- if (data.code == 10001) {
- uni.showModal({
- title: "提示",
- content: "未登录,请先登录",
- success: function (res) {
- if (res.confirm) {
- console.log("用户点击确定");
- uni.reLaunch({
- url: "/pages/login/login",
- });
- } else if (res.cancel) {
- console.log("用户点击取消");
- }
- },
- });
- }
-
- else 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);
- }
- );
- };
|