|
@@ -4,22 +4,25 @@
|
|
|
action="#"
|
|
|
:show-file-list="false"
|
|
|
:http-request="onImport"
|
|
|
+ multiple
|
|
|
class="ml-2"
|
|
|
- :on-success="onSuccess"
|
|
|
+ accept="image/*"
|
|
|
+ :on-change="onChange"
|
|
|
+ :before-upload="beforeUpload"
|
|
|
>
|
|
|
- <m-button size="mini" :loading="loading">
|
|
|
- 上传附件
|
|
|
+ <m-button size="mini" :loading="loading" @click="currentFiles = []">
|
|
|
+ {{ previewUrl.length ? '重新上传' : '上传附件' }}
|
|
|
</m-button>
|
|
|
</el-upload>
|
|
|
|
|
|
- <m-button size="mini" class="ml-3" v-if="previewUrl" @click="onOpen">
|
|
|
- 查看附件
|
|
|
+ <m-button size="mini" class="ml-3" v-if="previewUrl.length" @click="onOpen">
|
|
|
+ 查看附件 ({{ previewUrl.length }})
|
|
|
</m-button>
|
|
|
<el-image
|
|
|
ref="hiddenPreview"
|
|
|
style="display: none;"
|
|
|
- :src="previewUrl"
|
|
|
- :preview-src-list="[previewUrl]"
|
|
|
+ :src="previewUrl.length ? previewUrl[0] : ''"
|
|
|
+ :preview-src-list="previewUrl"
|
|
|
></el-image>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -32,33 +35,52 @@ export default {
|
|
|
name: 'accumulatePointsApplyEditUpload',
|
|
|
props: {
|
|
|
value: {
|
|
|
- type: [String, Object],
|
|
|
- default: null
|
|
|
+ type: Array,
|
|
|
+ default: () => []
|
|
|
}
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
loading: false,
|
|
|
- previewUrl: null
|
|
|
+ previewUrl: [],
|
|
|
+ filesUrl: [],
|
|
|
+ currentFiles: [] // 用于临时存储当前选择的文件
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ beforeUpload (file) {
|
|
|
+ // 每次选择前清空之前的内容
|
|
|
+ if (this.currentFiles.length === 0) {
|
|
|
+ this.previewUrl = []
|
|
|
+ this.filesUrl = []
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ },
|
|
|
+ onChange (file, fileList) {
|
|
|
+ // 存储当前选择的文件列表
|
|
|
+ this.currentFiles = fileList
|
|
|
+ },
|
|
|
onOpen () {
|
|
|
const img = this.$refs.hiddenPreview.$el.querySelector('img')
|
|
|
img && img.click()
|
|
|
},
|
|
|
async onImport (response) {
|
|
|
this.loading = true
|
|
|
+ // 清空之前的内容
|
|
|
+ this.previewUrl = []
|
|
|
+ this.filesUrl = []
|
|
|
const param = new FormData()
|
|
|
param.append('file', response.file)
|
|
|
param.append('fileType', 'employee_score')
|
|
|
try {
|
|
|
const { msg } = await fileUpload(param)
|
|
|
- this.$emit('input', msg)
|
|
|
+ this.filesUrl.push(msg)
|
|
|
+ this.$emit('input', this.filesUrl)
|
|
|
// 创建预览
|
|
|
const reader = new FileReader()
|
|
|
reader.onload = (e) => {
|
|
|
- this.previewUrl = e.target.result
|
|
|
+ this.previewUrl.push(e.target.result)
|
|
|
+ response.onSuccess()
|
|
|
}
|
|
|
reader.readAsDataURL(response.file)
|
|
|
} catch (error) {
|