cl-textarea.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="cl-textarea" :class="[classList]">
  3. <textarea
  4. v-model="value2"
  5. :style="{ height }"
  6. :placeholder="placeholder"
  7. :disabled="isDisabled"
  8. :focus="focus"
  9. :auto-height="autoHeight"
  10. :fixed="fixed"
  11. :cursor-spacing="cursorSpacing"
  12. :cursor="cursor"
  13. :show-confirm-bar="showConfirmBar"
  14. :selection-start="selectionStart"
  15. :selection-end="selectionEnd"
  16. :adjust-position="adjustPosition"
  17. :disable-default-padding="disableDefaultPadding"
  18. :hold-keyboard="holdKeyboard"
  19. :maxlength="maxlength"
  20. @focus="onFocus"
  21. @blur="onBlur"
  22. @linechange="onLinechange"
  23. @input="onInput"
  24. @confirm="onConfirm"
  25. @keyboardheightchange="onKeyboardheightchange"
  26. ></textarea>
  27. <!-- #ifndef MP-ALIPAY -->
  28. <text class="cl-textarea__count" v-if="count">{{ value2.length }}/{{ maxlength }}</text>
  29. <!-- #endif -->
  30. </view>
  31. </template>
  32. <script>
  33. import Form from "../../mixins/form";
  34. /**
  35. * textarea 文本域
  36. * @description 文本域
  37. * @tutorial https://docs.cool-js.com/uni/components/form/textarea.html
  38. * @property {String} value 绑定值
  39. * @property {Boolean} count 是否显示统计字数
  40. * @property {String} placeholder 占位内容
  41. * @property {String} height 输入框高度,默认140rpx
  42. * @event {Function} change 绑定值改变时触发
  43. * @example <cl-textarea v-model="val" />
  44. */
  45. export default {
  46. name: "cl-textarea",
  47. props: {
  48. // 绑定值
  49. value: {
  50. type: String,
  51. default: "",
  52. },
  53. // 占位内容
  54. placeholder: String,
  55. // 输入框高度
  56. height: {
  57. type: String,
  58. default: "140rpx",
  59. },
  60. // 是否禁用
  61. disabled: Boolean,
  62. // 是否显示统计字数
  63. count: Boolean,
  64. focus: Boolean,
  65. autoHeight: Boolean,
  66. fixed: Boolean,
  67. cursorSpacing: {
  68. type: Number,
  69. default: 0,
  70. },
  71. cursor: Number,
  72. showConfirmBar: {
  73. type: Boolean,
  74. default: true,
  75. },
  76. selectionStart: {
  77. type: Number,
  78. default: -1,
  79. },
  80. selectionEnd: {
  81. type: Number,
  82. default: -1,
  83. },
  84. adjustPosition: {
  85. type: Boolean,
  86. default: true,
  87. },
  88. disableDefaultPadding: Boolean,
  89. holdKeyboard: Boolean,
  90. maxlength: {
  91. type: Number,
  92. default: 140,
  93. },
  94. },
  95. mixins: [Form],
  96. data() {
  97. return {
  98. value2: "",
  99. };
  100. },
  101. watch: {
  102. value: {
  103. immediate: true,
  104. handler(val) {
  105. this.value2 = val;
  106. },
  107. },
  108. },
  109. computed: {
  110. classList() {
  111. let list = [];
  112. if (this.isDisabled) {
  113. list.push("is-disabled");
  114. }
  115. if (this.count) {
  116. list.push("is-count");
  117. }
  118. return list.join(" ");
  119. },
  120. },
  121. methods: {
  122. onFocus(e) {
  123. this.$emit("focus", e);
  124. },
  125. onBlur(e) {
  126. this.$emit("blur", e);
  127. },
  128. onLinechange(e) {
  129. this.$emit("linechange", e);
  130. },
  131. onInput(e) {
  132. this.$emit("input", e.detail.value);
  133. },
  134. onConfirm(e) {
  135. this.$emit("confirm", e);
  136. },
  137. onKeyboardheightchange(e) {
  138. this.$emit("keyboardheightchange", e);
  139. },
  140. },
  141. };
  142. </script>