| | |
| | | return ""; |
| | | } |
| | | |
| | | /** 上传后的文件值(数组,元素为 { name, url } 或 url 字符串) */ |
| | | const uploading = computed(() => false); |
| | | |
| | | /** 历史文件值仅用于只读展示,App 端不提供附件上传。 */ |
| | | function fileList(field: FormField) { |
| | | const value = getValue(field); |
| | | if (!Array.isArray(value)) return []; |
| | | return value.map(item => |
| | | typeof item === "string" ? { name: item, url: item } : item, |
| | | ); |
| | | } |
| | | |
| | | async function removeFile(field: FormField, index: number) { |
| | | const list = fileList(field); |
| | | const next = list.filter((_, i) => i !== index); |
| | | setValue( |
| | | field.field, |
| | | next.map(item => item.value ?? item.url ?? item), |
| | | ); |
| | | } |
| | | |
| | |
| | | <view v-else-if="field.kind === 'image' || field.kind === 'file'" class="upload"> |
| | | <view v-for="(file, index) in fileList(field)" :key="index" class="upload-item"> |
| | | <text class="upload-name">{{ file.name || `文件${index + 1}` }}</text> |
| | | <text class="upload-remove" @click="removeFile(field, index)">删除</text> |
| | | </view> |
| | | <text class="upload-tip">{{ field.placeholder }}</text> |
| | | </view> |
| | | |
| | | <!-- 兜底:不支持的组件按文本录入,保证值能填上 --> |