u--input.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <uvInput
  3. <!-- #ifdef VUE2 -->
  4. :value="value"
  5. @input="e => $emit('input', e)"
  6. <!-- #endif -->
  7. <!-- #ifdef VUE3 -->
  8. :modelValue="modelValue"
  9. @update:modelValue="e => $emit('update:modelValue', e)"
  10. <!-- #endif -->
  11. :type="type"
  12. :fixed="fixed"
  13. :disabled="disabled"
  14. :disabledColor="disabledColor"
  15. :clearable="clearable"
  16. :password="password"
  17. :maxlength="maxlength"
  18. :placeholder="placeholder"
  19. :placeholderClass="placeholderClass"
  20. :placeholderStyle="placeholderStyle"
  21. :confirmType="confirmType"
  22. :confirmHold="confirmHold"
  23. :holdKeyboard="holdKeyboard"
  24. :focus="focus"
  25. :autoBlur="autoBlur"
  26. :disableDefaultPadding="disableDefaultPadding"
  27. :alwaysEmbed="alwaysEmbed"
  28. :cursor="cursor"
  29. :cursorSpacing="cursorSpacing"
  30. :selectionStart="selectionStart"
  31. :selectionEnd="selectionEnd"
  32. :adjustPosition="adjustPosition"
  33. :inputAlign="inputAlign"
  34. :fontSize="fontSize"
  35. :color="color"
  36. :backgroundColor="backgroundColor"
  37. :round="round"
  38. :borderColor="borderColor"
  39. :prefixIcon="prefixIcon"
  40. :suffixIcon="suffixIcon"
  41. :suffixIconStyle="suffixIconStyle"
  42. :prefixIconStyle="prefixIconStyle"
  43. :border="border"
  44. :readonly="readonly"
  45. :shape="shape"
  46. :customStyle="customStyle"
  47. :formatter="formatter"
  48. :ignoreCompositionEvent="ignoreCompositionEvent"
  49. @focus="e => $emit('focus', e)"
  50. @blur="e => $emit('blur', e)"
  51. @keyboardheightchange="e => $emit('keyboardheightchange', e)"
  52. @change="e => $emit('change', e)"
  53. @confirm="e => $emit('confirm', e)"
  54. @clear="$emit('clear')"
  55. @click="$emit('click')"
  56. >
  57. <!-- #ifdef MP -->
  58. <slot name="prefix"></slot>
  59. <slot name="suffix"></slot>
  60. <!-- #endif -->
  61. <!-- #ifndef MP -->
  62. <slot name="prefix" slot="prefix"></slot>
  63. <slot name="suffix" slot="suffix"></slot>
  64. <!-- #endif -->
  65. </uvInput>
  66. </template>
  67. <script>
  68. /**
  69. * 此组件存在的理由是,在nvue下,u-input被uni-app官方占用了,u-input在nvue中相当于input组件
  70. * 所以在nvue下,取名为u--input,内部其实还是u-input.vue,只不过做一层中转
  71. */
  72. import uvInput from '../u-input/u-input.vue';
  73. import props from '../u-input/props.js'
  74. import mixin from '../../libs/mixin/mixin'
  75. import mpMixin from '../../libs/mixin/mpMixin'
  76. /**
  77. * Input 输入框
  78. * @description 此组件为一个输入框,默认没有边框和样式,是专门为配合表单组件u-form而设计的,利用它可以快速实现表单验证,输入内容,下拉选择等功能。
  79. * @tutorial https://uviewui.com/components/input.html
  80. * @property {String | Number} value 输入的值
  81. * @property {String} type 输入框类型,见上方说明 ( 默认 'text' )
  82. * @property {Boolean} fixed 如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true,兼容性:微信小程序、百度小程序、字节跳动小程序、QQ小程序 ( 默认 false )
  83. * @property {Boolean} disabled 是否禁用输入框 ( 默认 false )
  84. * @property {String} disabledColor 禁用状态时的背景色( 默认 '#f5f7fa' )
  85. * @property {Boolean} clearable 是否显示清除控件 ( 默认 false )
  86. * @property {Boolean} password 是否密码类型 ( 默认 false )
  87. * @property {String | Number} maxlength 最大输入长度,设置为 -1 的时候不限制最大长度 ( 默认 -1 )
  88. * @property {String} placeholder 输入框为空时的占位符
  89. * @property {String} placeholderClass 指定placeholder的样式类,注意页面或组件的style中写了scoped时,需要在类名前写/deep/ ( 默认 'input-placeholder' )
  90. * @property {String | Object} placeholderStyle 指定placeholder的样式,字符串/对象形式,如"color: red;"
  91. * @property {String} confirmType 设置右下角按钮的文字,兼容性详见uni-app文档 ( 默认 'done' )
  92. * @property {Boolean} confirmHold 点击键盘右下角按钮时是否保持键盘不收起,H5无效 ( 默认 false )
  93. * @property {Boolean} holdKeyboard focus时,点击页面的时候不收起键盘,微信小程序有效 ( 默认 false )
  94. * @property {Boolean} focus 自动获取焦点,在 H5 平台能否聚焦以及软键盘是否跟随弹出,取决于当前浏览器本身的实现。nvue 页面不支持,需使用组件的 focus()、blur() 方法控制焦点 ( 默认 false )
  95. * @property {Boolean} autoBlur 键盘收起时,是否自动失去焦点,目前仅App3.0.0+有效 ( 默认 false )
  96. * @property {Boolean} disableDefaultPadding 是否去掉 iOS 下的默认内边距,仅微信小程序,且type=textarea时有效 ( 默认 false )
  97. * @property {String | Number} cursor 指定focus时光标的位置( 默认 -1 )
  98. * @property {String | Number} cursorSpacing 输入框聚焦时底部与键盘的距离 ( 默认 30 )
  99. * @property {String | Number} selectionStart 光标起始位置,自动聚集时有效,需与selection-end搭配使用 ( 默认 -1 )
  100. * @property {String | Number} selectionEnd 光标结束位置,自动聚集时有效,需与selection-start搭配使用 ( 默认 -1 )
  101. * @property {Boolean} adjustPosition 键盘弹起时,是否自动上推页面 ( 默认 true )
  102. * @property {String} inputAlign 输入框内容对齐方式( 默认 'left' )
  103. * @property {String | Number} fontSize 输入框字体的大小 ( 默认 '15px' )
  104. * @property {String} color 输入框字体颜色 ( 默认 '#303133' )
  105. * @property {Function} formatter 内容式化函数
  106. * @property {String} prefixIcon 输入框前置图标
  107. * @property {String | Object} prefixIconStyle 前置图标样式,对象或字符串
  108. * @property {String} suffixIcon 输入框后置图标
  109. * @property {String | Object} suffixIconStyle 后置图标样式,对象或字符串
  110. * @property {String} border 边框类型,surround-四周边框,bottom-底部边框,none-无边框 ( 默认 'surround' )
  111. * @property {Boolean} readonly 是否只读,与disabled不同之处在于disabled会置灰组件,而readonly则不会 ( 默认 false )
  112. * @property {String} shape 输入框形状,circle-圆形,square-方形 ( 默认 'square' )
  113. * @property {Object} customStyle 定义需要用到的外部样式
  114. * @property {Boolean} ignoreCompositionEvent 是否忽略组件内对文本合成系统事件的处理。
  115. * @example <u--input v-model="value" :password="true" suffix-icon="lock-fill" />
  116. */
  117. export default {
  118. name: 'u--input',
  119. mixins: [mpMixin, mixin, props],
  120. components: {
  121. uvInput
  122. },
  123. }
  124. </script>