64 lines
1.2 KiB
JavaScript
64 lines
1.2 KiB
JavaScript
import {
|
|
baseURL
|
|
} from '../../config/api'
|
|
import {
|
|
getToken,
|
|
isLogin
|
|
} from '../permission/login'
|
|
export function request({
|
|
path,
|
|
params,
|
|
method
|
|
}) {
|
|
return new Promise((resolve, reject) => {
|
|
wx.request({
|
|
url: baseURL + path, //仅为示例,并非真实的接口地址
|
|
data: params,
|
|
header: {
|
|
'content-type': 'application/json', // 默认值
|
|
'X-API-TOKEN': getToken()
|
|
},
|
|
method: method,
|
|
success(res) {
|
|
console.log(res.data)
|
|
resolve(res.data);
|
|
},
|
|
fail(res) {
|
|
console.log(res);
|
|
reject(res)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
export function uploadFile({
|
|
path,
|
|
url,
|
|
data
|
|
}) {
|
|
return new Promise((resolve, reject) => {
|
|
let token = getToken()
|
|
if (token == '') {
|
|
isLogin()
|
|
}
|
|
console.log(url);
|
|
wx.uploadFile({
|
|
url: baseURL + path, //接口地址
|
|
filePath: url,
|
|
name: 'file',
|
|
header: {
|
|
"X-API-TOKEN": getToken()
|
|
},
|
|
name: 'upfile',
|
|
formData: data,
|
|
success: function (res) {
|
|
console.log(res)
|
|
resolve(res.data)
|
|
},
|
|
fail: function (res) {
|
|
console.log(res);
|
|
reject(res.data)
|
|
}
|
|
})
|
|
})
|
|
} |