@@ -72,21 +72,35 @@ function readFileAsDataURL(file: File) {
7272 })
7373}
7474
75+ const formSchema = z .object ({
76+ clubId: z .number ().int (),
77+ collectionId: z .string (),
78+ fileContent: z .string (),
79+ rawName: z .string ().max (256 ),
80+ })
81+
7582const onSubmit = form .handleSubmit (async (values ) => {
7683 submitting .value = true
7784 const fileName = values .file .name
78- const status = await $fetch (' /api/files/new-record' , {
79- method: ' POST' ,
80- body: {
81- clubId: Number .parseInt (props .club ),
82- collectionId: props .collection ,
83- fileContent: await readFileAsDataURL (values .file ),
84- rawName: fileName ,
85- },
86- })
87- form .resetForm ()
88- inputKey .value = uuidv4 ()
89- msg .value = (status && status .success ) ? ` ${fileName } (提交成功) ` : ' 提交失败'
85+ const data = {
86+ clubId: Number .parseInt (props .club ),
87+ collectionId: props .collection ,
88+ fileContent: await readFileAsDataURL (values .file ),
89+ rawName: fileName ,
90+ }
91+ if (formSchema .safeParse (data ).success ) {
92+ const status = await $fetch (' /api/files/new-record' , {
93+ method: ' POST' ,
94+ body: data ,
95+ })
96+ form .resetForm ()
97+ inputKey .value = uuidv4 ()
98+ await updateClub ()
99+ msg .value = (status && status .success ) ? ` ${fileName } (提交成功) ` : ' 提交失败'
100+ }
101+ else {
102+ msg .value = ' 文件内容异常'
103+ }
90104 submitting .value = false
91105})
92106
@@ -173,7 +187,7 @@ await updateClub()
173187 </FormItem >
174188 </FormField >
175189 <div class =" mt-2" >
176- <Button type =" submit" variant =" secondary" :disabled =" !form.values.file || submitting || clubUpdating" >
190+ <Button type =" submit" variant =" secondary" :disabled =" !form.values.file || submitting || clubUpdating || !props.club " >
177191 上传
178192 </Button >
179193 <Button v-if =" currentClubData" :disabled =" downloading" variant =" outline" class =" ml-2" type =" button" @click =" download" >
0 commit comments