| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- const baseRequest = async (url, method, data = {}, loading = true) => {
- let header = {}
- return new Promise((reslove, reject) => {
- loading && uni.showLoading({
- title: '加载中'
- })
- uni.request({
- url: 'https://xnh.xazhima.com/prod-api/wap/business/weixin' + url,
- method: method || 'GET',
- header: header,
- timeout: 10000,
- data: data || {},
- success: (successData) => {
- const res = successData.data
- if (successData.statusCode == 200) {
- if (res.code === 200) {
- reslove(res)
- } else {
- uni.showToast({
- title: '未知错误'
- })
- }
- } else {
- uni.showToast({
- title: '网络连接失败,请稍后重试'
- })
- reject(res)
- }
- },
- fail: (msg) => {
- uni.showToast({
- title: '网络连接失败,请稍后重试'
- })
- reject(msg)
- },
- complete: () => {
- uni.hideLoading()
- },
- })
- })
- }
- const request = {
- get: (api, data, loading) => baseRequest(api, 'GET', data, loading),
- getPath: (api, data, keys, loading) => {
- let newRequestPath = api;
- Object.keys(keys).forEach(function (key) {
- newRequestPath = newRequestPath.replace(
- "{" + key + "}",
- keys[key]
- );
- });
- return baseRequest(newRequestPath, 'GET', data, loading)
- },
- post: (api, data, loading) => baseRequest(api, 'POST', data, loading),
- }
- export default request
|