dy_iaa_new_project/utils/httpReques.ts
2024-07-12 15:57:54 +08:00

42 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { basUrl } from './config'
//request.js 此demo为简易封装开发者可根据自己的业务场景进行修改
export const httpRequest = (url: string, method: any = 'GET', data: any = {}, header: any = {}) => {
const uid = tt.getStorageSync('uid');
const platform = tt.getSystemInfoSync().platform;
return new Promise((resolve, reject) => {
let newUrl = '';
if (url.includes('https') || url.includes('http')) {
newUrl = url;
} else {
newUrl = `${basUrl}${url}`;
}
tt.request({
url: newUrl,
method: method,
data: {
uid: uid || '',
platform: platform || '',
...data,
},
header: header,
success: (res: any) => {
console.log(res,"pppppppp")
if (res.data.status == 1) {
resolve(res.data);
} else {
tt.showToast({
title: res.data.msg || '请求失败',
icon: 'none'
});
resolve(res.data);
}
},
fail: (err) => {
reject(err)
},
});
})
}