compute all hashes at the same time instead of using a select
This commit is contained in:
		
							parent
							
								
									34bc6a57a7
								
							
						
					
					
						commit
						4df3af4888
					
				| @ -2,34 +2,21 @@ | |||||||
|   <div> |   <div> | ||||||
|     <n-card> |     <n-card> | ||||||
|       <n-input v-model:value="clearText" type="textarea" placeholder="Your string..." :autosize="{ minRows: 3 }" /> |       <n-input v-model:value="clearText" type="textarea" placeholder="Your string..." :autosize="{ minRows: 3 }" /> | ||||||
|       <br /> |  | ||||||
|       <br /> |  | ||||||
|       <n-select v-model:value="algo" :options="Object.keys(algos).map((label) => ({ label, value: label }))" /> |  | ||||||
| 
 | 
 | ||||||
|       <br /> |       <n-divider /> | ||||||
|       <n-input | 
 | ||||||
|         style="text-align: center" |       <div v-for="algo in list" :key="algo" style="margin: 5px 0"> | ||||||
|         :value="hashedText" |         <n-input-group> | ||||||
|         type="textarea" |           <n-input-group-label style="flex: 0 0 120px"> {{ algo }} </n-input-group-label> | ||||||
|         placeholder="Your string hash" |           <input-copyable :value="hashedText(algo, clearText)" readonly /> | ||||||
|         :autosize="{ minRows: 1 }" |         </n-input-group> | ||||||
|         readonly |       </div> | ||||||
|         autocomplete="off" |  | ||||||
|         autocorrect="off" |  | ||||||
|         autocapitalize="off" |  | ||||||
|         spellcheck="false" |  | ||||||
|       /> |  | ||||||
|       <br /> |  | ||||||
|       <br /> |  | ||||||
|       <n-space justify="center"> |  | ||||||
|         <n-button secondary autofocus @click="copy"> Copy </n-button> |  | ||||||
|       </n-space> |  | ||||||
|     </n-card> |     </n-card> | ||||||
|   </div> |   </div> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| <script setup lang="ts"> | <script setup lang="ts"> | ||||||
| import { useCopy } from '@/composable/copy'; | import InputCopyable from '../../components/InputCopyable.vue'; | ||||||
| import { ref, computed } from 'vue'; | import { ref, computed } from 'vue'; | ||||||
| import { MD5, SHA1, SHA256, SHA224, SHA512, SHA384, SHA3, RIPEMD160 } from 'crypto-js'; | import { MD5, SHA1, SHA256, SHA224, SHA512, SHA384, SHA3, RIPEMD160 } from 'crypto-js'; | ||||||
| 
 | 
 | ||||||
| @ -44,11 +31,11 @@ const algos = { | |||||||
|   RIPEMD160, |   RIPEMD160, | ||||||
| } as const; | } as const; | ||||||
| 
 | 
 | ||||||
| const clearText = ref( | type Algo = keyof typeof algos; | ||||||
|   'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lacus metus blandit dolor lacus natoque ad fusce aliquam velit.', | const list = Object.keys(algos) as Algo[]; | ||||||
| ); |  | ||||||
| const algo = ref<keyof typeof algos>('SHA256'); |  | ||||||
| const hashedText = computed(() => algos[algo.value](clearText.value).toString()); |  | ||||||
| 
 | 
 | ||||||
| const { copy } = useCopy({ source: hashedText, text: 'Hash copied to the clipboard' }); | const clearText = ref( | ||||||
|  |   'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lacus metus blandit dolor lacus natoque ad fusce aliquam velit.' | ||||||
|  | ); | ||||||
|  | const hashedText = (algo: Algo, value: string) => (value ? algos[algo](value).toString() : ''); | ||||||
| </script> | </script> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user