import { useUserInfoStore } from '@/stores/userInfo.js'; const userInfoStore = useUserInfoStore(); export default function request(config = {}) { let { url, data = {}, method = "GET", header = {}, loading = false, loadingText = "请求中..." } = config // 拼接url TODO 这里要修改,改成不同环境取不同的url url = process.env.BASE_API_URL + url; // 添加token header['Authorization'] = userInfoStore.token; // 是否显示loading if (loading) { uni.showLoading({ title: loadingText, mask: true }); } return new Promise((resolve, reject) => { uni.request({ url, data, method, header, withCredentials: true, success: res => { if (res.data.code === '0') { resolve(res.data.data) } else if (res.data.code === '999') { uni.showModal({ title: "错误提示", content: res.data.msg, showCancel: false }) reject(res.data) } else { uni.showToast({ title: res.data.msg, icon: "none" }) reject(res.data) } }, fail: err => { reject(err) }, complete: () => { if (loading) { uni.hideLoading(); } } }) }) }