|
@@ -1,17 +1,20 @@
|
|
|
-import {BASE_URL} from './request';
|
|
|
+import { BASE_URL } from './request';
|
|
|
+
|
|
|
/**
|
|
|
- * 上传图片
|
|
|
- * @param {string} filePath 本地文件路径
|
|
|
- * @param {string} url 上传接口路径(默认 /api/upload/image)
|
|
|
- * @param {string} name 后端接收文件字段名(默认 file)
|
|
|
+ * 上传报名证明图片
|
|
|
+ * @param {Object} params 参数对象
|
|
|
+ * @param {string} params.filePath 本地文件路径
|
|
|
+ * @param {number} params.marathonId 比赛ID
|
|
|
+ * @param {string} params.competitionNo 参赛号
|
|
|
+ * @param {string} [url='/api/upload/image'] 上传接口路径
|
|
|
+ * @param {string} [name='file'] 后端接收文件字段名
|
|
|
*/
|
|
|
-export function uploadImage(filePath, url = '/api/upload/image', name = 'file') {
|
|
|
+export function uploadImage(
|
|
|
+ { filePath, marathonId = '', competitionNo = '' },
|
|
|
+ url = '/api/upload/image',
|
|
|
+ name = 'file'
|
|
|
+) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- // wx.showLoading({
|
|
|
- // title: '上传中...',
|
|
|
- // mask: true
|
|
|
- // });
|
|
|
-
|
|
|
wx.uploadFile({
|
|
|
url: BASE_URL + url,
|
|
|
filePath,
|
|
@@ -19,11 +22,14 @@ export function uploadImage(filePath, url = '/api/upload/image', name = 'file')
|
|
|
header: {
|
|
|
'Authorization': wx.getStorageSync('token') || ''
|
|
|
},
|
|
|
+ formData: {
|
|
|
+ marathon_id: marathonId,
|
|
|
+ competition_no: competitionNo,
|
|
|
+ file:filePath
|
|
|
+ },
|
|
|
success(res) {
|
|
|
- // wx.hideLoading();
|
|
|
try {
|
|
|
const data = JSON.parse(res.data);
|
|
|
- console.log(data)
|
|
|
if (data.code === 200 && data.ret) {
|
|
|
wx.showToast({
|
|
|
title: '上传成功',
|
|
@@ -42,7 +48,6 @@ export function uploadImage(filePath, url = '/api/upload/image', name = 'file')
|
|
|
}
|
|
|
},
|
|
|
fail(err) {
|
|
|
- // wx.hideLoading();
|
|
|
wx.showToast({
|
|
|
title: '网络异常,请重试',
|
|
|
icon: 'none'
|