NumberKeyBoardKey.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <Touchable
  3. v-if="text"
  4. :innerStyle="keyStyle"
  5. :pressedColor="action === 'finish' ? context.keyFinishPressedColor.value : context.keyPressedColor.value"
  6. touchable
  7. direction="column"
  8. @click="emit('click', action, text)"
  9. >
  10. <Icon v-if="icon" :icon="text" :innerStyle="context.keyTextStyle.value" />
  11. <Text v-else :innerStyle="action === 'finish' ? context.keyTextStyleFinish.value : context.keyTextStyle.value" :text="text" />
  12. </Touchable>
  13. <view
  14. v-else
  15. :style="keyStyle"
  16. />
  17. </template>
  18. <script setup lang="ts">
  19. import { computed, inject } from 'vue';
  20. import { useTheme, type ViewStyle } from '../theme/ThemeDefine';
  21. import { DynamicSize } from '../theme/ThemeTools';
  22. import type { NumberKeyBoardContext } from './NumberKeyBoardInner.vue';
  23. import Text from '../basic/Text.vue';;
  24. import Icon from '../basic/Icon.vue';
  25. import Touchable from '../feedback/Touchable.vue';
  26. export interface NumberKeyBoardKeyProps {
  27. text: string;
  28. icon: boolean;
  29. action?: string;
  30. widthCount?: number;
  31. heightCount?: number;
  32. side?: boolean;
  33. }
  34. const emit = defineEmits([ 'click' ]);
  35. const props = withDefaults(defineProps<NumberKeyBoardKeyProps>(), {
  36. action: '',
  37. widthCount: 2,
  38. heightCount: 2,
  39. side: false
  40. });
  41. const context = inject<NumberKeyBoardContext>('NumberKeyBoardContext') as NumberKeyBoardContext;
  42. const keyWidthReal = computed(() => props.widthCount * context.keyWidthBase.value + context.keyMargin.value * (props.widthCount - 1) - 5);
  43. const keyHeightReal = computed(() => props.heightCount * context.keyHeight.value + (props.side ? context.keyMargin.value * (props.heightCount - 1) : 0));
  44. const keyStyle = computed(() => ({
  45. ...themeStyles.key.value,
  46. backgroundColor: themeContext.resolveThemeColor(props.action === 'finish' ? context.keyFinishColor.value : context.keyColor.value),
  47. width: themeContext.resolveSize(keyWidthReal.value),
  48. height: themeContext.resolveSize(keyHeightReal.value),
  49. minHeight: themeContext.resolveSize(keyHeightReal.value),
  50. marginLeft: themeContext.resolveSize(props.side ? 0 : context.keyMargin.value),
  51. marginRight: themeContext.resolveSize(props.side ? context.keyMargin.value : 0),
  52. marginTop: themeContext.resolveSize(context.keyMargin.value),
  53. ...context.keyStyle.value,
  54. }) as ViewStyle);
  55. const themeContext = useTheme();
  56. const themeStyles = themeContext.useThemeStyles({
  57. key: {
  58. display: 'flex',
  59. height: DynamicSize('NumberKeyBoardKeyHeight', 20),
  60. flexDirection: 'column',
  61. justifyContent: 'center',
  62. alignItems: 'center',
  63. borderRadius: DynamicSize('NumberKeyBoardKeyBorderRadius', 12),
  64. },
  65. });
  66. </script>