props.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { defineProps } from '../../libs/util/props';
  2. export default defineProps('avatar', {
  3. // 头像图片路径(不能为相对路径)
  4. src: {
  5. type: String,
  6. default: ''
  7. },
  8. // 头像形状,circle-圆形,square-方形
  9. shape: {
  10. type: String,
  11. default: 'circle'
  12. },
  13. // 头像尺寸
  14. size: {
  15. type: [String, Number],
  16. default: 40
  17. },
  18. // 裁剪模式
  19. mode: {
  20. type: String,
  21. default: 'scaleToFill'
  22. },
  23. // 显示的文字
  24. text: {
  25. type: String,
  26. default: ''
  27. },
  28. // 背景色
  29. bgColor: {
  30. type: String,
  31. default: '#c0c4cc'
  32. },
  33. // 文字颜色
  34. color: {
  35. type: String,
  36. default: '#ffffff'
  37. },
  38. // 文字大小
  39. fontSize: {
  40. type: [String, Number],
  41. default: 18
  42. },
  43. // 显示的图标
  44. icon: {
  45. type: String,
  46. default: ''
  47. },
  48. // 显示小程序头像,只对百度,微信,QQ小程序有效
  49. mpAvatar: {
  50. type: Boolean,
  51. default: false
  52. },
  53. // 是否使用随机背景色
  54. randomBgColor: {
  55. type: Boolean,
  56. default: false
  57. },
  58. // 加载失败的默认头像(组件有内置默认图片)
  59. defaultUrl: {
  60. type: String,
  61. default: ''
  62. },
  63. // 如果配置了randomBgColor为true,且配置了此值,则从默认的背景色数组中取出对应索引的颜色值,取值0-19之间
  64. colorIndex: {
  65. type: [String, Number],
  66. // 校验参数规则,索引在0-19之间
  67. validator(n) {
  68. return uni.$u.test.range(n, [0, 19]) || n === ''
  69. },
  70. default: ''
  71. },
  72. // 组件标识符
  73. name: {
  74. type: String,
  75. default: ''
  76. }
  77. })