gui-search.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view
  3. class="gui-flex gui-row gui-nowrap gui-align-items-center gui-flex1"
  4. :class="customClass"
  5. :style="{
  6. height:height,
  7. borderRadius:borderRadius
  8. }">
  9. <text
  10. class="gui-icons gui-block gui-text-center gui-color-gray"
  11. @tap.stop="tapme"
  12. :style="{
  13. fontSize:iconFontSize,
  14. lineHeight:height,
  15. width:iconWidth,
  16. marginLeft:'12rpx'
  17. }">&#xe604;</text>
  18. <!-- #ifdef APP-NVUE -->
  19. <input
  20. type="text"
  21. class="gui-search-input gui-flex1 gui-primary-text"
  22. :placeholder="placeholder"
  23. v-model="inputVal"
  24. v-if="!disabled"
  25. :style="{
  26. height:inputHeight,
  27. lineHeight:inputHeight,
  28. fontSize:inputFontSize,
  29. }"
  30. @input="inputting"
  31. @confirm="confirm" />
  32. <!-- #endif -->
  33. <!-- #ifndef APP-NVUE -->
  34. <input
  35. type="text"
  36. :placeholder-class="placeholderClass"
  37. class="gui-search-input gui-flex1 gui-primary-text"
  38. :placeholder="placeholder"
  39. v-model="inputVal"
  40. v-if="!disabled"
  41. :focus="focus"
  42. :style="{
  43. height:inputHeight,
  44. lineHeight:inputHeight,
  45. fontSize:inputFontSize,
  46. }"
  47. @input="inputting"
  48. @confirm="confirm" />
  49. <!-- #endif -->
  50. <text
  51. class="gui-search-input gui-flex1 gui-block gui-color-gray"
  52. v-if="disabled"
  53. @tap.stop="tapme"
  54. :style="{
  55. height:inputHeight,
  56. lineHeight:inputHeight,
  57. fontSize:inputFontSize
  58. }">{{placeholder}}</text>
  59. <text
  60. class="gui-search-icon gui-icons gui-block gui-text-center gui-color-gray"
  61. v-if="inputVal.length > 0 && clearBtn"
  62. @tap.stop="clearKwd"
  63. :style="{
  64. fontSize:iconFontSize,
  65. lineHeight:height,
  66. width:iconWidth,
  67. marginRight:'5rpx'
  68. }">&#xe78a;</text>
  69. </view>
  70. </template>
  71. <script>
  72. export default{
  73. name : "gui-search",
  74. props : {
  75. height:{type:String, default:'66rpx'},
  76. customClass:{type:Array, default:function(){
  77. return ['gui-bg-gray', 'gui-dark-bg-level-3'];
  78. }},
  79. fontSize:{type:String, default:'28rpx'},
  80. iconWidth:{type:String, default:'70rpx'},
  81. iconFontSize:{type:String, default:'30rpx'},
  82. inputHeight:{type:String, default:'30rpx'},
  83. inputFontSize:{type:String, default:'26rpx'},
  84. placeholder:{type:String, default:'关键字'},
  85. placeholderClass:{type:String, default:''},
  86. kwd:{type:String, default:''},
  87. borderRadius:{type:String, default:'66rpx'},
  88. disabled:{type:Boolean, default:false},
  89. focus:{type:Boolean, default:false},
  90. clearBtn:{type:Boolean, default:true}
  91. },
  92. data() {
  93. return {
  94. inputVal : ''
  95. }
  96. },
  97. created: function (){
  98. this.inputVal = this.kwd;
  99. },
  100. watch:{
  101. kwd : function(val, vo){
  102. this.inputVal = val;
  103. }
  104. },
  105. methods:{
  106. clearKwd : function () {
  107. this.inputVal = '';
  108. this.$emit('clear', '');
  109. },
  110. inputting : function(e){
  111. this.$emit('inputting', e.detail.value);
  112. },
  113. confirm : function (e) {
  114. this.$emit('confirm', e.detail.value);
  115. uni.hideKeyboard();
  116. },
  117. tapme : function () {
  118. this.$emit('tapme')
  119. }
  120. },
  121. emits : ['clear', 'confirm', 'tapme', 'inputting']
  122. }
  123. </script>
  124. <style scoped>
  125. .gui-search-input{width:100rpx; border-width:0rpx; padding:0; background-color:rgba(255,255,255,0);}
  126. </style>