import {getEventParam} from "../../../../utils/utils"; import Upload from "../../../../model/upload"; import {uploadResTypes} from "../../../../model/enum"; Component({ properties: { uploadPath: String, }, data: { dict: { "image": uploadResTypes.IMAGE, "video": uploadResTypes.VIDEO, }, fileList: [], maxCount: 9, accept: 'media', isPC: false }, attached() { let app = getApp(); let isPC = app.globalData.isPC; this.setData({isPC}) }, methods: { async afterRead(e) { const file = getEventParam(e, "file") wx.showLoading({ title: '正在上传...', mask: true }); await Upload.uploadRes(this.data.uploadPath, file); wx.hideLoading(); if ("image" == file.type) { this.setData({ accept: 'image', maxCount: 9 }); } else { this.setData({ accept: 'video', maxCount: 1 }); } const {fileList = []} = this.data; fileList.push({...file}); this.setData({fileList}); this.triggerEvent('upload', { fileType: this.data.dict[this.data.accept], fileList: fileList }) }, deleteImg(e) { const index = getEventParam(e, "index"); const {fileList = []} = this.data; fileList.splice(index, 1); if (fileList.length == 0) { this.setData({ accept: 'media', fileList }, () => { this.triggerEvent('upload', { fileType: this.data.dict[this.data.accept], fileList: fileList }) }); } else { this.setData({ fileList }, () => { this.triggerEvent('upload', { fileType: this.data.dict[this.data.accept], fileList: fileList }) }); } }, }, })