|
|
@@ -106,51 +106,55 @@ Component({
|
|
|
file,
|
|
|
callback
|
|
|
} = event.detail;
|
|
|
- /* 校验文件大小 */
|
|
|
- if (file.size > 10485760) {
|
|
|
- wx.showToast({
|
|
|
- title: '文件体积大于10Mb',
|
|
|
- icon: "none",
|
|
|
- duration: 3000
|
|
|
- })
|
|
|
- return callback(false)
|
|
|
- }
|
|
|
- /* 校验文件格式 */
|
|
|
- const suffix = ['jpg', 'jpeg', 'png', 'gif', 'pdf'],
|
|
|
- index = file.url.lastIndexOf("."),
|
|
|
- ext = file.url.substr(index + 1);
|
|
|
- if (!suffix.some((value) => value == ext)) {
|
|
|
- wx.showToast({
|
|
|
- title: '错误文件格式',
|
|
|
- icon: "none",
|
|
|
- duration: 3000
|
|
|
- })
|
|
|
- return callback(false)
|
|
|
+ for (let i = 0; i < file.length; i++) {
|
|
|
+ /* 校验文件大小 */
|
|
|
+ if (file[i].size > 10485760) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '文件体积大于10Mb',
|
|
|
+ icon: "none",
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ return callback(false)
|
|
|
+ }
|
|
|
+ /* 校验文件格式 */
|
|
|
+ const suffix = ['jpg', 'jpeg', 'png', 'gif', 'pdf'],
|
|
|
+ index = file[i].url.lastIndexOf("."),
|
|
|
+ ext = file[i].url.substr(index + 1);
|
|
|
+ if (!suffix.some((value) => value == ext)) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '错误文件格式',
|
|
|
+ icon: "none",
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ return callback(false)
|
|
|
+ }
|
|
|
+ callback(true)
|
|
|
}
|
|
|
- callback(true)
|
|
|
},
|
|
|
/* 上传图片 */
|
|
|
afterRead(event) {
|
|
|
- // 初始化数据
|
|
|
- let that = this,
|
|
|
- data = this.requestType(event.detail.file);
|
|
|
- //发送请求
|
|
|
- wx.getFileSystemManager().readFile({
|
|
|
- filePath: event.detail.file.url,
|
|
|
- success: result => {
|
|
|
- //返回临时文件路径
|
|
|
- const fileData = result.data
|
|
|
- _Http.basic(data).then(res => {
|
|
|
- console.log(res)
|
|
|
- if(res.msg!="成功")return wx.showToast({
|
|
|
- title: res.data,
|
|
|
- icon:"none"
|
|
|
- })
|
|
|
- that.uploadFile(res, fileData)
|
|
|
- }).catch(err => {})
|
|
|
- },
|
|
|
- fail: console.error
|
|
|
- })
|
|
|
+ for (let i = 0; i < event.detail.file.length; i++) {
|
|
|
+ // 初始化数据
|
|
|
+ let that = this,
|
|
|
+ data = this.requestType(event.detail.file[i]);
|
|
|
+ //发送请求
|
|
|
+ wx.getFileSystemManager().readFile({
|
|
|
+ filePath: event.detail.file[i].url,
|
|
|
+ success: result => {
|
|
|
+ //返回临时文件路径
|
|
|
+ const fileData = result.data
|
|
|
+ _Http.basic(data).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ if (res.msg != "成功") return wx.showToast({
|
|
|
+ title: res.data,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ that.uploadFile(res, fileData)
|
|
|
+ }).catch(err => {})
|
|
|
+ },
|
|
|
+ fail: console.error
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
/* 上传成功反馈 */
|
|
|
uploadFile(res, data) {
|