PlateKeyBoardKey.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <Touchable
  3. v-if="text"
  4. direction="column"
  5. :innerStyle="keyStyle"
  6. :pressedColor="context.keyPressedColor.value"
  7. :touchable="text!==''"
  8. @click="emit('click', text, action)"
  9. >
  10. <Icon v-if="icon" :icon="text" :innerStyle="context.keyTextStyle.value" />
  11. <Text v-else :innerStyle="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 } from '../theme/ThemeDefine';
  21. import { DynamicColor, DynamicSize } from '../theme/ThemeTools';
  22. import type { PlateKeyBoardContext } from './PlateKeyBoardInner.vue';
  23. import FlexCol from '../layout/FlexCol.vue';
  24. import Text from '../basic/Text.vue';
  25. import Icon from '../basic/Icon.vue';
  26. import Touchable from '../feedback/Touchable.vue';
  27. export interface PlateKeyBoardKeyProps {
  28. text: string,
  29. icon: boolean,
  30. action?: string,
  31. width?: number,
  32. height?: number,
  33. }
  34. const emit = defineEmits([ 'click' ])
  35. const props = withDefaults(defineProps<PlateKeyBoardKeyProps>(), {
  36. action: '',
  37. width: 0,
  38. height: 1,
  39. });
  40. const themeContext = useTheme();
  41. const themeStyles = themeContext.useThemeStyles({
  42. key: {
  43. display: 'flex',
  44. flexBasis: '13%',
  45. width: '13%',
  46. height: '10rpx',
  47. flexDirection: 'column',
  48. justifyContent: 'center',
  49. alignItems: 'center',
  50. borderWidth: DynamicSize('PlateKeyBoardKeyBorderWidth', 2),
  51. borderColor: DynamicColor('PlateKeyBoardKeyBorderColor', 'border.default'),
  52. borderRadius: DynamicSize('PlateKeyBoardKeyBorderRadius', 10),
  53. },
  54. });
  55. const context = inject<PlateKeyBoardContext>('PlateKeyBoardContext') as PlateKeyBoardContext;
  56. const keyStyle = computed(() => ({
  57. ...themeStyles.key.value,
  58. backgroundColor: themeContext.resolveThemeColor(context.keyColor.value),
  59. flexBasis: `${props.width === 0 ? (100 / context.keyColumCount.value) : props.width}%`,
  60. width: `${props.width === 0 ? (100 / context.keyColumCount.value) : props.width}%`,
  61. height: themeContext.resolveSize(context.keyHeight.value * props.height),
  62. minHeight: themeContext.resolveSize(context.keyHeight.value * props.height),
  63. margin: themeContext.resolveSize(context.keyMargin.value),
  64. ...context.keyStyle.value,
  65. }));
  66. defineOptions({
  67. options: {
  68. virtualHost: true,
  69. }
  70. })
  71. </script>