32 lines
957 B
TypeScript
32 lines
957 B
TypeScript
|
||
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) => {
|
||
resolve(res.data)
|
||
},
|
||
fail: (err) => {
|
||
reject(err)
|
||
},
|
||
});
|
||
})
|
||
} |