index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-rate v-model="value" :count="count" @change="change"
  7. :active-color="activeColor" :inaction-color="inactiveColor"
  8. :active-icon="activeIcon" :inactive-icon="inactiveIcon"
  9. :disabled="disabled" :colors="colors" :icons="icons"></u-rate>
  10. </view>
  11. </view>
  12. <view class="u-config-wrap">
  13. <view class="u-config-title u-border-bottom">
  14. 参数配置
  15. </view>
  16. <view class="u-config-item">
  17. <view class="u-item-title">初始值</view>
  18. <u-subsection :list="[1, 2, 3, 4]" @change="currentChange"></u-subsection>
  19. </view>
  20. <view class="u-config-item">
  21. <view class="u-item-title">镂空状态</view>
  22. <u-subsection current="1" :list="['是', '否']" @change="plainChange"></u-subsection>
  23. </view>
  24. <view class="u-config-item">
  25. <view class="u-item-title">自定义样式</view>
  26. <u-subsection current="1" :list="['是', '否']" @change="styleChange"></u-subsection>
  27. </view>
  28. <view class="u-config-item">
  29. <view class="u-item-title">自定义图标</view>
  30. <u-subsection current="1" :list="['是', '否']" @change="iconChange"></u-subsection>
  31. </view>
  32. <view class="u-config-item">
  33. <view class="u-item-title">是否分层</view>
  34. <u-subsection current="1" :list="['是', '否']" @change="decimalChange"></u-subsection>
  35. </view>
  36. <view class="u-config-item">
  37. <view class="u-item-title">是否禁用</view>
  38. <u-subsection current="1" :list="['是', '否']" @change="disabledChange"></u-subsection>
  39. </view>
  40. <view class="u-config-item">
  41. <view class="u-item-title">星星数量</view>
  42. <u-subsection current="1" :list="[4, 5, 6]" @change="countChange"></u-subsection>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. data() {
  50. return {
  51. // 1.4.5后推荐使用v-model双向绑定,弃用current
  52. // current: 1,
  53. activeColor: '#FA3534',
  54. inactiveColor: '#b2b2b2',
  55. disabled: false,
  56. count: 5,
  57. customIcon: false,
  58. plain: false,
  59. value: 0,
  60. colors: [],
  61. icons: []
  62. }
  63. },
  64. watch: {
  65. value(n) {
  66. // console.log(n);
  67. }
  68. },
  69. computed: {
  70. activeIcon() {
  71. let icon = this.customIcon ? 'heart' : 'star';
  72. return this.plain ? icon : icon + '-fill'
  73. },
  74. inactiveIcon() {
  75. let icon = this.customIcon ? 'heart' : 'star';
  76. return this.plain ? icon : icon + '-fill'
  77. }
  78. },
  79. methods: {
  80. currentChange(index) {
  81. this.value = index == 0 ? 1 : index == 1 ? 2 : index == 2 ? 3 : 4;
  82. },
  83. plainChange(index) {
  84. this.plain = !index;
  85. },
  86. disabledChange(index) {
  87. this.disabled = index == 0 ? true : false;
  88. },
  89. countChange(index) {
  90. this.count = index == 0 ? 4 : index == 1 ? 5 : 6;
  91. },
  92. styleChange(index) {
  93. if(index == 0) {
  94. this.activeColor = this.$u.color['primary'];
  95. this.inactiveColor = this.$u.color['info'];
  96. } else {
  97. this.activeColor = '#FA3534';
  98. this.inactiveColor = '#b2b2b2';
  99. }
  100. },
  101. decimalChange(index) {
  102. if(index == 0) {
  103. this.colors = ['#ffc454', '#ffb409', '#ff9500'];
  104. this.icons = ['thumb-down-fill', 'thumb-down-fill', 'thumb-up-fill', 'thumb-up-fill'];
  105. } else {
  106. this.colors = [];
  107. this.icons = [];
  108. }
  109. },
  110. iconChange(index) {
  111. this.customIcon = !index;
  112. },
  113. change(val) {
  114. // console.log(val);
  115. }
  116. }
  117. }
  118. </script>
  119. <style scoped lang="scss">
  120. .u-demo {}
  121. </style>