You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.9 KiB
76 lines
1.9 KiB
2 months ago
|
Page({
|
||
|
data: {
|
||
|
fileID: null // 初始化为 null
|
||
|
},
|
||
|
|
||
|
// 选择文件
|
||
|
chooseFile: function() {
|
||
|
wx.chooseMessageFile({
|
||
|
count: 1,
|
||
|
type: 'file',
|
||
|
success: (res) => {
|
||
|
console.log('Selected file:', res.tempFiles[0]);
|
||
|
const tempFilePath = res.tempFiles[0].path; // 获取临时文件路径
|
||
|
|
||
|
// 上传文件到云存储
|
||
|
wx.cloud.uploadFile({
|
||
|
cloudPath: `files/${res.tempFiles[0].name}`, // 云存储路径
|
||
|
filePath: tempFilePath, // 临时文件路径
|
||
|
success: (uploadRes) => {
|
||
|
console.log('File uploaded successfully:', uploadRes);
|
||
|
const fileID = uploadRes.fileID; // 获取上传后的文件ID
|
||
|
console.log('fileID:', fileID); // 确认 fileID 的值
|
||
|
this.setData({
|
||
|
fileID: fileID
|
||
|
});
|
||
|
},
|
||
|
fail: (err) => {
|
||
|
console.error('Failed to upload file:', err);
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
fail: (err) => {
|
||
|
console.error('Failed to choose file:', err);
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
|
||
|
// 导入名单
|
||
|
importStudents: function() {
|
||
|
const fileID = this.data.fileID;
|
||
|
|
||
|
if (!fileID) {
|
||
|
wx.showToast({
|
||
|
title: '请选择文件',
|
||
|
icon: 'none'
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
wx.cloud.callFunction({
|
||
|
name: 'importstudents',
|
||
|
data: {
|
||
|
fileID: fileID
|
||
|
},
|
||
|
success: (res) => {
|
||
|
console.log('Import students success:', res.result);
|
||
|
wx.showToast({
|
||
|
title: '名单导入成功',
|
||
|
icon: 'success'
|
||
|
});
|
||
|
|
||
|
// 跳转到点名页面
|
||
|
wx.navigateTo({
|
||
|
url: '/pages/rollcall/rollcall'
|
||
|
});
|
||
|
},
|
||
|
fail: (err) => {
|
||
|
console.error('Import students failed:', err);
|
||
|
wx.showToast({
|
||
|
title: '名单导入失败',
|
||
|
icon: 'none'
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|