feat: add file upload workflow

This commit is contained in:
yml
2026-05-22 18:50:32 +08:00
parent 6f915b37d3
commit 236518ade4
22 changed files with 819 additions and 117 deletions
@@ -3,10 +3,13 @@ import { ElMessage } from 'element-plus'
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { uploadFile } from '@/api/files'
import { createListing } from '@/api/listings'
const router = useRouter()
const loading = ref(false)
const uploading = ref(false)
const screenshotUrls = ref<string[]>([])
const form = reactive({
title: '',
description: '',
@@ -25,7 +28,7 @@ const form = reactive({
async function handleSubmit() {
loading.value = true
try {
await createListing({ ...form })
await createListing({ ...form, screenshot_urls: screenshotUrls.value })
ElMessage.success('发布已创建')
await router.push('/seller/listings')
} catch (error) {
@@ -35,6 +38,27 @@ async function handleSubmit() {
}
}
async function handleScreenshotUpload(event: Event) {
const input = event.target as HTMLInputElement
const file = input.files?.[0]
if (!file) return
uploading.value = true
try {
const uploaded = await uploadFile(file, 'listing')
screenshotUrls.value = [...screenshotUrls.value, uploaded.url]
ElMessage.success('截图已上传')
} catch (error) {
ElMessage.error(readError(error, '截图上传失败'))
} finally {
uploading.value = false
input.value = ''
}
}
function removeScreenshot(index: number) {
screenshotUrls.value = screenshotUrls.value.filter((_, itemIndex) => itemIndex !== index)
}
function readError(error: unknown, fallback: string) {
if (typeof error === 'object' && error && 'response' in error) {
const response = (error as { response?: { data?: { message?: string } } }).response
@@ -59,6 +83,25 @@ function readError(error: unknown, fallback: string) {
<el-form-item label="账号说明">
<el-input v-model="form.description" type="textarea" :rows="3" />
</el-form-item>
<el-form-item label="账号资产截图">
<div class="upload-stack">
<div class="upload-line">
<input
type="file"
accept="image/jpeg,image/png,image/webp,application/pdf"
:disabled="uploading || screenshotUrls.length >= 12"
@change="handleScreenshotUpload"
/>
<el-button :loading="uploading" disabled>最多 12 </el-button>
</div>
<div v-if="screenshotUrls.length" class="evidence-list">
<div v-for="(url, index) in screenshotUrls" :key="url" class="evidence-row">
<span>{{ url }}</span>
<el-button size="small" @click="removeScreenshot(index)">移除</el-button>
</div>
</div>
</div>
</el-form-item>
<div class="form-grid">
<el-form-item label="区服">
<el-input v-model="form.server_region" />