| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 | let apiUrl = 'https://test.api.zanxiangnet.com/miniapp'let isopen = false  // 控制loadingconst openLoading = () => {    if (!isopen) {        isopen = true        uni.showLoading({            title: '加载中'        });    }}const hiddenLoading = () => {    isopen = false    uni.hideLoading()}/** *  */// interface Props {//     url: string,//     data?: any,//     config?: {//         header?: any,//         method?: "OPTIONS" | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT",//         responseType?: "text" | "arraybuffer"//     },//     backspace?: boolean, // 是否返回上一页 默认否//     isLoading?: boolean,  // 是否展示loading//     isToast?: boolean  // 是否提示// }export function request(props) {	let {		url,		data,		config,		method,		backspace = false,		isLoading = true,		isToast = true	} = props	let _loading = false	let reqTimer = null	if (isLoading) {		reqTimer = setTimeout(() => {			openLoading()			_loading = true		}, 500)	}	return new Promise((resolve, reject) => {		uni.request({			url: `${apiUrl}${url}`,			data,			method: method || 'GET',			success: (res) => {				console.log("请求返回数据---》", res)				reqTimer && clearTimeout(reqTimer)				if (_loading) {					hiddenLoading()				}				if (res.data.code === 500) {					uni.showToast({					    title: res.data.msg || `${apiUrl}${url}请求错误`,						icon: 'none',					    duration: 2000					})					return				}				resolve(res.data)			},			fail: (err) => {				reqTimer && clearTimeout(reqTimer)				if (_loading) {					hiddenLoading()				}				reject(`${url}接口调用失败${err}`)			}		})	})}
 |