当前位置:   article > 正文

微信小程序textarea层级过高覆盖其他组件的解决方法,亲测优化有效(taro,微信小程序原代码类似)_vue textarea 拖动会覆盖其他元素

vue textarea 拖动会覆盖其他元素

今天在做微信小程序一个页面多个textarea输入框时,出现了textarea层级过高覆盖其他组件的问题,在网上搜了很多资料,按照某一个解决方案思路去尝试,但是还是遇到了部分问题,最终优化解决了这些问题,运行效果图如下:

具体代码如下:

app.styl:

  1. .hide{
  2. display: none !important;
  3. }
  4. .show{
  5. display: block !important;
  6. }
  7. // @textare
  8. .textarea_content {
  9. width:100%;
  10. height: 192rpx;
  11. padding: 18rpx;
  12. font-size:32rpx;
  13. line-height:1.5;
  14. border-radius:8rpx;
  15. background-color:#FFF;
  16. -webkit-box-sizing:border-box;
  17. box-sizing:border-box;
  18. border-top:1PX #d6e4ef solid;
  19. border-bottom:1PX #d6e4ef solid;
  20. border-right:1PX #d6e4ef solid;
  21. border-left:1PX #d6e4ef solid;
  22. }
  23. /*隐藏滚动条*/
  24. ::-webkit-scrollbar{
  25. width: 0;
  26. height: 0;
  27. color: transparent;
  28. }
  29. .textarea_text {
  30. word-break: keep-all;
  31. word-wrap: break-word;
  32. width:100%;
  33. font-size:32rpx;
  34. line-height:1;
  35. outline:none;
  36. resize:none;
  37. -webkit-appearance:none;
  38. border-radius:0;
  39. padding:0;
  40. margin:0;
  41. border:0;
  42. }
  43. .textarea_placeholder{
  44. font-size:32rpx;
  45. color: #CCCCCC;
  46. }

maintenanceAdd.tsx:

  1. import Taro, { Component, Config } from '@tarojs/taro'
  2. import { View, Text, ScrollView } from '@tarojs/components'
  3. export default class maintenanceAdd extends Component {
  4. /**
  5. * 指定config的类型声明为: Taro.Config
  6. *
  7. * 由于 typescript 对于 object 类型推导只能推出 Key 的基本类型
  8. * 对于像 navigationBarTextStyle: 'black' 这样的推导出的类型是 string
  9. * 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型
  10. */
  11. config: Config = {
  12. navigationBarTitleText: '填写维修报告'
  13. }
  14. constructor() {
  15. super(...arguments)
  16. this.state = {
  17. repairDesc: "",
  18. problemDesc: "",
  19. // @textare
  20. textAreaObj: [{
  21. isContentFocus: true,
  22. isInputContentFocus: false,
  23. isFocus: false
  24. },{
  25. isContentFocus: true,
  26. isInputContentFocus: false,
  27. isFocus: false
  28. }]
  29. }
  30. }
  31. ......
  32. repairDescHandleText(e) {
  33. const value = e.detail.value
  34. this.setState({
  35. repairDesc: value
  36. })
  37. }
  38. problemDescHandleText(e) {
  39. const value = e.detail.value
  40. this.setState({
  41. problemDesc: value
  42. })
  43. }
  44. ......
  45. // @textare处理事件
  46. bindTextareaHandle(index, type){
  47. if(type=='blur'){
  48. this.state.textAreaObj[index] = {
  49. isFocus: false, //触发焦点
  50. isContentFocus: true, //聚焦时隐藏内容文本标签
  51. isInputContentFocus: false
  52. };
  53. }else if(type=='focus'){
  54. this.state.textAreaObj[index] = {
  55. isFocus: true, //触发焦点
  56. isContentFocus: false, //聚焦时隐藏内容文本标签
  57. isInputContentFocus: true
  58. };
  59. }
  60. this.setState({
  61. textAreaObj: this.state.textAreaObj
  62. });
  63. }
  64. render() {
  65. const {
  66. repairDesc,
  67. problemDesc,
  68. // @textare
  69. textAreaObj
  70. } = this.state;
  71. const textAreaObj0 = textAreaObj[0], textAreaObj1 = textAreaObj[1];
  72. return (
  73. <View className='page90 bk-F3 pd24 mt128'>
  74. <Cnavbar title='填写维修报告' left={true}></Cnavbar>
  75. <View className='p_view bk'>
  76. ......
  77. <View className='resultFont'>维修描述</View>
  78. <View className={textAreaObj0.isInputContentFocus ? 'show':'hide'}>
  79. <AtTextarea
  80. name='repairDesc'
  81. value={repairDesc}
  82. focus={textAreaObj0.isFocus}
  83. onChange={this.repairDescHandleText.bind(this)}
  84. onBlur={this.bindTextareaHandle.bind(this,0,'blur')}
  85. maxlength='180'
  86. placeholder='请输入'
  87. />
  88. </View>
  89. <View className={textAreaObj0.isContentFocus ? 'show':'hide'} onClick={this.bindTextareaHandle.bind(this,0,'focus')}>
  90. <ScrollView
  91. scrollY={true}
  92. className="textarea_content"
  93. >
  94. {repairDesc
  95. ? <Text className="textarea_text" space="nbsp">{repairDesc}</Text>
  96. : <View className="textarea_placeholder">请输入</View>}
  97. </ScrollView>
  98. </View>
  99. ......
  100. <View className='resultFont'>问题描述</View>
  101. <View className={textAreaObj1.isInputContentFocus ? 'show':'hide'}>
  102. <AtTextarea
  103. name='problemDesc'
  104. value={problemDesc}
  105. focus={textAreaObj1.isFocus}
  106. onChange={this.problemDescHandleText.bind(this)}
  107. onBlur={this.bindTextareaHandle.bind(this,1,'blur')}
  108. maxlength='180'
  109. placeholder='请输入'
  110. />
  111. </View>
  112. <View className={textAreaObj1.isContentFocus ? 'show':'hide'} onClick={this.bindTextareaHandle.bind(this,1,'focus')}>
  113. <ScrollView
  114. scrollY={true}
  115. className="textarea_content"
  116. >
  117. {problemDesc
  118. ? <Text className="textarea_text" space="nbsp">{problemDesc}</Text>
  119. : <View className="textarea_placeholder">请输入</View>}
  120. </ScrollView>
  121. </View>
  122. </View>
  123. ......
  124. <View className='mt26'>
  125. <AtButton className='btn1' onClick={this.saveHandler}><View className='white-Font'>提交维修报告</View></AtButton>
  126. </View>
  127. </View>
  128. </View>
  129. )
  130. }
  131. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/93839
推荐阅读
  

闽ICP备14008679号