import useNetWork from "./useNetWork.js"; import { useStore } from 'vuex'; function fetch(method) { return function(url, data, otherParams = {}) { // if (method === 'POST' || method === 'PUT') { // data = { // param: data, // }; // } const sessionId = uni.getStorageSync('sessionId'); //定时器 return new Promise((resolve, reject) => { uni.request({ url, method, data, header: { AccessToken: sessionId }, success(data) { if (data.statusCode === 200) { if (data.data.statusCode === 200) { resolve(data.data.content); } else { uni.showToast({ title: '系统异常,请稍后再试!', icon: 'none', duration: 2000, }) reject(data); } } else { reject(data); } }, fail(err) { reject(err); }, ...otherParams, }); }); }; } export default { get: fetch('GET'), post: fetch('POST'), put: fetch('PUT'), delete: fetch('DELETE'), connect: fetch('CONNECT'), head: fetch('HEAD'), options: fetch('OPTIONS'), trace: fetch('TRACE'), }