build(custom): 修正提交规范
This commit is contained in:
@@ -1,54 +1,49 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
import Taro from "@tarojs/taro";
|
||||
|
||||
export const BASE_URL = process.env.TARO_APP_API
|
||||
export const BASE_URL = process.env.TARO_APP_API;
|
||||
|
||||
interface Res<T> {
|
||||
code: number;
|
||||
data: T;
|
||||
msg: string;
|
||||
code: number;
|
||||
data: T;
|
||||
msg: string;
|
||||
}
|
||||
|
||||
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||
type Method = "GET" | "POST" | "PUT" | "DELETE";
|
||||
|
||||
const request = (
|
||||
url: string,
|
||||
data: object = {},
|
||||
method: Method = 'GET'
|
||||
url: string,
|
||||
data: object = {},
|
||||
method: Method = "GET"
|
||||
): Promise<Res<any>> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Taro.showLoading({
|
||||
// title: '加载中...',
|
||||
// mask: true
|
||||
// })
|
||||
Taro.request({
|
||||
url: BASE_URL + url,
|
||||
data: data,
|
||||
method: method,
|
||||
header: {
|
||||
'content-type': 'application/json',
|
||||
token: Taro.getStorageSync('token') || ''
|
||||
},
|
||||
success: ({data}) => {
|
||||
// Taro.hideLoading()
|
||||
if (data.code !== 200) {
|
||||
Taro.showToast({
|
||||
title: data.msg,
|
||||
icon: 'none'
|
||||
})
|
||||
reject(data)
|
||||
return
|
||||
}
|
||||
resolve(data)
|
||||
},
|
||||
fail: () => {
|
||||
Taro.showToast({
|
||||
title: '服务器异常',
|
||||
icon: 'none'
|
||||
})
|
||||
reject({code: 1, msg: '服务器异常'})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
Taro.request({
|
||||
url: BASE_URL + url,
|
||||
data: data,
|
||||
method: method,
|
||||
header: {
|
||||
"content-type": "application/json",
|
||||
token: Taro.getStorageSync("token") || "",
|
||||
},
|
||||
success: ({ data }) => {
|
||||
if (data.code !== 200) {
|
||||
Taro.showToast({
|
||||
title: data.msg,
|
||||
icon: "none",
|
||||
});
|
||||
reject(data);
|
||||
return;
|
||||
}
|
||||
resolve(data);
|
||||
},
|
||||
fail: () => {
|
||||
Taro.showToast({
|
||||
title: "服务器异常",
|
||||
icon: "none",
|
||||
});
|
||||
reject({ code: 1, msg: "服务器异常" });
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default request
|
||||
export default request;
|
||||
|
||||
Reference in New Issue
Block a user