在項(xiàng)目開(kāi)發(fā)中碰到需要導(dǎo)入文件、下載文件的功能,內(nèi)容如下:
1、導(dǎo)入功能文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-743682.html
uni.chooseMessageFile({
count: 1,
type: 'file',
extension: ['.xlsx', '.xls'],
success: function(res) {
console.log("文件上傳", res);
uni.uploadFile({
url: config.baseUrl + '/core/xxxxx', //文件上傳的接口地址
filePath: res.tempFiles[0].path,
name: 'excel', //接口需要的參數(shù)名
header: {
'Authorization': uni.getStorageSync('lifeData').vuex_token
},
success(uploadRes) {
uni.showToast({
icon: 'none',
title: '上傳成功'
});
that.pageNum = 1
that.getProjectList()
},
fail(uploadErr) {
console.log('上傳失敗', uploadErr);
// 處理上傳失敗后的邏輯
}
});
},
fail(err) {
console.log('選擇文件失敗', err);
// 處理選擇文件失敗后的邏輯
}
});
2、下載文件文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-743682.html
uni.request({
url: config.baseUrl + '/core/XXXX',
method: 'POST',
data: params,
header: {
"content-type": "application/json",
"Authorization": uni.getStorageSync('lifeData').vuex_token
},
responseType: "arraybuffer",
success: res => {
const fs = wx.getFileSystemManager()
let data = res.data
fs.writeFile({
filePath: wx.env.USER_DATA_PATH + "/文件名稱.xlsx",
data: data,
encoding: "ascii",
success(res) {
uni.hideLoading();
uni.openDocument({
showMenu: true,
fileType: 'xlsx',
filePath: wx.env.USER_DATA_PATH + "/文件名稱.xlsx",
success: function(res) {}
});
},
})
}
})
到了這里,關(guān)于uniapp微信小程序下載、導(dǎo)入excel文件的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!