Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

115 wiersze
2.3 KiB

  1. <style scoped lang="scss">
  2. .up-choose {
  3. ::v-deep .up-tag {
  4. font-weight: 600;
  5. }
  6. &:last-child {
  7. margin-right: 0;
  8. }
  9. }
  10. .up-choose-wrap {
  11. flex-wrap: wrap;
  12. }
  13. .up-choose-nowrap {
  14. flex-wrap: nowrap;
  15. white-space: nowrap;
  16. }
  17. </style>
  18. <template>
  19. <scroll-view
  20. :scroll-x="wrap === false"
  21. :class="['up-choose', wrap ? 'up-choose-wrap' : 'up-choose-nowrap']">
  22. <template :key="item.id" v-for="(item,index) in options">
  23. <view :style="{width: itemWidth, display: 'inline-block'}">
  24. <slot :item="item" :index="index">
  25. <up-tag :type="index == currentIndex ? 'primary' : 'info'"
  26. size="large" :plain="index == currentIndex ? false : true"
  27. :class="currentIndex === index ? 'active': ''" :height="itemHeight"
  28. :style="{width: itemWidth, padding: itemPadding}"
  29. @click="change(index)">
  30. {{item[labelName]}}
  31. </up-tag>
  32. </slot>
  33. </view>
  34. </template>
  35. </scroll-view>
  36. </template>
  37. <script>
  38. export default {
  39. name: 'up-choose',
  40. props: {
  41. options:{
  42. type: Array,
  43. default: ()=>{
  44. return [];
  45. }
  46. },
  47. modelValue: {
  48. type: [Number,String,Array],
  49. default: false
  50. },
  51. type: {
  52. type: [String],
  53. default: 'radio'
  54. },
  55. itemWidth: {
  56. type: [String],
  57. default: 'auto'
  58. },
  59. itemHeight: {
  60. type: [String],
  61. default: '50px'
  62. },
  63. itemPadding: {
  64. type: [String],
  65. default: '8px'
  66. },
  67. labelName: {
  68. type: String,
  69. default: 'title'
  70. },
  71. valueName: {
  72. type: String,
  73. default: 'value'
  74. },
  75. customClick: {
  76. type: Boolean,
  77. default: false
  78. },
  79. // 是否换行
  80. wrap: {
  81. type: Boolean,
  82. default: true
  83. }
  84. },
  85. data() {
  86. return {
  87. currentIndex: ''
  88. }
  89. },
  90. watch: {
  91. modelValue: {
  92. immediate: true,
  93. handler(newVal) {
  94. this.currentIndex = newVal
  95. }
  96. }
  97. },
  98. emits: ['update:modelValue', 'custom-click'],
  99. methods: {
  100. change(index){
  101. if (this.customClick) {
  102. this.$emit('custom-click', index);
  103. } else {
  104. this.currentIndex = index;
  105. this.$emit('update:modelValue', index);
  106. }
  107. }
  108. }
  109. }
  110. </script>