This commit is contained in:
2023-08-18 17:22:11 +08:00
parent 1263c372cb
commit 61f840059b
36 changed files with 2371 additions and 1109 deletions

View File

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