gui-search.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="gui-flex gui-rows gui-nowrap gui-align-items-center"
  3. :style="{
  4. height:height,
  5. backgroundColor:background,
  6. borderRadius:borderRadius
  7. }">
  8. <text class="gui-search-icon gui-icons gui-block-text gui-text-center" @tap.stop="tapme"
  9. :style="{
  10. color:iconColor,
  11. fontSize:iconFontSize,
  12. lineHeight:height, width:iconWidth
  13. }">&#xe604;</text>
  14. <input
  15. type="text"
  16. :placeholder-class="placeholderClass"
  17. class="gui-search-input gui-flex1"
  18. :placeholder="placeholder"
  19. v-model="inputVal"
  20. v-if="!disabled" :focus="focus"
  21. :style="{
  22. height:inputHeight,
  23. lineHeight:inputHeight,
  24. fontSize:inputFontSize,
  25. color:inputColor
  26. }"
  27. @input="inputting" @confirm="confirm" />
  28. <text class="gui-search-input gui-flex1 gui-block-text"
  29. v-if="disabled" @tap.stop="tapme"
  30. :style="{
  31. height:inputHeight,
  32. lineHeight:inputHeight,
  33. fontSize:inputFontSize,
  34. color:disableColor}">{{placeholder}}</text>
  35. <text class="gui-search-icon gui-icons gui-block-text gui-text-center"
  36. v-if="inputVal.length > 0 && clearBtn" @tap.stop="clearKwd"
  37. :style="{
  38. color:iconColor,
  39. fontSize:iconFontSize,
  40. lineHeight:height,
  41. width:iconWidth}">&#xe78a;</text>
  42. </view>
  43. </template>
  44. <script>
  45. export default{
  46. name : "gui-search",
  47. props : {
  48. height:{type:String, default:'66rpx'},
  49. background:{type:String, default:'#FFFFFF'},
  50. fontSize:{type:String, default:'28rpx'},
  51. iconWidth:{type:String, default:'70rpx'},
  52. iconColor:{type:String, default:'#A5A7B2'},
  53. iconFontSize:{type:String, default:'30rpx'},
  54. inputHeight:{type:String, default:'30rpx'},
  55. inputFontSize:{type:String, default:'26rpx'},
  56. inputColor:{type:String, default:'#323232'},
  57. placeholder:{type:String, default:'关键字'},
  58. placeholderClass:{type:String, default:''},
  59. disableColor:{type:String, default:'#666666'},
  60. kwd:{type:String, default:''},
  61. borderRadius:{type:String, default:'66rpx'},
  62. disabled:{type:Boolean, default:false},
  63. focus:{type:Boolean, default:false},
  64. clearBtn:{type:Boolean, default:true}
  65. },
  66. data() {
  67. return {
  68. inputVal : ''
  69. }
  70. },
  71. created: function (){
  72. this.inputVal = this.kwd;
  73. },
  74. watch:{
  75. kwd : function(val, vo){
  76. this.inputVal = val;
  77. }
  78. },
  79. methods:{
  80. clearKwd : function () {
  81. this.inputVal = '';
  82. this.$emit('clear', '');
  83. },
  84. inputting : function(e){
  85. this.$emit('inputting', e.detail.value);
  86. },
  87. confirm : function (e) {
  88. this.$emit('confirm', e.detail.value);
  89. uni.hideKeyboard();
  90. },
  91. tapme : function () {
  92. this.$emit('tapme')
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped>
  98. .gui-search-input{width:100rpx; margin:0 10rpx; border-width:0rpx; padding:0; background-color:rgba(255,255,255,0);}
  99. </style>