index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="u-demo">
  3. <view class="u-demo-wrap">
  4. <view class="u-demo-title">演示效果</view>
  5. <view class="u-demo-area">
  6. <u-avatar
  7. :mode="mode"
  8. :size="size"
  9. :src="src"
  10. :text="text"
  11. :showLevel="showLevel"
  12. :showSex="showSex"
  13. :sexIcon="sexIcon"
  14. :bgColor='bgColor'
  15. ></u-avatar>
  16. </view>
  17. </view>
  18. <view class="u-config-wrap">
  19. <view class="u-config-title u-border-bottom">
  20. 参数配置
  21. </view>
  22. <view class="u-config-item">
  23. <view class="u-item-title">模式选择</view>
  24. <u-subsection :list="['圆形', '圆角方形']" @change="modeChange"></u-subsection>
  25. </view>
  26. <view class="u-config-item">
  27. <view class="u-item-title">性别选择</view>
  28. <u-subsection :list="['男', '女', '不显示']" @change="sexChange"></u-subsection>
  29. </view>
  30. <view class="u-config-item">
  31. <view class="u-item-title">等级</view>
  32. <u-subsection :list="['显示', '不显示']" @change="levelChange"></u-subsection>
  33. </view>
  34. <view class="u-config-item">
  35. <view class="u-item-title">自定义内容</view>
  36. <u-subsection current="0" :list="['图片', '文字']" @change="styleChange"></u-subsection>
  37. </view>
  38. <view class="u-config-item">
  39. <view class="u-item-title">尺寸</view>
  40. <u-subsection current="1" :list="['large', 'default', 'mini', 160]" @change="sizeChange"></u-subsection>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. mode: 'circle',
  50. src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
  51. text: '', // 优先级比src高
  52. size: '90',
  53. showLevel: true,
  54. showSex: true,
  55. sexIcon: 'man',
  56. bgColor: '#fcbd71'
  57. }
  58. },
  59. methods: {
  60. modeChange(index) {
  61. this.mode = index == 0 ? 'circle' : 'square';
  62. },
  63. styleChange(index) {
  64. if(index == 0) {
  65. this.text = '';
  66. this.src = 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg';
  67. } else {
  68. this.text = '无头像';
  69. }
  70. },
  71. sizeChange(index) {
  72. this.size = index == 0 ? 'large' : index == 1 ? 'default' : index == 2 ? 'mini' : 160;
  73. },
  74. sexChange(index) {
  75. this.showSex = true;
  76. if(index == 0) this.sexIcon = 'man';
  77. if(index == 1) this.sexIcon = 'woman';
  78. if(index == 2) this.showSex = false;
  79. },
  80. levelChange(index) {
  81. this.showLevel = !index;
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. </style>