graceSearch.nvue 2.4 KB

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