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.
102 lines
2.3 KiB
102 lines
2.3 KiB
// pages/studentList/studentList.js
|
|
Page({
|
|
data: {
|
|
number: ''
|
|
},
|
|
|
|
clickbtn() {
|
|
let that = this;
|
|
wx.chooseMessageFile({
|
|
count: 1,
|
|
type: 'file',
|
|
success: res => {
|
|
wx.showLoading({
|
|
title: '正在上传',
|
|
});
|
|
let filePath = res.tempFiles[0].path;
|
|
console.log("选择execl成功", filePath);
|
|
that.clearDatabase(filePath); // 传递filePath到clearDatabase
|
|
}
|
|
});
|
|
},
|
|
|
|
clearDatabase(filePath) {
|
|
let that = this;
|
|
const db = wx.cloud.database({
|
|
env: 'fzu-rollcall-system-7c9tbd0e8c2b'
|
|
});
|
|
const stu = db.collection('users');
|
|
stu.where({
|
|
_id: db.command.exists(true)
|
|
}).remove().then(res => {
|
|
console.log('删除成功', res);
|
|
that.setData({
|
|
number: ''
|
|
});
|
|
that.cloudFile(filePath); // 确保在数据库清空后上传文件
|
|
}).catch(err => {
|
|
console.log('删除失败', err);
|
|
wx.hideLoading();
|
|
});
|
|
},
|
|
|
|
cloudFile(path) {
|
|
let that = this;
|
|
wx.cloud.uploadFile({
|
|
cloudPath: "学生名单.xlsx",
|
|
filePath: path,
|
|
success: res => {
|
|
wx.hideLoading();
|
|
console.log("上传成功", res.fileID);
|
|
that.jiexi(res.fileID);
|
|
},
|
|
fail: err => {
|
|
console.log("上传失败", err);
|
|
wx.hideLoading();
|
|
}
|
|
});
|
|
},
|
|
|
|
jiexi(fileId) {
|
|
let that = this;
|
|
wx.cloud.callFunction({
|
|
name: "excel",
|
|
data: {
|
|
fileID: fileId
|
|
},
|
|
success: res => {
|
|
console.log("success", res);
|
|
},
|
|
fail: res => {
|
|
console.log("failed", res);
|
|
}
|
|
});
|
|
},
|
|
|
|
clickbtn2() {
|
|
const fileID = 'cloud://fzu-rollcall-system-7c9tbd0e8c2b.667a-fzu-rollcall-system-7c9tbd0e8c2b-1329892612/xueshemingdan.xlsx';
|
|
wx.cloud.downloadFile({
|
|
fileID: fileID,
|
|
success: res => {
|
|
wx.openDocument({
|
|
filePath: res.tempFilePath,
|
|
success: openRes => {
|
|
console.log('文件打开成功');
|
|
},
|
|
fail: openErr => {
|
|
console.error('文件打开失败', openErr);
|
|
}
|
|
});
|
|
},
|
|
fail: err => {
|
|
console.error('下载文件失败', err);
|
|
}
|
|
});
|
|
},
|
|
|
|
goBack: function() {
|
|
wx.navigateTo({
|
|
url: '/pages/teacherHomePage/teacherHomePage'
|
|
});
|
|
},
|
|
}); |