examPointVenueImage.vue
5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<template>
<view class="venue-page">
<view class="content-card">
<view class="title">上传场馆照片</view>
<view class="desc">请上传 1~3 张清晰的场馆照片,照片将作为考点申请材料提交审核。</view>
<view class="photo-grid">
<view
v-for="(item, index) in photoList"
:key="item.url"
class="photo-item"
>
<image class="photo" :src="item.previewUrl" mode="aspectFill" @click="previewPhoto(index)" />
<view class="delete-btn" @click.stop="deletePhoto(index)">×</view>
</view>
<view v-if="photoList.length < 3" class="upload-card" @click="choosePhoto">
<view class="plus">+</view>
<view class="upload-text">添加照片</view>
</view>
</view>
<view class="tip">最多上传 3 张,支持从相册选择或拍照上传。</view>
</view>
<view class="footer">
<button class="back-btn" @click="goBack">上一步</button>
<button class="next-btn" @click="goNext">下一步</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { fillImgUrl } from '@/common/utils.js'
import config from '@/config.js'
const photoList = ref([])
const memId = ref('')
onLoad((option) => {
memId.value = option.memId || ''
})
function choosePhoto() {
const count = 3 - photoList.value.length
if (count <= 0) return
uni.chooseImage({
count,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: async (res) => {
const paths = res.tempFilePaths || []
for (const path of paths) {
if (photoList.value.length >= 3) break
await uploadPhoto(path)
}
}
})
}
async function uploadPhoto(path) {
if (!path) return
try {
uni.showLoading({ title: '上传中', mask: true })
const res = await uploadApplyImage(path)
const url = getUploadUrl(res)
if (!url) {
uni.showToast({ title: '上传返回数据异常', icon: 'none' })
return
}
photoList.value.push({
url,
previewUrl: fillImgUrl(url)
})
} catch (err) {
uni.showToast({ title: '上传失败,请重新上传', icon: 'none' })
} finally {
uni.hideLoading()
}
}
function uploadApplyImage(path) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: config.baseUrl_api + '/fileServer/uploadImg',
filePath: path,
name: 'image',
header: {
'Authorization': uni.getStorageSync('token')
},
success: (res) => {
try {
resolve(JSON.parse(res.data || '{}'))
} catch (e) {
reject(e)
}
},
fail: reject
})
})
}
function getUploadUrl(res) {
const data = res?.data
if (typeof data === 'string') return data
return data?.ms || data?.url || data?.fang || res?.msg || ''
}
function deletePhoto(index) {
photoList.value.splice(index, 1)
}
function previewPhoto(index) {
uni.previewImage({
current: index,
urls: photoList.value.map(item => item.previewUrl)
})
}
function goNext() {
if (photoList.value.length === 0) {
uni.showToast({ title: '请上传1~3张场馆照片', icon: 'none' })
return
}
const photos = encodeURIComponent(JSON.stringify(photoList.value.map(item => item.url)))
uni.navigateTo({
url: `/myCenter/examPointApply?photos=${photos}&memId=${memId.value || ''}`
})
}
function goBack() {
uni.navigateBack({ delta: 1 })
}
</script>
<style lang="scss" scoped>
.venue-page {
min-height: 100vh;
display: flex;
flex-direction: column;
background: #f5f5f5;
}
.content-card {
flex: 1;
margin: 30rpx;
padding: 36rpx;
background: #fff;
border-radius: 18rpx;
}
.title {
font-size: 34rpx;
font-weight: 600;
color: #222;
}
.desc {
margin-top: 18rpx;
color: #777;
font-size: 26rpx;
line-height: 1.6;
}
.photo-grid {
display: flex;
flex-wrap: wrap;
gap: 22rpx;
margin-top: 36rpx;
}
.photo-item,
.upload-card {
position: relative;
width: 196rpx;
height: 196rpx;
border-radius: 16rpx;
overflow: hidden;
}
.photo {
width: 100%;
height: 100%;
}
.delete-btn {
position: absolute;
top: 8rpx;
right: 8rpx;
width: 42rpx;
height: 42rpx;
line-height: 38rpx;
text-align: center;
border-radius: 50%;
color: #fff;
background: #C4121B;
font-size: 34rpx;
}
.upload-card {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border: 2rpx dashed #d7d7d7;
background: #fafafa;
}
.plus {
color: #C4121B;
font-size: 58rpx;
line-height: 1;
}
.upload-text {
margin-top: 12rpx;
color: #777;
font-size: 24rpx;
}
.tip {
margin-top: 26rpx;
color: #999;
font-size: 24rpx;
}
.footer {
padding: 30rpx;
display: flex;
justify-content: space-between;
background: #fff;
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
}
.back-btn,
.next-btn {
width: 48%;
height: 88rpx;
line-height: 88rpx;
border-radius: 44rpx;
font-size: 32rpx;
}
.back-btn {
background: #fff;
color: #C4121B;
border: 1rpx solid #C4121B;
}
.next-btn {
background: #C4121B;
color: #fff;
border: none;
}
</style>