tm-search.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="tm-search fulled py-12"
  3. :class="[
  4. black_tmeme?'grey-darken-5':bgColor,
  5. `shadow-${shadow}`
  6. ]"
  7. >
  8. <view @click="$emit('click')" class="tm-search-body flex-around">
  9. <view v-if="showLeft" class="flex-shrink pl-32 flex-center">
  10. <slot name="left">
  11. <tm-icons @click="$emit('cancel')" :black="black_tmeme" :color="color_tmeme" dense :name="leftIcon"></tm-icons>
  12. </slot>
  13. </view>
  14. <view class="flex-between fulled py-10 mx-32" :class="[
  15. black_tmeme?' grey-darken-5':'grey-lighten-4',
  16. `round-${round}`
  17. ]">
  18. <view v-if="prefixText" class="px-16 flex-shrink flex-center text-size-n text-grey">
  19. {{prefixText}}
  20. </view>
  21. <view v-if="prefixIcon" class="pl-16 flex-shrink flex-center">
  22. <tm-icons :black="black_tmeme" :color="insertColor_thmeme" dense :name="prefixIcon"></tm-icons>
  23. </view>
  24. <input @focus="$emit('focus',$event)" @blur="$emit('blur',$event)" confirm-type="search" type="search" @confirm="confirm" v-model="valData" :disabled="disabled" :placeholder="placeholder" class="flat fulled text-size-n pl-16 py-4 tm-search-body-searc" :class="[`text-align-${align}`]" />
  25. <view v-if="clear&&valData.length>0" class="px-16 flex-shrink flex-center">
  26. <tm-icons @click="valData='';$emit('clear',valData)" :size="24" :black="black_tmeme" :color="insertColor_thmeme" dense name="icon-times"></tm-icons>
  27. </view>
  28. <view v-if="suffixIcon" class="px-16 flex-shrink flex-center">
  29. <slot name="suffixIcon">
  30. <tm-icons @click="confirm" :black="black_tmeme" :color="insertColor_thmeme" dense :name="suffixIcon"></tm-icons>
  31. </slot>
  32. </view>
  33. </view>
  34. <view @click="confirm" v-if="showRight" class="flex-shrink mr-32 text-size-n" :class="[
  35. `text-${color_tmeme}`
  36. ]">
  37. <slot name="right">
  38. <text class="text-size-n">{{confirmText}}</text>
  39. </slot>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. /**
  46. * 搜索框
  47. * @property {String} value = [] 默认:'',建议valu.sync或者v-model双向绑定输入的词。
  48. * @property {Boolean} disabled = [true|false] 默认:false,是否禁用。
  49. * @property {String} left-icon = [] 默认:icon-angle-left,左边图标名称。
  50. * @property {String} prefix-text = [] 默认:'',输入框内前缀文字。
  51. * @property {String} prefix-icon = [] 默认:'icon-search',输入框内前缀图标。
  52. * @property {String} insert-color = [] 默认:'primary',输入框内图标的主题色。
  53. * @property {String} suffix-icon = [] 默认:'',输入框内后缀图标。
  54. * @property {Boolean} show-left = [true|false] 默认:false,是否显示左边部分
  55. * @property {String} confirm-text = [] 默认:搜索, 右边文字
  56. * @property {Boolean} show-right = [] 默认:true ,是否显示右边
  57. * @property {String} color = [] 默认:primary , 外部图标文字的主题色。
  58. * @property {String} bg-color = [] 默认:white , 搜索框的背景。
  59. * @property {Boolean} black = [true|false] 默认:null , 是否暗黑模式
  60. * @property {Boolean} clear = [true|false] 默认:false , 是否显示清除图标
  61. * @property {Number} round = [] 默认:2 , 输入框内圆角。
  62. * @property {Number} shadow = [] 默认:2 , 搜索框的投影
  63. * @property {String} placeholder = [] 默认:'请输入关键词' , 输入框的点位符
  64. * @property {String} align = [left|right|center] 默认:'left' , 输入框输入对齐的方式。
  65. * @property {Function} cancel 点击左边图标产生的事件。
  66. * @property {Function} clear 点击清除图标时触发相关事件。
  67. * @property {Function} confirm 输入法键盘上点击确认,输入框后缀图标,右边部分点击时产生的事件,含当前输入的内容。
  68. * @property {Function} click 点击整体组件的事件。
  69. */
  70. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  71. export default {
  72. components:{tmIcons},
  73. name:"tm-search",
  74. model:{
  75. prop:'value',
  76. event:'input'
  77. },
  78. props:{
  79. clear:{
  80. type:Boolean,
  81. default:false
  82. },
  83. value:{
  84. type:String,
  85. default:''
  86. },
  87. disabled:{
  88. type:Boolean|String,
  89. default:false
  90. },
  91. leftIcon:{
  92. type:String,
  93. default:'icon-angle-left'
  94. },
  95. // 输入框内的前缀文字
  96. prefixText:{
  97. type:String,
  98. default:''
  99. },
  100. //输入框内的前缀图标。
  101. prefixIcon:{
  102. type:String,
  103. default:'icon-search'
  104. },
  105. // 输入框内部主题
  106. insertColor:{
  107. type:String,
  108. default:'primary'
  109. },
  110. //输入框内的后缀图标。
  111. suffixIcon:{
  112. type:String,
  113. default:''
  114. },
  115. showLeft:{
  116. type:Boolean,
  117. default:false
  118. },
  119. confirmText:{
  120. type:String,
  121. default:'搜索'
  122. },
  123. showRight:{
  124. type:Boolean,
  125. default:true
  126. },
  127. color:{
  128. type:String,
  129. default:'primary'
  130. },
  131. bgColor:{
  132. type:String,
  133. default:'white'
  134. },
  135. black:{
  136. type:Boolean|String,
  137. default:null
  138. },
  139. round:{
  140. type:Number,
  141. default:2
  142. },
  143. shadow:{
  144. type:Number,
  145. default:4
  146. },
  147. placeholder:{
  148. type:String,
  149. default:"请输入"
  150. },
  151. align:{
  152. type:String,
  153. default:'left' //left|right|center
  154. },
  155. // 跟随主题色的改变而改变。
  156. fllowTheme:{
  157. type:Boolean|String,
  158. default:true
  159. }
  160. },
  161. computed:{
  162. black_tmeme: function() {
  163. if (this.black !== null) return this.black;
  164. return this.$tm.vx.state().tmVuetify.black;
  165. },
  166. color_tmeme:function(){
  167. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  168. return this.$tm.vx.state().tmVuetify.color;
  169. }
  170. return this.color;
  171. },
  172. insertColor_thmeme:function(){
  173. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  174. return this.$tm.vx.state().tmVuetify.color;
  175. }
  176. return this.insertColor;
  177. },
  178. valData:{
  179. get:function(){
  180. return this.value;
  181. },
  182. set:function(val){
  183. this.$emit('input',val)
  184. }
  185. }
  186. },
  187. data() {
  188. return {
  189. };
  190. },
  191. methods: {
  192. confirm(e) {
  193. this.$emit('confirm',this.value)
  194. }
  195. },
  196. }
  197. </script>
  198. <style lang="scss" scoped>
  199. .tm-search-body-searc{
  200. -webkit-appearance: none !important;
  201. }
  202. </style>