diff --git a/1.0 pages index.js b/1.0 pages index.js new file mode 100644 index 0000000..0e07647 --- /dev/null +++ b/1.0 pages index.js @@ -0,0 +1,76 @@ +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' + }); + } + }); + } +}); \ No newline at end of file