app-textarea.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="app-textarea">
  3. <view class="a"
  4. @click="showInput=true"
  5. :style="{
  6. background: background,
  7. fontSize: `${fontSize}rpx`,
  8. color: color,
  9. borderRadius: `${borderRadius}rpx`,
  10. border: showBorder ? `1rpx solid ${borderColor}` : 'none',
  11. padding: `${paddingY}rpx ${paddingX}rpx`,
  12. }">
  13. <text v-if="inValue" class="content">{{inValue}}</text>
  14. <view v-else
  15. class="placeholder"
  16. :style="placeholderStyle"
  17. :class="placeholderClass">{{placeholder}}
  18. </view>
  19. </view>
  20. <view class="b" v-if="showInput">
  21. <textarea class="textarea"
  22. :value="inValue"
  23. :placeholder="placeholder"
  24. :focus="showInput"
  25. :maxlength="maxlength"
  26. @input="handleInput"
  27. @blur="complete"
  28. @confirm="complete"/>
  29. <view class="c" @click="complete"></view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. name: 'app-textarea',
  36. props: {
  37. value: {
  38. default: '',
  39. },
  40. placeholder: {
  41. default: '',
  42. },
  43. placeholderStyle: {
  44. default: '',
  45. },
  46. placeholderClass: {
  47. default: [],
  48. },
  49. disable: {
  50. default: false,
  51. },
  52. maxlength: {
  53. default: 10000,
  54. },
  55. focus: {
  56. default: false,
  57. },
  58. confirmType: {
  59. default: 'done'
  60. },
  61. showBorder: {
  62. default: true,
  63. },
  64. borderColor: {
  65. default: '#cccccc',
  66. },
  67. borderRadius: {
  68. default: 8,
  69. },
  70. fontSize: {
  71. default: 32,
  72. },
  73. color: {
  74. default: '#555',
  75. },
  76. background: {
  77. default: '#fff',
  78. },
  79. paddingX: {
  80. default: 24,
  81. },
  82. paddingY: {
  83. default: 24,
  84. },
  85. },
  86. data() {
  87. return {
  88. showInput: !!this.focus,
  89. inValue: this.value,
  90. };
  91. },
  92. methods: {
  93. handleInput(e) {
  94. this.inValue = e.detail.value;
  95. },
  96. complete(e) {
  97. this.showInput = false;
  98. this.$emit('input', this.inValue);
  99. },
  100. }
  101. }
  102. </script>
  103. <style scoped lang="scss">
  104. .a {
  105. .content {
  106. color: #444;
  107. display: block;
  108. width: 100%;
  109. min-height: $uni-font-size;
  110. word-wrap: break-word;
  111. }
  112. .placeholder {
  113. color: #aaa;
  114. min-height: $uni-font-size;
  115. }
  116. }
  117. .b {
  118. position: fixed;
  119. background: rgba(0, 0, 0, 0.5);
  120. padding: #{50rpx};
  121. top: 0;
  122. left: 0;
  123. right: 0;
  124. bottom: 0;
  125. z-index: 2000;
  126. .textarea {
  127. width: 100%;
  128. background: #fff;
  129. border: #{1rpx} solid #ccc;
  130. z-index: 1;
  131. padding: #{24rpx};
  132. border-radius: #{5rpx};
  133. }
  134. .c {
  135. position: fixed;
  136. left: 0;
  137. top: 0;
  138. right: 0;
  139. bottom: 0;
  140. z-index: 0;
  141. }
  142. }
  143. </style>