import config from "@/config" export default class Http { constructor() {} async get(params) { uni.showLoading({ title: '加载中...' }); return new Promise((success, error) => { uni.request({ url: config.CheckBaseUrl() + params.url, method: "GET", data: params.data, header: Object.assign({ "Content-Type": "application/json; charset=utf-8", }, params.headers), success: (res) => { this.interceptors(success, error, res.data) } }); }) } async post(params) { uni.showLoading({ title: '加载中...' }); return new Promise((success, error) => { uni.request({ url: config.CheckBaseUrl() + params.url, method: "POST", data: params.data, header: Object.assign({ "Content-Type": "application/json; charset=utf-8", }, params.headers), success: (res) => { this.interceptors(success, error, res.data) } }); }) } interceptors(s, e, data) { uni.hideLoading(); switch (data.status) { case 200: s(data.result) break; case 404: uni.showToast({ title: data.msg, duration: 2000 }); throw new Error(data.msg); break; default: break; } } }