handleChange(e, item.id)"
>
-
+
{
- if (info.file.status === 'done') {
- const result = info.file.response?.result;
- console.log('result: ', result);
- }
-};
+// const fileList = computed({
+// get: () => props.attachments.map((m) => ({ id: fileId(), ...m })),
+// set: (val) =>
+// emit(
+// 'update:attachments',
+// val.map(({ name, location }) => ({ name, location })),
+// ),
+// });
const fileList = ref([]);
+
watch(
() => props.attachments,
(val) => {
- fileList.value = val;
+ fileList.value = val.map((m) => ({
+ id: fileId(),
+ ...m,
+ }));
},
{ deep: true },
);
-const handleDelete = (id: number) => {
- const idx = fileList.value.findIndex((f) => f.id === id);
- fileList.value.splice(idx, 1);
- emit('update:attachments', fileList.value);
+const handleChange = (info: UploadChangeParam, id: string | undefined) => {
+ if (info.file.status === 'done') {
+ const targetFileIdx = fileList.value.findIndex((f) => f.id === id);
+ fileList.value[targetFileIdx].name = info.file.name;
+ fileList.value[targetFileIdx].location = info.file.response?.result;
+ }
};
+
+/**
+ * 删除附件
+ * @param id
+ */
+const handleDelete = (id: string | undefined) => {
+ const idx = fileList.value.findIndex((f) => f.id === id);
+
+ fileList.value.splice(idx, 1);
+ emit(
+ 'update:attachments',
+ fileList.value.map(({ name, location }) => ({ name, location })),
+ );
+};
+
+/**
+ * 添加附件
+ */
const handleAdd = () => {
fileList.value.push({
- id: fileList.value.length,
+ id: fileId(),
name: '',
location: '',
});
- emit('update:attachments', fileList.value);
+
+ emit(
+ 'update:attachments',
+ fileList.value.map(({ name, location }) => ({ name, location })),
+ );
};
+
+/**
+ * 附件标识
+ */
+const fileId = () => String(new Date().getTime() + Math.random() * 9);
diff --git a/src/views/notice/Template/Detail/index.vue b/src/views/notice/Template/Detail/index.vue
index 9699ee50..610ad87d 100644
--- a/src/views/notice/Template/Detail/index.vue
+++ b/src/views/notice/Template/Detail/index.vue
@@ -418,6 +418,34 @@