This commit is contained in:
2023-10-08 22:53:13 +08:00
parent b883b02fb9
commit e36d60d015
83 changed files with 18303 additions and 9590 deletions

View File

@@ -1,9 +1,6 @@
import Taro from "@tarojs/taro";
import Taro from '@tarojs/taro'
export const BASE_URL =
process.env.NODE_ENV === "development"
? "http://192.168.2.3:9000/app"
: "https://www.wanzhuanyongcheng.cn/app";
export const BASE_URL = process.env.TARO_APP_API
interface Res<T> {
code: number;
@@ -11,47 +8,47 @@ interface Res<T> {
msg: string;
}
type Method = "GET" | "POST" | "PUT" | "DELETE";
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
const request = (
url: string,
data: object = {},
method: Method = "GET"
method: Method = 'GET'
): Promise<Res<any>> => {
return new Promise((resolve, reject) => {
Taro.showLoading({
title: "加载中...",
mask: true,
});
// Taro.showLoading({
// title: '加载中...',
// mask: true
// })
Taro.request({
url: BASE_URL + url,
data: data,
method: method,
header: {
"content-type": "application/json",
token: Taro.getStorageSync("token"),
'content-type': 'application/json',
token: Taro.getStorageSync('token') || ''
},
success: ({ data }) => {
Taro.hideLoading();
success: ({data}) => {
// Taro.hideLoading()
if (data.code !== 200) {
Taro.showToast({
title: data.msg,
icon: "none",
});
reject(data);
return;
icon: 'none'
})
reject(data)
return
}
resolve(data);
resolve(data)
},
fail: () => {
Taro.showToast({
title: "服务器异常",
icon: "none",
});
reject({ code: 1, msg: "服务器异常" });
},
});
});
};
title: '服务器异常',
icon: 'none'
})
reject({code: 1, msg: '服务器异常'})
}
})
})
}
export default request;
export default request