// const baseURL = 'https://console.sxtvs.com.cn' const baseURL = 'https://baoliao.sxtvs.net' import { config } from '../utils/config.js' export const myRequest = options => { uni.showLoading({ title: '加载中...' }) return new Promise((resolve, reject) => { uni.request({ url: `${baseURL}${options.url}`, //接口地址:前缀+方法中传入的地址 method: options.method || 'GET', //请求方法:传入的方法或者默认是“GET” data: options.data || {}, //传递参数:传入的参数或者默认传递空集合 header: { 'tenantId': config.tenantId }, success: (res) => { //返回的数据(不固定,看后端接口,这里是做了一个判断,如果不为true,用uni.showToast方法提示获取数据失败) // if (res.data.success != true) { // return uni.showToast({ // title: '获取数据失败', // icon: 'none' // }) // } // 如果不满足上述判断就输出数据 uni.hideLoading() resolve(res) }, // 这里的接口请求,如果出现问题就输出接口请求失败 fail: (err) => { uni.hideLoading() console.log(err) reject(err) } }) }) } //上传文件 export const uploadFile = options => { uni.showLoading({ title: '加载中...' }) return new Promise((resolve, reject) => { console.log(options); uni.uploadFile({ url: `${baseURL}${options.url}`, name: 'file', fileType: options.fileType, filePath: options.filePath, // 文件 formData: options.formData, // 除文件外其他所有数据,传对象,会默认转换为 FormData header: { 'tenantId': config.tenantId }, success: res => { uni.hideLoading() resolve(JSON.parse(res.data)) }, // 这里的接口请求,如果出现问题就输出接口请求失败 fail: (err) => { uni.hideLoading() console.log(err) reject(err) } }) }) }