en-textarea.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="box">
  3. <view class="input-box" :class="isFlex?'input-flex':''">
  4. <view class="input-box-left" :style="{'letter-spacing':labelWidth}">
  5. {{ label }}
  6. </view>
  7. <view class="input-textarea">
  8. <textarea
  9. class="textarea-data"
  10. :placeholder="placeholder ? placeholder : ''"
  11. :disabled="!!disabled"
  12. :value="inputValue"
  13. @blur="bindTextAreaBlur"
  14. :auto-height="true"
  15. />
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'en-textarea',
  23. props: {
  24. label: {
  25. type: String,
  26. default: '标题'
  27. },
  28. placeholder: {
  29. type: String,
  30. default: '请输入'
  31. },
  32. disabled: {
  33. default: false
  34. },
  35. value: {
  36. default: ''
  37. },
  38. isFlex:{
  39. default: true
  40. }
  41. },
  42. data() {
  43. return {
  44. inputValue: '',
  45. labelWidth: 0
  46. }
  47. },
  48. components: {},
  49. mounted() {
  50. this.inputValue = this.value
  51. this.setLabelWidth()
  52. },
  53. watch: {
  54. 'value': function () {
  55. if (this.inputValue !== this.value) {
  56. this.inputValue = this.value
  57. }
  58. },
  59. 'inputValue': function () {
  60. this.$emit('input', this.inputValue)
  61. }
  62. },
  63. methods: {
  64. setLabelWidth() {
  65. let differenceNum = 4 - this.label.length;
  66. if (differenceNum === 2) {
  67. this.labelWidth = '2em'
  68. } else if (differenceNum === 1) {
  69. this.labelWidth = '0.5em'
  70. }
  71. },
  72. bindTextAreaBlur(e){
  73. this.inputValue=e.detail.value
  74. }
  75. }
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. @import url("../../static/css/en-common.css");
  80. .box {
  81. .input-flex{
  82. display: flex;
  83. align-items: center;
  84. }
  85. .input-box {
  86. .input-box-left {
  87. width: 210rpx;
  88. min-width: 210rpx;
  89. font-size: 32rpx;
  90. color: #333333;
  91. }
  92. .input-textarea{
  93. height: 170rpx;
  94. padding: 6rpx;
  95. border-radius: 10rpx;
  96. border: 2rpx solid #F0F0F0;
  97. overflow: auto;
  98. .textarea-data{
  99. height: 170rpx;
  100. width: 400rpx;
  101. }
  102. }
  103. }
  104. }
  105. </style>