|
|
@@ -0,0 +1,102 @@
|
|
|
+import {
|
|
|
+ request as miniRequest,
|
|
|
+ showToast,
|
|
|
+ uploadFile as miniUpload,
|
|
|
+} from '@tarojs/taro';
|
|
|
+import {NETWORK_URL} from 'utils/constants';
|
|
|
+
|
|
|
+function request({url, data, method, skipError}) {
|
|
|
+ const pr = new Promise(function (res) {
|
|
|
+ miniRequest({
|
|
|
+ url: `${NETWORK_URL}${url}`,
|
|
|
+ data,
|
|
|
+ method,
|
|
|
+ header: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ 'Cache-Control': 'no-cache',
|
|
|
+ },
|
|
|
+ success(data) {
|
|
|
+ const result = data.data;
|
|
|
+ if (result.msg === '500' && !skipError)
|
|
|
+ showToast({
|
|
|
+ title: result.errMsg,
|
|
|
+ duration: 2000,
|
|
|
+ mask: true,
|
|
|
+ icon: 'none',
|
|
|
+ });
|
|
|
+
|
|
|
+ res(result);
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ setTimeout(function () {
|
|
|
+ !skipError &&
|
|
|
+ showToast({
|
|
|
+ title: '请求失败,请稍后再试',
|
|
|
+ duration: 2000,
|
|
|
+ mask: true,
|
|
|
+ icon: 'none',
|
|
|
+ });
|
|
|
+ }, 10);
|
|
|
+
|
|
|
+ res({msg: '500', errmsg: '请求失败,请稍后再试'});
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return pr;
|
|
|
+}
|
|
|
+
|
|
|
+export function get(options) {
|
|
|
+ return request({...options, method: 'GET'});
|
|
|
+}
|
|
|
+
|
|
|
+export function post(options) {
|
|
|
+ return request({...options, method: 'POST'});
|
|
|
+}
|
|
|
+
|
|
|
+export function del(options) {
|
|
|
+ return request({...options, method: 'DELETE'});
|
|
|
+}
|
|
|
+
|
|
|
+export function put(options) {
|
|
|
+ return request({...options, method: 'PUT'});
|
|
|
+}
|
|
|
+
|
|
|
+export function uploadFile(url, skipError) {
|
|
|
+ const pr = new Promise(function (res) {
|
|
|
+ miniUpload({
|
|
|
+ url: 'https://www.tuyatrip.com/api/upload/uploadFile',
|
|
|
+ filePath: url,
|
|
|
+ name: 'file',
|
|
|
+ header: {
|
|
|
+ 'Cache-Control': 'no-cache',
|
|
|
+ },
|
|
|
+ success(data) {
|
|
|
+ const result = data.data;
|
|
|
+ if (result.msg === '500' && !skipError) {
|
|
|
+ showToast({
|
|
|
+ title: result.errMsg,
|
|
|
+ duration: 2000,
|
|
|
+ mask: true,
|
|
|
+ icon: 'none',
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ res(result);
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ !skipError &&
|
|
|
+ showToast({
|
|
|
+ title: '请求失败,请稍后再试',
|
|
|
+ duration: 2000,
|
|
|
+ mask: true,
|
|
|
+ icon: 'none',
|
|
|
+ });
|
|
|
+
|
|
|
+ res({msg: '500', errmsg: '请求失败,请稍后再试'});
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return pr;
|
|
|
+}
|