66 :close-on-click-modal =" false"
77 :close-on-press-escape =" false"
88 @close =" handleClose"
9- size =" 35 %"
9+ size =" 40 %"
1010 >
1111 <template #header >
1212 <DrawerHeader :header =" $t('setting.apiInterface')" :back =" handleClose" />
@@ -89,6 +89,7 @@ import i18n from '@/lang';
8989import { MsgSuccess } from ' @/utils/message' ;
9090import { ElMessageBox , FormInstance } from ' element-plus' ;
9191import DrawerHeader from ' @/components/drawer-header/index.vue' ;
92+ import { checkCidr , checkIp } from ' @/utils/util' ;
9293
9394const loading = ref ();
9495const drawerVisible = ref ();
@@ -105,7 +106,7 @@ const form = reactive({
105106});
106107
107108const rules = reactive ({
108- ipWhiteList: [Rules .requiredInput ],
109+ ipWhiteList: [Rules .requiredInput , { validator: checkIPs , trigger: ' blur ' } ],
109110 apiKey: [Rules .requiredInput ],
110111});
111112
@@ -114,7 +115,28 @@ interface DialogProps {
114115 apiKey: string ;
115116 ipWhiteList: string ;
116117}
118+
119+ function checkIPs(rule : any , value : any , callback : any ) {
120+ if (form .ipWhiteList !== ' ' ) {
121+ let addr = form .ipWhiteList .split (' \n ' );
122+ for (const item of addr ) {
123+ if (item === ' ' ) {
124+ continue ;
125+ }
126+ if (item .indexOf (' /' ) !== - 1 ) {
127+ if (checkCidr (item )) {
128+ return callback (new Error (i18n .global .t (' firewall.addressFormatError' )));
129+ }
130+ } else if (checkIp (item )) {
131+ return callback (new Error (i18n .global .t (' firewall.addressFormatError' )));
132+ }
133+ }
134+ }
135+ callback ();
136+ }
137+
117138const emit = defineEmits <{ (e : ' search' ): void }>();
139+
118140const acceptParams = async (params : DialogProps ): Promise <void > => {
119141 form .apiInterfaceStatus = params .apiInterfaceStatus ;
120142 form .apiKey = params .apiKey ;
@@ -128,12 +150,12 @@ const acceptParams = async (params: DialogProps): Promise<void> => {
128150};
129151
130152const resetApiKey = async () => {
131- loading .value = true ;
132153 ElMessageBox .confirm (i18n .global .t (' setting.apiKeyResetHelper' ), i18n .global .t (' setting.apiKeyReset' ), {
133154 confirmButtonText: i18n .global .t (' commons.button.confirm' ),
134155 cancelButtonText: i18n .global .t (' commons.button.cancel' ),
135156 })
136157 .then (async () => {
158+ loading .value = true ;
137159 await generateApiKey ()
138160 .then ((res ) => {
139161 loading .value = false ;
0 commit comments