import { baseurl } from "../config/idnex"; function httpError(err) { console.error(err); wx.hideLoading(); wx.showToast({ title: '请稍后再试!', icon: 'none' }) } export function httpCloud(params) { !params.noLoading && wx.showLoading(); const par = params || {}; wx.cloud.callFunction({ // 云函数名称 name: par.name, // 传给云函数的参数 data: { ...(par.data || {}), type: par.type }, success: function (res) { wx.hideLoading(); if (!/ok/g.test(res.errMsg)) return httpError(res); if (res.result.code != 0) return wx.showToast({ title: '请稍后再试!', icon: 'none' }) par.call && par.call(res.result.data); }, fail: httpError }) } export function httpOrther(params) { !params.noLoading && wx.showLoading(); const par = params || {}; wx.request({ url: baseurl + par.url, data: { ...(par.data || {}), }, success(res) { if (res.statusCode !== 200 || res.data.code != 0 )return wx.showToast({ title: '请稍后再试!', icon: 'none' }) if (!/ok/g.test(res.errMsg)) return httpError(res); par.call && par.call(res.data.data); }, complete() { wx.hideLoading(); } }) }