input.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view>
  3. <view class="cu-form-group" :class=" formItem.topLine ? 'top-line': '' ">
  4. <view class="title">{{ interceptNum(formItem.label, 0, 6) }}
  5. <text class="red opacity0" :class="formItem.requied ? 'opacity1' : ''">*</text>
  6. </view>
  7. <input :type="formItem.inputType? formItem.inputType: 'text'"
  8. :disabled="formItem.disabled" :value="formItem.value" :password="formItem.password"
  9. bindinput="inputChange" :maxlength="formItem.maxLen ? formItem.maxLen: '40'"
  10. :placeholder="formItem.placeholder ? formItem.placeholder : formItem.noPlaceholder ? '' : '请输入' +interceptNum(formItem.label, 0 ,6)"
  11. placeholder-class="placeholderinput">
  12. </input>
  13. <!-- <text if="formItem.icon"
  14. class="{{formItem.icon}} {{formItem.icon && formItem.iconColor ? formItem.iconColor : 'text-orange'}}">
  15. </text> -->
  16. <!-- 按钮 -->
  17. <!-- <button if="formItem.BtnText"
  18. class="cu-btn shadow {{formItem.BtnText && formItem.BtnBgCol ? formItem.BtnBgCol : 'bg-green'}}">{{ formItem.BtnText }}
  19. </button> -->
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { getPrepPage } from './common'
  25. export default {
  26. props: {
  27. /**
  28. * 当且仅当 type === 'input' 显示该组件
  29. *
  30. * ---参数说明---
  31. * topLine 默认没有上划线,可加
  32. * clearBottomLine 默认有下划线,可删
  33. * label 输入框标题(最大长度为6,溢出隐藏)
  34. * requied 是否必填(显示红星)
  35. * inputType input框的类型,默认text
  36. * disabled 是否禁用
  37. * value input值
  38. * password 是否是密码类型,默认为否
  39. * maxLen input框最大长度,默认40
  40. * placeholder + noPlaceholder 默认为“‘请输入’ + 输入框标题(label)” 通过placeholder可自定义
  41. * 也可通过noPlaceholder 来清除默认placeholder
  42. * icon input框右侧是否添加icon(color UI: 如:"cuIcon-locationfill",colorUI的图标)
  43. * iconColor icon颜色,默认橘色 "text-orange"
  44. * BtnText 加按钮的文本(最多四字,溢出隐藏)
  45. * BtnBgCol 按钮的背景色
  46. * rule + message 结合“WxValidate.js” 验证输入文本是否符合规则
  47. *
  48. */
  49. formItem: {
  50. type: Object,
  51. default: {}
  52. },
  53. index: {
  54. type: Number
  55. },
  56. },
  57. data() {
  58. return {
  59. }
  60. },
  61. methods: {
  62. interceptNum: function (str, start, end) {
  63. if (str != null) {
  64. return str.slice(start, end);
  65. }
  66. },
  67. inputChange: function (e) {
  68. const index = e.currentTarget.dataset.key;
  69. const value = e.detail.value;
  70. this.formItem = value;
  71. this.setData({ formItem });
  72. getPrepPage().setData({ ['form[' + index + ']']: formItem });
  73. }
  74. }
  75. }
  76. </script>
  77. <style scoped>
  78. .red {
  79. color: red;
  80. margin-left: 4rpx;
  81. }
  82. .cu-form-group .cu-btn {
  83. width: 180rpx;
  84. }
  85. .cu-form-group .title {
  86. padding-right: 10rpx;
  87. min-width: calc(4em + 50rpx);
  88. max-width: calc(6em + 50rpx);
  89. overflow: hidden;
  90. }
  91. .placeholderinput {
  92. color: #aaa;
  93. font-size: 28rpx;
  94. }
  95. .top-line {
  96. border-top: 1rpx solid #eee;
  97. }
  98. .bottom-line {
  99. border-bottom: 1rpx solid #eee;
  100. }
  101. .opacity0 {
  102. opacity: 0;
  103. }
  104. .opacity1 {
  105. opacity: 1;
  106. }
  107. </style>