UNPKG

autobots-lib

Version:

汽车人基础库

45 lines (39 loc) 970 B
import na from './native'; import ToastMan from './lib/toast'; const post = function (url, body) { var requestUrl = url; return fetch(requestUrl, { method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify(body) }).then((res) => res.json()); } var http = { request(url, body) { var posturl = na.getPostUrl(url); if (!body || body == "") { body = {}; } return post(posturl, body) .then((data) => { if (data.status == undefined) { ToastMan.Show("错误的数据返回格式"); } if (data.status != 1) { if (data.info != '' && data.status == 0) { ToastMan.Show(data.info); } return false; } return (data.returnObject); }) .catch((error) => { ToastMan.Show(error.message); return (false); }) } } module.exports = http;