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.
|
|
|
|
import { toast } from '../../utils/extendApi'
|
|
|
|
|
//导入ComponentWithStore方法
|
|
|
|
|
import { ComponentWithStore } from 'mobx-miniprogram-bindings'
|
|
|
|
|
import { userStore } from '../../stores/userstore'
|
|
|
|
|
import { getStorage } from '../../utils/storage';
|
|
|
|
|
|
|
|
|
|
ComponentWithStore({
|
|
|
|
|
storeBindings: {
|
|
|
|
|
store: userStore,
|
|
|
|
|
fields: ['id', 'identify'],//从Store中获取id和identify,存放在页面的data里
|
|
|
|
|
actions: []
|
|
|
|
|
},
|
|
|
|
|
methods:{
|
|
|
|
|
// 在你的页面的.js文件中
|
|
|
|
|
|
|
|
|
|
// 选择并上传文件
|
|
|
|
|
AddLessonInfo: function () {
|
|
|
|
|
const self = this;
|
|
|
|
|
wx.chooseMessageFile({
|
|
|
|
|
count: 1, // 最多可以选择的文件个数
|
|
|
|
|
type: 'file', // 指定是文件类型
|
|
|
|
|
extension: ['csv'], // 指定文件扩展名
|
|
|
|
|
success: function (res) {
|
|
|
|
|
const tempFilePath = res.tempFiles[0].path; // 获取选中文件的临时路径
|
|
|
|
|
const fileName = res.tempFiles[0].name; // 获取选中文件的名称(包含扩展名)
|
|
|
|
|
console.log(fileName)
|
|
|
|
|
// 上传文件
|
|
|
|
|
wx.uploadFile({
|
|
|
|
|
url: 'http://172.20.10.2:8600/student-api/student/uploadcsv', // 后端服务器的接收地址
|
|
|
|
|
filePath: tempFilePath, // 要上传的文件的路径
|
|
|
|
|
name: 'multipartFile', // 后端用于接收文件的参数名(根据后端接口要求调整)
|
|
|
|
|
formData: {
|
|
|
|
|
'lesson_name':fileName,
|
|
|
|
|
'teacher_id' :getStorage('id')
|
|
|
|
|
},
|
|
|
|
|
// header: {
|
|
|
|
|
header: {
|
|
|
|
|
// 'Content-Type': 'multipart/form-data'
|
|
|
|
|
},
|
|
|
|
|
// },
|
|
|
|
|
success: (uploadRes) =>{
|
|
|
|
|
console.log(uploadRes)
|
|
|
|
|
// 上传请求成功后的处理逻辑
|
|
|
|
|
// const {code,data} = uploadRes.data //解构?
|
|
|
|
|
if (uploadRes.statusCode === 200){
|
|
|
|
|
console.log('文件上传成功');
|
|
|
|
|
// 例如,可以提示用户上传成功,或者更新页面状态等
|
|
|
|
|
toast({
|
|
|
|
|
title: '上传成功:',
|
|
|
|
|
icon: 'success',
|
|
|
|
|
duration: 2000
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
console.log('文件上传失败',data);
|
|
|
|
|
toast({
|
|
|
|
|
title: '上传失败:',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
duration: 2000
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fail: (uploadRes)=> {
|
|
|
|
|
// 上传失败后的处理逻辑
|
|
|
|
|
console.log('文件上传失败', uploadRes);
|
|
|
|
|
// 例如,可以提示用户上传失败,或者重试上传等
|
|
|
|
|
toast({
|
|
|
|
|
title: '上传错误',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
duration: 2000
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
fail: function (err) {
|
|
|
|
|
// 选择文件失败的处理逻辑
|
|
|
|
|
console.log('文件选择失败', err);
|
|
|
|
|
toast({
|
|
|
|
|
title: '文件选择失败',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
duration: 2000
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|