wk-field-textarea.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="wk-field wk-field-textarea">
  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. <textarea
  9. ref="core"
  10. v-model="formValue"
  11. :type="type"
  12. :placeholder="_placeholder"
  13. :maxlength="getMaxlength"
  14. :disabled="field.disabled"
  15. placeholder-style="font-size: 28rpx;"
  16. placeholder-class="wk-placeholder placeholder"
  17. class="wk-field__body-core"
  18. @input="changeText" />
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import mixins from './mixins'
  24. export default {
  25. name: 'WkFieldTextarea',
  26. mixins: [mixins],
  27. props: {
  28. type: {
  29. type: String,
  30. default: 'text'
  31. }
  32. },
  33. data() {
  34. return {
  35. }
  36. },
  37. computed: {
  38. getMaxlength() {
  39. return this.field.maxlength || 800
  40. }
  41. },
  42. methods: {
  43. handleClick() {
  44. if (this.field.disabled) {
  45. if (this.config && this.config.disabledMsg) {
  46. this.$toast(this.config.disabledMsg)
  47. }
  48. return
  49. }
  50. },
  51. // 禁止输入 emoji
  52. changeText() {
  53. const regStr = /[\ud800-\udbff]|[\udc00-\udfff]/g;
  54. let _str = this.formValue
  55. if (regStr.test(_str)) {
  56. _str = _str.replace(regStr, '');
  57. }
  58. this.$nextTick(() => {
  59. this.formValue = _str
  60. if (this.value !== this.formValue) {
  61. this.emitChangeEvt(this.formValue)
  62. }
  63. })
  64. }
  65. }
  66. }
  67. </script>
  68. <style scoped lang="scss">
  69. @import "wkField";
  70. .wk-field-textarea {
  71. display: block;
  72. .wk-field__body {
  73. .wk-field__body-core {
  74. height: 150rpx;
  75. }
  76. }
  77. }
  78. .placeholder {
  79. font-size: $wk-font-base;
  80. }
  81. </style>