common.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { h, onMounted, CSSProperties } from 'vue';
  2. import { computed, PropType, toRefs } from 'vue';
  3. export type avatarShape = 'round' | 'square';
  4. export const component = {
  5. props: {
  6. //每行宽度
  7. width: {
  8. type: String,
  9. default: '100px'
  10. },
  11. //每行高度
  12. height: {
  13. type: String,
  14. default: '100px'
  15. },
  16. //是否显示动画
  17. animated: {
  18. type: Boolean,
  19. default: false
  20. },
  21. //头像
  22. avatar: {
  23. type: Boolean,
  24. default: false
  25. },
  26. //头像形状:正方形/圆形
  27. avatarShape: {
  28. type: String as PropType<avatarShape>,
  29. default: 'round'
  30. },
  31. //头像大小
  32. avatarSize: {
  33. type: String,
  34. default: '50px'
  35. },
  36. //是否显示骨架屏
  37. loading: {
  38. type: Boolean,
  39. default: true
  40. },
  41. //标题/段落 圆角风格
  42. round: {
  43. type: Boolean,
  44. default: false
  45. },
  46. //显示段落行数
  47. row: {
  48. type: String,
  49. default: '1'
  50. },
  51. //是否显示段落标题
  52. title: {
  53. type: Boolean,
  54. default: true
  55. }
  56. },
  57. setup(props: any) {
  58. const { avatarShape, round, avatarSize } = toRefs(props);
  59. const avatarClass = computed(() => {
  60. const prefixCls = 'avatarClass';
  61. return {
  62. [prefixCls]: true,
  63. [`${prefixCls}--${avatarShape.value}`]: avatarShape.value
  64. };
  65. });
  66. const blockClass = computed(() => {
  67. const prefixCls = 'blockClass';
  68. return {
  69. [prefixCls]: true,
  70. [`${prefixCls}--round`]: round.value
  71. };
  72. });
  73. const getStyle = (): CSSProperties => {
  74. const style: CSSProperties = {};
  75. if (avatarSize.value) {
  76. return {
  77. width: avatarSize.value,
  78. height: avatarSize.value
  79. };
  80. }
  81. return {
  82. width: '50px',
  83. height: '50px'
  84. };
  85. };
  86. onMounted(() => {
  87. // console.log('row', props.row);
  88. });
  89. return {
  90. avatarShape,
  91. avatarClass,
  92. blockClass,
  93. getStyle
  94. };
  95. }
  96. };