Files
2026-09-23 17:38:24 +08:00

66 lines
2.1 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view v-if="files.length || editable" class="wrap">
<text v-if="label" class="lab">{{ label }}</text>
<view class="list">
<view v-for="(f, i) in files" :key="fileKey(f, i)" class="chip" @click="open(f)">
<text class="name">{{ displayName(f) }}</text>
<text v-if="editable" class="del" @click.stop="$emit('remove', i)">×</text>
</view>
<view v-if="editable" class="add" @click="add"> {{ files.length ? '再加一份' : '上传附件' }}</view>
</view>
<text v-if="!files.length && !editable" class="empty">无附件</text>
</view>
</template>
<script>
import { store } from '../utils/store.js'
import { fileId, fileName, pickAndUpload, openFile } from '../utils/files.js'
import { toast } from '../utils/format.js'
export default {
name: 'FyFiles',
props: {
files: { type: Array, default: () => [] },
label: { type: String, default: '附件' },
editable: { type: Boolean, default: false },
kind: { type: String, default: 'attach' }
},
methods: {
fileKey(f, i) { return fileId(f) || fileName(f) + i },
displayName(f) { return fileName(f) },
async add() {
try {
const rows = await pickAndUpload(store.token, this.kind)
if (rows.length) this.$emit('update:files', [...this.files, ...rows])
} catch (e) {
toast((e && e.message) || '上传失败')
}
},
open(f) {
openFile(f, store.token)
}
}
}
</script>
<style scoped>
.wrap { margin: 12rpx 0; }
.lab { font-size: 26rpx; color: #374151; display: block; margin-bottom: 10rpx; }
.list { display: flex; flex-wrap: wrap; gap: 12rpx; }
.chip, .add {
font-size: 24rpx;
padding: 14rpx 18rpx;
border-radius: 12rpx;
background: #F5F7FA;
border: 1rpx solid #E8ECF2;
color: #1677FF;
display: flex;
align-items: center;
max-width: 100%;
}
.name { max-width: 360rpx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.del { color: #DC2626; margin-left: 10rpx; font-size: 28rpx; line-height: 1; }
.add { color: #4B5563; border-style: dashed; }
.empty { font-size: 22rpx; color: #6B7280; }
</style>