123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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
- })
- });
- }
- },
- },
- })
|