求大佬,这是哪里的问题,应该怎么解决
vue+spring boot 实现微信小程序查询管理员下用户相关信息导出excel表格进行下载的功能
求大佬,这是哪里的问题,应该怎么解决
vue+spring boot 实现微信小程序查询管理员下用户相关信息导出excel表格进行下载的功能
微信小程序提供了自己的文件系统 API,使用 wx.getFileSystemManager()来代替fs模块
function dell() {
const fileSystemManager = wx.getFileSystemManager(); // 获取微信小程序文件系统管理器
const dirPath = wx.env.USER_DATA_PATH; // 微信小程序用户数据路径
// 读取目录下的文件
fileSystemManager.readdir({
dirPath: dirPath,
success(res) {
console.log('文件列表:', res.files);
let indexVal = res.files.length;
res.files.forEach((el) => {
let name = `${wx.env.USER_DATA_PATH}/${el}`.replace(/\/g/, "usr/");
// 删除文件
fileSystemManager.unlink({
filePath: name,
success() {
console.log('文件删除成功:', name);
indexVal++;
if (indexVal === 0) {
console.log('文件删除完成:', indexVal);
}
},
fail(e) {
console.log('文件删除失败:', e);
}
});
});
},
fail(e) {
console.log('读取目录失败:', e);
}
});
}
4 回答755 阅读✓ 已解决
2 回答1k 阅读✓ 已解决
6 回答1.1k 阅读
3 回答795 阅读✓ 已解决
5 回答541 阅读
1 回答892 阅读✓ 已解决
3 回答1.1k 阅读
首先截图中的部分就不是用户信息下载相关的函数哇,看明明和API是使用FS去操作文件删除的功能。但是浏览器端就没有FS相关的API吧。你要下载也是从后端获取文件流再把文件流保存下来,或者后端直接返回生成文件的静态地址过来。
但小程序下载文件的API和浏览器网页端又不一样,限制了下载能力。只能使用小程序提供的下载API和保存文件API去下载文件。而且OP你的问题描述 Vue + 小程序应该是 uni-app,对应使用的API是 uni.downloadFile() 和 uni.saveFile() 这两个API。