update:上传素材

This commit is contained in:
ltx 2026-04-24 01:53:36 +08:00
parent f49d8be67a
commit b0c8f32d3a
2 changed files with 89 additions and 26 deletions

View File

@ -1,6 +1,7 @@
const { API } = require('../../utils/constants');
const { request } = require('../../utils/http');
const { formatDateTime, eventStatusText, eventStatusForPill, eventFormatText } = require('../../utils/format');
const auth = require('../../utils/auth');
/** 统一后台轮播字段(camelCase / PascalCase、枚举数字)供 wxml 绑定 */
function normalizeBannerItem(raw) {
@ -234,36 +235,97 @@ Page({
openUploadPicker({ kind, registrationId }) {
const title = kind === 'voucher' ? '上传付款凭证' : '上传素材';
wx.showActionSheet({
itemList: ['从相册选择', '拍照'],
success: (r) => {
if (!r || typeof r.tapIndex !== 'number') return;
const sourceType = r.tapIndex === 1 ? ['camera'] : ['album'];
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType,
success: (res) => {
const tempFilePath =
res && res.tempFiles && res.tempFiles[0] ? res.tempFiles[0].tempFilePath : '';
if (!tempFilePath) return;
wx.showModal({
title,
content: '确认上传该图片?',
cancelText: '取消',
confirmText: '确定',
success: (mr) => {
if (!mr || !mr.confirm) return;
// TODO: 接入后端上传接口(素材/付款凭证)
// kind: material | voucher
// registrationId: 报名记录 id
// tempFilePath: 本地图片路径
wx.showToast({ title: '已选择', icon: 'success' });
if (kind === 'material') {
wx.showActionSheet({
itemList: ['从相册选择图片/视频', '拍照/录视频', '选择音乐文件'],
success: (r) => {
if (!r || typeof r.tapIndex !== 'number') return;
if (r.tapIndex === 2) {
wx.chooseMessageFile({
count: 1,
type: 'file',
extension: ['mp3', 'wav', 'aac', 'flac', 'm4a', 'ogg'],
success: (res) => {
const file = res && res.tempFiles && res.tempFiles[0];
const tempFilePath = file ? file.path : '';
if (!tempFilePath) return;
this._confirmAndUploadMaterial(title, tempFilePath, registrationId);
}
});
} else {
const sourceType = r.tapIndex === 1 ? ['camera'] : ['album'];
wx.chooseMedia({
count: 1,
mediaType: ['image', 'video'],
sourceType,
success: (res) => {
const tempFilePath =
res && res.tempFiles && res.tempFiles[0] ? res.tempFiles[0].tempFilePath : '';
if (!tempFilePath) return;
this._confirmAndUploadMaterial(title, tempFilePath, registrationId);
}
});
}
});
}
});
} else {
wx.showActionSheet({
itemList: ['从相册选择', '拍照'],
success: (r) => {
if (!r || typeof r.tapIndex !== 'number') return;
const sourceType = r.tapIndex === 1 ? ['camera'] : ['album'];
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType,
success: (res) => {
const tempFilePath =
res && res.tempFiles && res.tempFiles[0] ? res.tempFiles[0].tempFilePath : '';
if (!tempFilePath) return;
wx.showModal({
title,
content: '确认上传该图片?',
cancelText: '取消',
confirmText: '确定',
success: (mr) => {
if (!mr || !mr.confirm) return;
// TODO: 接入付款凭证上传接口
wx.showToast({ title: '已选择', icon: 'success' });
}
});
}
});
}
});
}
},
_confirmAndUploadMaterial(title, tempFilePath, registrationId) {
wx.showModal({
title,
content: '确认上传该文件?',
cancelText: '取消',
confirmText: '确定',
success: (mr) => {
console.log('用户选择:', mr);
if (!mr || !mr.confirm) return;
wx.showLoading({ title: '上传中...', mask: true });
auth.uploadFile(tempFilePath)
.then((url) => {
return request({
path: API.uploadMaterial,
method: 'POST',
needAuth: true,
data: { registrationId, materialUrl: url }
});
})
.then(() => {
wx.showToast({ title: '上传成功', icon: 'success' });
})
.catch((err) => {
wx.showToast({ title: (err && err.message) || '上传失败', icon: 'none' });
});
}
});
},

View File

@ -32,6 +32,7 @@ const API = {
myTeams: '/api/my/teams',
myCertificates: '/api/my/certificates',
fileUpload: '/api/file/upload',
uploadMaterial: '/api/eventclient/upload-material',
ocrIdCard: '/api/ocr/recognize/idcard',
ocrPassport: '/api/ocr/recognize/passport'
};