-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor code structure and improve demo page (#4389)
* feat: captcha example * fix: fix lint errors * chore: event handling and methods * chore: add accessibility features ARIA labels and roles * refactor: refactor code structure and improve captcha demo page * feat: add captcha internationalization * chore: 适配时间戳国际化展示 --------- Co-authored-by: vince <vince292007@gmail.com>
- Loading branch information
1 parent
10b90ea
commit 5ba3a9d
Showing
10 changed files
with
459 additions
and
157 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
packages/effects/common-ui/src/components/captcha/captcha-card.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<script setup lang="ts"> | ||
import type { CaptchaCardProps } from './types'; | ||
import { computed } from 'vue'; | ||
import { $t } from '@vben/locales'; | ||
import { | ||
Card, | ||
CardContent, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from '@vben-core/shadcn-ui'; | ||
import { parseValue } from './utils'; | ||
const props = withDefaults(defineProps<CaptchaCardProps>(), { | ||
height: '220px', | ||
paddingX: '12px', | ||
paddingY: '16px', | ||
title: '', | ||
width: '300px', | ||
}); | ||
const emit = defineEmits<{ | ||
click: [MouseEvent]; | ||
}>(); | ||
const rootStyles = computed(() => ({ | ||
padding: `${parseValue(props.paddingY)}px ${parseValue(props.paddingX)}px`, | ||
width: `${parseValue(props.width) + parseValue(props.paddingX) * 2}px`, | ||
})); | ||
const captchaStyles = computed(() => { | ||
return { | ||
height: `${parseValue(props.height)}px`, | ||
width: `${parseValue(props.width)}px`, | ||
}; | ||
}); | ||
function handleClick(e: MouseEvent) { | ||
emit('click', e); | ||
} | ||
</script> | ||
<template> | ||
<Card :style="rootStyles" aria-labelledby="captcha-title" role="region"> | ||
<CardHeader class="p-0"> | ||
<CardTitle id="captcha-title" class="flex items-center justify-between"> | ||
<template v-if="$slots.title"> | ||
<slot name="title">{{ $t('captcha.title') }}</slot> | ||
</template> | ||
<template v-else> | ||
<span>{{ title }}</span> | ||
</template> | ||
<div class="flex items-center justify-end"> | ||
<slot name="extra"></slot> | ||
</div> | ||
</CardTitle> | ||
</CardHeader> | ||
<CardContent class="relative mt-2 flex w-full overflow-hidden rounded p-0"> | ||
<img | ||
v-show="captchaImage" | ||
:alt="$t('captcha.alt')" | ||
:src="captchaImage" | ||
:style="captchaStyles" | ||
class="relative z-10" | ||
@click="handleClick" | ||
/> | ||
<div class="absolute inset-0"> | ||
<slot></slot> | ||
</div> | ||
</CardContent> | ||
<CardFooter class="mt-2 flex justify-between p-0"> | ||
<slot name="footer"></slot> | ||
</CardFooter> | ||
</Card> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as CaptchaCard } from './captcha-card.vue'; | ||
export { default as PointSelectionCaptcha } from './point-selection-captcha.vue'; | ||
export type * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.