wk-field-input.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="wk-field wk-field-input">
  3. <view v-if="_label" class="wk-field__label">
  4. <view v-if="field.isNull === 1" class="line" />
  5. {{ _label }}
  6. </view>
  7. <view class="wk-field__body" @click="handleClick">
  8. <input
  9. ref="core"
  10. v-model="formValue"
  11. type="text"
  12. :disabled="field.disabled"
  13. :placeholder="_placeholder"
  14. :maxlength="getMaxlength"
  15. placeholder-class="wk-placeholder placeholder"
  16. class="wk-field__body-core"
  17. @input="changeText">
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import mixins from './mixins'
  23. export default {
  24. name: 'WkFieldInput',
  25. mixins: [mixins],
  26. data() {
  27. return {}
  28. },
  29. computed: {
  30. getMaxlength() {
  31. if (this.field.formType === 'website') return 800
  32. return this.field.maxlength || 100
  33. }
  34. },
  35. methods: {
  36. handleClick() {
  37. if (this.field.disabled) {
  38. if (this.config && this.config.disabledMsg) {
  39. this.$toast(this.config.disabledMsg)
  40. }
  41. return
  42. }
  43. },
  44. formatValue(oldStr) {
  45. // 禁止输入 emoji
  46. const regStr = /[\ud800-\udbff]|[\udc00-\udfff]/g;
  47. return oldStr.replace(regStr, '');
  48. },
  49. changeText() {
  50. let oldStr = String(this.formValue)
  51. let valueStr = this.formatValue(this.formValue)
  52. this.formValue = oldStr
  53. this.$nextTick(function() {
  54. this.formValue = valueStr
  55. if (this.value !== this.formValue) {
  56. this.emitChangeEvt(this.formValue)
  57. }
  58. })
  59. }
  60. }
  61. }
  62. </script>
  63. <style scoped lang="scss">
  64. @import './wkField.scss';
  65. .placeholder {
  66. font-size: 26rpx;
  67. }
  68. </style>