| | |
| | | <text class="file-title">{{ title }}</text> |
| | | <text class="file-count">{{ filesList.length }}/{{ limitLength }}</text> |
| | | </view> |
| | | <upload-image v-if="fileMediatype === 'image' && showType === 'grid'" :readonly="readonly" |
| | | :image-styles="imageStyles" :files-list="filesList" :limit="limitLength" :disablePreview="disablePreview" |
| | | :delIcon="delIcon" @uploadFiles="uploadFiles" @choose="choose" @delFile="delFile"> |
| | | <upload-image v-if="fileMediatype === 'image' && showType === 'grid'" :readonly="readonly" :image-styles="imageStyles" :files-list="filesList" :limit="limitLength" :disablePreview="disablePreview" :delIcon="delIcon" @uploadFiles="uploadFiles" @choose="choose" @delFile="delFile"> |
| | | <slot> |
| | | <view class="is-add"> |
| | | <view class="icon-add"></view> |
| | | <view class="icon-add rotate"></view> |
| | | </view> |
| | | </slot> |
| | | </upload-image> |
| | | <upload-file v-if="fileMediatype !== 'image' || showType !== 'grid'" :readonly="readonly" |
| | | :list-styles="listStyles" :files-list="filesList" :showType="showType" :delIcon="delIcon" |
| | | @uploadFiles="uploadFiles" @choose="choose" @delFile="delFile"> |
| | | <upload-file v-if="fileMediatype !== 'image' || showType !== 'grid'" :readonly="readonly" :list-styles="listStyles" :files-list="filesList" :showType="showType" :delIcon="delIcon" @uploadFiles="uploadFiles" @choose="choose" @delFile="delFile"> |
| | | <slot><button type="primary" size="mini">选择文件</button></slot> |
| | | </upload-file> |
| | | </view> |
| | |
| | | provider: { |
| | | type: String, |
| | | default: '' // 默认上传到 unicloud 内置存储 extStorage 扩展存储 |
| | | }, |
| | | dir: { |
| | | type: String, |
| | | default: '' |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | files: [], |
| | | localValue: [] |
| | | localValue: [], |
| | | dirPath: '' |
| | | } |
| | | }, |
| | | watch: { |
| | |
| | | modelValue: { |
| | | handler(newVal, oldVal) { |
| | | this.setValue(newVal, oldVal) |
| | | }, |
| | | immediate: true |
| | | }, |
| | | dir: { |
| | | handler(newVal) { |
| | | this.dirPath = newVal |
| | | }, |
| | | immediate: true |
| | | }, |
| | |
| | | * @param {Object} res |
| | | */ |
| | | async chooseFileCallback(res) { |
| | | |
| | | const _extname = get_extname(this.fileExtname) |
| | | |
| | | const is_one = (Number(this.limitLength) === 1 && |
| | | this.disablePreview && |
| | | !this.disabled) || |
| | |
| | | let filedata = await get_file_data(files[i], this.fileMediatype) |
| | | filedata.progress = 0 |
| | | filedata.status = 'ready' |
| | | this.files.push(filedata) |
| | | currentData.push({ |
| | | // fix by mehaotian ,统一返回,删除也包含file对象 |
| | | let fileTempData = { |
| | | ...filedata, |
| | | file: files[i] |
| | | }) |
| | | } |
| | | this.files.push(fileTempData) |
| | | currentData.push(fileTempData) |
| | | } |
| | | this.$emit('select', { |
| | | tempFiles: currentData, |
| | |
| | | if (!this.autoUpload || this.noSpace) { |
| | | res.tempFiles = [] |
| | | } |
| | | res.tempFiles.forEach((fileItem, index) => { |
| | | res.tempFiles.map((fileItem, index) => { |
| | | this.provider && (fileItem.provider = this.provider); |
| | | const fileNameSplit = fileItem.name.split('.') |
| | | const ext = fileNameSplit.pop() |
| | | const fileName = fileNameSplit.join('.').replace(/[\s\/\?<>\\:\*\|":]/g, '_') |
| | | fileItem.cloudPath = fileName + '_' + Date.now() + '_' + index + '.' + ext |
| | | // 选择文件目录上传 |
| | | let dir = this.dirPath || ''; // 防止用户传入的 dir 不正常 |
| | | // 检查最后一个字符是否为 '/'(同时处理空字符串情况) |
| | | if (dir && dir[dir.length - 1] !== '/') { |
| | | dir += '/'; |
| | | } |
| | | |
| | | fileItem.cloudPath = dir + fileName + '_' + Date.now() + '_' + index + '.' + ext |
| | | fileItem.cloudPathAsRealPath = true |
| | | |
| | | return fileItem |
| | | }) |
| | | return res |
| | | }, |
| | | |
| | | /** |
| | |
| | | .file-count { |
| | | font-size: 14px; |
| | | color: #999; |
| | | } |
| | | |
| | | .is-add { |
| | | /* #ifndef APP-NVUE */ |
| | | display: flex; |
| | | /* #endif */ |
| | | align-items: center; |
| | | justify-content: center; |
| | | } |
| | | |
| | | .icon-add { |