1818 </div >
1919 </div >
2020 <div class =" divider" />
21- <div ref = " scrollContainer " class =" flex-col p-5 overflow-y-auto h-180 mt-10" style =" scroll-behavior : smooth ;" >
21+ <div class =" flex-col p-5 overflow-y-auto h-180 mt-10" style =" scroll-behavior : smooth ;" >
2222 <div v-for =" item in localOptions" :key =" item.serialNum" class =" my-5" >
2323 <div class =" flex items-center gap-10" >
24- <input type =" checkbox" :name =" item.serialNum" class =" checkbox-sm my-5" >
24+ <input type =" checkbox" :name =" `${ item.serialNum}` " class =" checkbox-sm my-5" >
2525 <input
2626 v-model =" item.content"
2727 type =" text"
3030 >
3131 <div class =" ml-10 flex items-center gap-20" >
3232 <div v-if =" item.img" class =" mt-4" >
33- <img :src =" item.img" :key =" item.img" alt =" Preview" style =" max-width : 50px ; max-height : 50px ;" >
33+ <img
34+ :key =" item.img"
35+ :src =" item.img"
36+ alt =" Preview"
37+ style =" max-width : 50px ; max-height : 50px ;"
38+ >
3439 </div >
3540 <input
3641 v-if =" isActive"
5863</template >
5964
6065<script setup lang="ts">
61- import { ref , watch , defineProps , defineEmits } from " vue" ;
66+ import { ref , watch } from " vue" ;
6267import { useRequest } from " vue-hooks-plus" ;
6368import { saveImgAPI } from " @/apis" ;
6469import { ElNotification } from " element-plus" ;
@@ -80,8 +85,17 @@ const props = defineProps<{
8085 }[]
8186}>();
8287
83- const scrollContainer = ref <HTMLDivElement >();
84- const emits = defineEmits ([" update:unique" , " on-click" , " update:otherOption" , " update:optionChoose" , " update:title" , " update:options" , " update:describe" ]);
88+ const emits = defineEmits ([
89+ " update:unique" ,
90+ " on-click" ,
91+ " update:otherOption" ,
92+ " update:optionChoose" ,
93+ " update:title" ,
94+ " update:options" ,
95+ " update:describe" ,
96+ " update:minimum_option" ,
97+ " update:maximum_option"
98+ ]);
8599
86100// Local copies of props to maintain reactivity
87101const localTitle = ref <string >(props .title || " " );
@@ -97,37 +111,37 @@ const handleFileChange = async (event: Event, serialNum: number) => {
97111 const input = event .target as HTMLInputElement ;
98112 const file = input .files ?.[0 ];
99113 if (! file ) return ;
100-
114+
101115 const formData = new FormData ();
102116 formData .append (" img" , file );
103-
104- const currentOption = localOptions .value .find (item => item .serialNum === serialNum );
117+
118+ const currentOption = localOptions .value ? .find (item => item .serialNum === serialNum );
105119 if (! currentOption ) return ;
106-
107- const originalImg = currentOption .img || ' ' ;
108-
120+
121+ const originalImg = currentOption .img || " " ;
122+
109123 useRequest (() => saveImgAPI (formData ), {
110124 onSuccess(res : any ) {
111125 if (res .code === 200 ) {
112-
126+
113127 currentOption .img = res .data ;
114128 ElNotification .success (" 上传图片成功" );
115129 } else {
116130 throw new Error (res .msg || " 上传失败" );
117131 }
118132 },
119133 onError(error : any ) {
120-
134+
121135 currentOption .img = originalImg ;
122- input .value = ' ' ;
136+ input .value = " " ;
123137 ElNotification .error (" 上传图片失败:" + (error .message || error ));
124138 }
125139 });
126140};
127141
128142const deleteOption = (serialNum : number ) => {
129- localOptions .value = localOptions .value .filter (item => item .serialNum !== serialNum );
130- localOptions .value .forEach ((item ) => {
143+ localOptions .value = localOptions .value ? .filter (item => item .serialNum !== serialNum );
144+ localOptions .value ? .forEach ((item ) => {
131145 if (item .serialNum > serialNum ) {
132146 item .serialNum -= 1 ;
133147 }
0 commit comments