ActivityIndicator.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view
  3. class="nana-activity-indicator"
  4. :style="style"
  5. >
  6. </view>
  7. </template>
  8. <script setup lang="ts">
  9. import { computed } from 'vue';
  10. import { propGetThemeVar, useTheme, type ViewStyle } from '../theme/ThemeDefine';
  11. export interface ActivityIndicatorProps {
  12. /**
  13. * 加载中圆圈颜色
  14. */
  15. color?: string,
  16. /**
  17. * 加载中圆圈颜色
  18. */
  19. size?: string|number,
  20. /**
  21. * 自定义样式
  22. */
  23. innerStyle?: ViewStyle,
  24. }
  25. const themeContext = useTheme();
  26. const props = withDefaults(defineProps<ActivityIndicatorProps>(), {
  27. color: () => propGetThemeVar('ActivityIndicatorColor', 'primary'),
  28. size: () => propGetThemeVar('ActivityIndicatorSize', 60),
  29. })
  30. const style = computed(() => {
  31. return {
  32. borderTopColor: themeContext.resolveThemeColor(props.color),
  33. width: themeContext.resolveThemeSize(props.size),
  34. height: themeContext.resolveThemeSize(props.size),
  35. ...props.innerStyle,
  36. }
  37. });
  38. </script>
  39. <style>
  40. @keyframes spin {
  41. from {
  42. transform: rotate(0deg);
  43. }
  44. to {
  45. transform: rotate(360deg);
  46. }
  47. }
  48. .nana-activity-indicator {
  49. width: 50px;
  50. height: 50px;
  51. border: 5px solid transparent;
  52. border-top: 5px solid #3498db;
  53. border-radius: 50%;
  54. animation: spin 1s linear infinite;
  55. }
  56. </style>