graceSearch.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="gui-search" :style="{height:height, backgroundColor:background,borderRadius:borderRadius}">
  3. <view class="gui-search-icon grace-icons icon-search" @tap.stop="tapme"
  4. :style="{color:iconColor, fontSize:iconFontSize, lineHeight:height, width:iconWidth}"></view>
  5. <input type="text" class="gui-search-input" :placeholder="placeholder" v-model="inputVal" v-if="!disabled"
  6. :style="{height:inputHeight, lineHeight:inputHeight, fontSize:inputFontSize, background:background, color:inputColor}"
  7. @input="inputting" @confirm="confirm" confirm-type="search" />
  8. <view class="gui-search-input" v-if="disabled" @tap.stop="tapme"
  9. :style="{height:inputHeight, lineHeight:inputHeight, fontSize:inputFontSize, background:background, color:iconColor}">{{placeholder}}</view>
  10. <view class="gui-search-icon grace-icons icon-close" v-if="inputVal.length > 0" @tap.stop="clearKwd"
  11. :style="{color:iconColor, fontSize:iconFontSize, lineHeight:height, width:iconWidth}"></view>
  12. </view>
  13. </template>
  14. <script>
  15. export default{
  16. props:{
  17. height:{type:String, default:'66rpx'},
  18. background:{type:String, default:'#FFFFFF'},
  19. fontSize:{type:String, default:'28rpx'},
  20. iconWidth:{type:String, default:'60rpx'},
  21. iconColor:{type:String, default:'#A5A7B2'},
  22. iconFontSize:{type:String, default:'30rpx'},
  23. inputHeight:{type:String, default:'30rpx'},
  24. inputFontSize:{type:String, default:'26rpx'},
  25. inputColor:{type:String, default:'#323232'},
  26. placeholder:{type:String, default:'关键字'},
  27. kwd:{type:String, default:''},
  28. borderRadius:{type:String, default:'66rpx'},
  29. disabled:{type:Boolean, default:false}
  30. },
  31. data() {
  32. return {
  33. inputVal : ''
  34. }
  35. },
  36. created: function (){
  37. this.inputVal = this.kwd;
  38. },
  39. watch:{
  40. kwd : function(val, vo){
  41. this.inputVal = val;
  42. }
  43. },
  44. methods:{
  45. clearKwd : function () {
  46. this.inputVal = '';
  47. this.$emit('clear', '');
  48. },
  49. inputting : function(e){
  50. this.$emit('inputting', e.detail.value);
  51. },
  52. confirm : function (e) {
  53. this.$emit('confirm', e.detail.value);
  54. },
  55. tapme : function () {
  56. this.$emit('tapme')
  57. }
  58. }
  59. }
  60. </script>
  61. <style scoped>
  62. .gui-search{border-radius:66rpx; box-sizing:border-box; padding:0 10rpx; display:flex; flex-wrap:nowrap; align-items:center; overflow:hidden; width:100%; box-sizing:border-box;}
  63. .gui-search-icon{text-align:center; flex-shrink:0;}
  64. .gui-search-input{width:100%; margin:0 10rpx; border:none; padding:0;}
  65. </style>