app-textarea.vue 3.8 KB

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