66 lines
2.1 KiB
Vue
66 lines
2.1 KiB
Vue
<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: 24rpx; color: #434655; display: block; margin-bottom: 8rpx; }
|
||
.list { display: flex; flex-wrap: wrap; gap: 12rpx; }
|
||
.chip, .add {
|
||
font-size: 22rpx;
|
||
padding: 10rpx 16rpx;
|
||
border-radius: 12rpx;
|
||
background: #fff;
|
||
border: 1rpx solid #dbe1ff;
|
||
color: #2563eb;
|
||
display: flex;
|
||
align-items: center;
|
||
max-width: 100%;
|
||
}
|
||
.name { max-width: 360rpx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||
.del { color: #ba1a1a; margin-left: 10rpx; font-size: 28rpx; line-height: 1; }
|
||
.add { color: #434655; border-style: dashed; }
|
||
.empty { font-size: 22rpx; color: #737686; }
|
||
</style>
|