Fix #7483
This commit is contained in:
		
							parent
							
								
									4b205aee91
								
							
						
					
					
						commit
						77ccf3b929
					
				
					 1 changed files with 16 additions and 10 deletions
				
			
		|  | @ -6,7 +6,7 @@ | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| <script lang="ts"> | <script lang="ts"> | ||||||
| import { defineComponent } from 'vue'; | import { defineComponent, PropType } from 'vue'; | ||||||
| 
 | 
 | ||||||
| type Captcha = { | type Captcha = { | ||||||
| 	render(container: string | Node, options: { | 	render(container: string | Node, options: { | ||||||
|  | @ -32,7 +32,7 @@ declare global { | ||||||
| export default defineComponent({ | export default defineComponent({ | ||||||
| 	props: { | 	props: { | ||||||
| 		provider: { | 		provider: { | ||||||
| 			type: String, | 			type: String as PropType<CaptchaProvider>, | ||||||
| 			required: true, | 			required: true, | ||||||
| 		}, | 		}, | ||||||
| 		sitekey: { | 		sitekey: { | ||||||
|  | @ -51,19 +51,25 @@ export default defineComponent({ | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	computed: { | 	computed: { | ||||||
| 		loaded() { | 		variable(): string { | ||||||
| 			return !!window[this.provider as CaptchaProvider]; | 			switch (this.provider) { | ||||||
|  | 				case 'hcaptcha': return 'hcaptcha'; | ||||||
|  | 				case 'recaptcha': return 'grecaptcha'; | ||||||
|  | 			} | ||||||
| 		}, | 		}, | ||||||
| 		src() { | 		loaded(): boolean { | ||||||
|  | 			return !!window[this.variable]; | ||||||
|  | 		}, | ||||||
|  | 		src(): string { | ||||||
| 			const endpoint = ({ | 			const endpoint = ({ | ||||||
| 				hcaptcha: 'https://hcaptcha.com/1', | 				hcaptcha: 'https://hcaptcha.com/1', | ||||||
| 				recaptcha: 'https://www.recaptcha.net/recaptcha', | 				recaptcha: 'https://www.recaptcha.net/recaptcha', | ||||||
| 			} as Record<PropertyKey, unknown>)[this.provider]; | 			} as Record<CaptchaProvider, string>)[this.provider]; | ||||||
| 
 | 
 | ||||||
| 			return `${typeof endpoint == 'string' ? endpoint : 'about:invalid'}/api.js?render=explicit`; | 			return `${typeof endpoint === 'string' ? endpoint : 'about:invalid'}/api.js?render=explicit`; | ||||||
| 		}, | 		}, | ||||||
| 		captcha() { | 		captcha(): Captcha { | ||||||
| 			return window[this.provider as CaptchaProvider] || {} as unknown as Captcha; | 			return window[this.variable] || {} as unknown as Captcha; | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | @ -94,7 +100,7 @@ export default defineComponent({ | ||||||
| 
 | 
 | ||||||
| 	methods: { | 	methods: { | ||||||
| 		reset() { | 		reset() { | ||||||
| 			this.captcha?.reset(); | 			if (this.captcha?.reset) this.captcha.reset(); | ||||||
| 		}, | 		}, | ||||||
| 		requestRender() { | 		requestRender() { | ||||||
| 			if (this.captcha.render && this.$refs.captcha instanceof Element) { | 			if (this.captcha.render && this.$refs.captcha instanceof Element) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue