org-input-text.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="org-input-text">
  3. <view class="org-input-text-info" :style="{'border-radius':borderRadius}">
  4. <view v-if="$slots.left">
  5. <slot name="left"></slot>
  6. </view>
  7. <view class="left-info" v-if="leftText&&!$slots.left" :style="{'font-size':fontSize+'px','background-color':labeBg,'padding':padding}">
  8. {{leftText}}
  9. </view>
  10. <view v-if="$slots.content" class="content" :style="{'padding':padding}">
  11. <slot name="content"></slot>
  12. </view>
  13. <view class="content" v-if="!$slots.content&&placeholder" :style="{'padding':padding}">
  14. <input type="text" :maxlength="140" :password="isShowPass" v-model="inputText" :placeholder="placeholder"
  15. :placeholder-style="'color:'+placeholderColor+';font-size:'+(fontSize-2)+'px;'" :style="{'font-size':fontSize+'px'}"
  16. @input="changeInput" @blur="changeInput" @focus="changeInput" @confirm="changeInput" />
  17. </view>
  18. <view v-if="$slots.right">
  19. <slot name="right"></slot>
  20. </view>
  21. <view v-if="isPassword" @tap="isShowPass=!isShowPass" class="red-pass" :style="{'padding':padding,'padding-left':'10rpx'}">
  22. <uni-icons type="eye" :color="btnColor" :size="fontSize"></uni-icons>
  23. </view>
  24. <view class="clear-btn" v-if="showClear" @tap="clear" :style="{'padding':padding}">
  25. <uni-icons type="clear" :color="btnColor" :size="fontSize"></uni-icons>
  26. </view>
  27. <view class="status" @tap="getMsg" :style="{'padding':padding,'padding-left':'10rpx'}">
  28. <uni-icons :type="!isTrue?'clear':'checkbox-filled'" :color="!isTrue?'red':'#20a97e'" :size="fontSize"></uni-icons>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import uniIcons from '../../components/uni-icons/uni-icons';
  35. export default {
  36. data() {
  37. return {
  38. inputText: this.value,
  39. isTrue: false,
  40. isShowPass: this.isPassword,
  41. msg: this.leftText+'不能为空!'
  42. }
  43. },
  44. components: {
  45. uniIcons
  46. },
  47. props: {
  48. /**
  49. * 输入问题不提示文字,
  50. */
  51. leftText: {
  52. type: String,
  53. default: '标题标题'
  54. },
  55. /**
  56. * 是否显示清除按钮,
  57. */
  58. showClear: {
  59. type: Boolean,
  60. default: true
  61. },
  62. /**
  63. * 默认提示占位信息
  64. */
  65. placeholder: {
  66. type: String,
  67. default: '请输入信息...'
  68. },
  69. /**
  70. * 提示文字颜色
  71. */
  72. placeholderColor: {
  73. type: String,
  74. default: '#cccccc'
  75. },
  76. /**
  77. * 字体大小
  78. */
  79. fontSize: {
  80. type: Number,
  81. default: 20
  82. },
  83. /**
  84. * 左侧提示文字颜色
  85. */
  86. labeBg: {
  87. type: String,
  88. default: '#dedede'
  89. },
  90. /**
  91. * 按钮默认颜色
  92. */
  93. btnColor: {
  94. type: String,
  95. default: '#dedede'
  96. },
  97. /**
  98. * 是否是密码框
  99. */
  100. isPassword: {
  101. type: Boolean,
  102. default: false
  103. },
  104. /**
  105. * 最大长度
  106. */
  107. maxLength: {
  108. type: Number,
  109. default: 140
  110. },
  111. /**
  112. * 边框圆角
  113. */
  114. borderRadius:{
  115. type: String,
  116. default: '20rpx'
  117. },
  118. /**
  119. * 默认初始值
  120. */
  121. value:{
  122. type: String,
  123. default: ''
  124. },
  125. /**
  126. * 校验信息
  127. */
  128. checkInfo: {
  129. type: Object,
  130. default: function() {
  131. return {
  132. msg: '请输入6-12位字符',
  133. reg: '^.{6,12}$',
  134. required: true
  135. }
  136. }
  137. },
  138. /**
  139. * 中间文本框边距
  140. */
  141. padding: {
  142. type: String,
  143. default: '20rpx'
  144. }
  145. },
  146. methods: {
  147. clear() {
  148. this.inputText = "";
  149. this.$emit("clear");
  150. this.changeInput();
  151. },
  152. changeInput() {
  153. var text = this.inputText;
  154. if (this.checkInfo.required == true || this.checkInfo.required === undefined) {
  155. if (text.length <= 0) {
  156. this.isTrue = false;
  157. this.msg = this.leftText + "不能为空,请输入!"
  158. return;
  159. }
  160. }
  161. let reg = new RegExp(this.checkInfo.reg);
  162. if (!reg.test(text)) {
  163. this.msg = this.leftText + this.checkInfo.msg;
  164. this.isTrue = false;
  165. return;
  166. }
  167. this.msg = "验证通过!";
  168. this.isTrue = true;
  169. this.$emit("input", this.inputText);
  170. },
  171. getMsg() {
  172. uni.showToast({
  173. icon: "none",
  174. title: this.msg
  175. });
  176. }
  177. }
  178. ,created() {
  179. setTimeout(()=>{
  180. this.changeInput()
  181. },200);
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .org-input-text {
  187. width: 100%;
  188. box-sizing: border-box;
  189. margin-top: 20rpx;
  190. .org-input-text-info {
  191. border-radius: 20rpx;
  192. border: 1px solid rgba(215, 215, 215, 1);
  193. line-height: 60rpx;
  194. display: flex;
  195. justify-content: space-between;
  196. font-size: 32rpx;
  197. overflow: hidden;
  198. .left-info {
  199. flex-direction: column;
  200. flex: 2;
  201. padding: 20rpx;
  202. color: #AAAAAA;
  203. flex-basis:250rpx;
  204. // min-width: 80rpx;
  205. background-color: #dedede;
  206. text-align: right;
  207. }
  208. .content {
  209. flex-grow: 1;
  210. // width: 100%;
  211. padding: 20rpx;
  212. }
  213. .clear-btn {
  214. padding: 20rpx;
  215. }
  216. .status {
  217. padding: 20rpx;
  218. }
  219. .red-pass {
  220. padding: 20rpx;
  221. }
  222. }
  223. }
  224. </style>