b25b036d
wuxw
v1.9 优化日期
|
1
|
<template>
|
43eaaadb
wuxw
开发房屋优惠折扣
|
2
|
<div class="upload-image-container">
|
f99ceb4f
wuxw
收据优化完成
|
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<div class="image-preview">
<div v-for="(image, index) in photos" :key="index" class="image-item">
<el-image
:src="image.url"
fit="cover"
:preview-src-list="previewList"
style="width: 100px; height: 100px"
></el-image>
<i class="el-icon-delete delete-icon" @click="removeImage(index)"></i>
</div>
<div v-if="photos.length < maxCount" class="upload-btn" @click="triggerUpload">
<i class="el-icon-plus"></i>
</div>
|
43eaaadb
wuxw
开发房屋优惠折扣
|
16
|
</div>
|
f99ceb4f
wuxw
收据优化完成
|
17
18
|
<input
type="file"
|
43eaaadb
wuxw
开发房屋优惠折扣
|
19
|
ref="fileInput"
|
f99ceb4f
wuxw
收据优化完成
|
20
21
|
accept="image/*"
style="display: none"
|
43eaaadb
wuxw
开发房屋优惠折扣
|
22
|
@change="handleFileChange"
|
f99ceb4f
wuxw
收据优化完成
|
23
|
multiple
|
43eaaadb
wuxw
开发房屋优惠折扣
|
24
25
26
27
28
|
/>
</div>
</template>
<script>
|
f99ceb4f
wuxw
收据优化完成
|
29
30
|
import { uploadImage } from '@/api/fee/listApplyRoomDiscountRecordApi'
import { getCommunityId } from '@/api/community/communityApi'
|
43eaaadb
wuxw
开发房屋优惠折扣
|
31
32
33
34
|
export default {
name: 'UploadImageUrl',
props: {
|
f99ceb4f
wuxw
收据优化完成
|
35
|
maxCount: {
|
43eaaadb
wuxw
开发房屋优惠折扣
|
36
37
38
39
40
41
|
type: Number,
default: 99
}
},
data() {
return {
|
f99ceb4f
wuxw
收据优化完成
|
42
43
|
photos: [],
previewList: []
|
43eaaadb
wuxw
开发房屋优惠折扣
|
44
45
46
47
48
49
50
51
52
53
|
}
},
methods: {
triggerUpload() {
this.$refs.fileInput.click()
},
async handleFileChange(event) {
const files = event.target.files
if (!files || files.length === 0) return
|
f99ceb4f
wuxw
收据优化完成
|
54
55
|
if (files.length + this.photos.length > this.maxCount) {
this.$message.error(this.$t('uploadImage.maxCountError', { count: this.maxCount }))
|
43eaaadb
wuxw
开发房屋优惠折扣
|
56
57
58
|
return
}
|
f99ceb4f
wuxw
收据优化完成
|
59
60
61
62
63
|
for (let i = 0; i < files.length; i++) {
const file = files[i]
if (file.size > 2 * 1024 * 1024) {
this.$message.error(this.$t('uploadImage.sizeError')))
continue
|
43eaaadb
wuxw
开发房屋优惠折扣
|
64
|
}
|
43eaaadb
wuxw
开发房屋优惠折扣
|
65
|
|
f99ceb4f
wuxw
收据优化完成
|
66
67
68
69
|
try {
const formData = new FormData()
formData.append('uploadFile', file)
formData.append('communityId', getCommunityId())
|
43eaaadb
wuxw
开发房屋优惠折扣
|
70
|
|
f99ceb4f
wuxw
收据优化完成
|
71
72
73
74
75
76
77
78
79
80
81
|
const res = await uploadImage(formData)
if (res.code === 0) {
this.photos.push({
fileId: res.data.fileId,
url: res.data.url
})
this.previewList.push(res.data.url)
}
} catch (error) {
this.$message.error(this.$t('uploadImage.uploadFailed')))
}
|
43eaaadb
wuxw
开发房屋优惠折扣
|
82
|
}
|
f99ceb4f
wuxw
收据优化完成
|
83
|
event.target.value = null
|
43eaaadb
wuxw
开发房屋优惠折扣
|
84
85
86
|
},
removeImage(index) {
this.photos.splice(index, 1)
|
f99ceb4f
wuxw
收据优化完成
|
87
|
this.previewList.splice(index, 1)
|
43eaaadb
wuxw
开发房屋优惠折扣
|
88
|
},
|
f99ceb4f
wuxw
收据优化完成
|
89
90
|
getPhotos() {
return this.photos.map(item => item.fileId)
|
43eaaadb
wuxw
开发房屋优惠折扣
|
91
92
93
|
},
clear() {
this.photos = []
|
f99ceb4f
wuxw
收据优化完成
|
94
|
this.previewList = []
|
43eaaadb
wuxw
开发房屋优惠折扣
|
95
96
97
98
99
100
101
|
}
}
}
</script>
<style lang="scss" scoped>
.upload-image-container {
|
f99ceb4f
wuxw
收据优化完成
|
102
103
104
105
|
.image-preview {
display: flex;
flex-wrap: wrap;
gap: 10px;
|
43eaaadb
wuxw
开发房屋优惠折扣
|
106
|
|
f99ceb4f
wuxw
收据优化完成
|
107
108
109
110
|
.image-item {
position: relative;
width: 100px;
height: 100px;
|
43eaaadb
wuxw
开发房屋优惠折扣
|
111
|
|
f99ceb4f
wuxw
收据优化完成
|
112
113
114
115
116
117
118
119
120
121
122
|
.delete-icon {
position: absolute;
top: -10px;
right: -10px;
color: #f56c6c;
cursor: pointer;
font-size: 16px;
background: white;
border-radius: 50%;
padding: 2px;
}
|
43eaaadb
wuxw
开发房屋优惠折扣
|
123
124
|
}
|
f99ceb4f
wuxw
收据优化完成
|
125
126
127
128
129
130
131
|
.upload-btn {
width: 100px;
height: 100px;
border: 1px dashed #dcdfe6;
display: flex;
justify-content: center;
align-items: center;
|
43eaaadb
wuxw
开发房屋优惠折扣
|
132
|
cursor: pointer;
|
f99ceb4f
wuxw
收据优化完成
|
133
134
|
color: #909399;
font-size: 24px;
|
43eaaadb
wuxw
开发房屋优惠折扣
|
135
136
|
&:hover {
|
f99ceb4f
wuxw
收据优化完成
|
137
138
|
border-color: #409eff;
color: #409eff;
|
43eaaadb
wuxw
开发房屋优惠折扣
|
139
140
141
|
}
}
}
|
43eaaadb
wuxw
开发房屋优惠折扣
|
142
143
|
}
</style>
|