|
- import baseurl from '../environment.js'
- export const request = function(data) {
- return new Promise((resolve, reject) => {
- if(data.showLoading) {
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- }
- // 接口api拼接环境地址
- data.url = baseurl + data.url
- wx.request({
- ...data,
- success: function(res) {
- // 处理请求
- if(data.url === baseurl+'/aliyunOss/getSecurityToken') {
- resolve(res.data)
- } else {
- if(res.data.code == 0) { // 请求成功状态码
- resolve(res.data)
- } else {
- reject(res.data.msg)
- }
- }
- },
- fail: function (error) {
- reject(error)
- },
- complete: function () {
- if (data.showLoading) {
- wx.hideLoading()
- }
- }
- })
- }).catch(e => {
- wx.showToast({
- icon: "error",
- title: e || '系统错误',
- })
- })
- }
|