input-box.nvue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="subnvue" @click.stop="">
  3. <div class="mask" @click="hide()"></div>
  4. <div class="bottom" >
  5. <div v-if="!flag"></div>
  6. <input class="input" ref="input" @keyboardheightchange="heightChange" :cursor-spacing="space" v-model="message" :placeholder="placeholder" v-if="flag"/>
  7. <div class="bottomBtn-box">
  8. <div class="bottomBtn" @click="clickSubmit" :style="{backgroundColor:message!=''?'#00CAFC':'#B1EFFE'}">
  9. <text class="bottom-text">发送</text>
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. flag:false,
  20. message:'',
  21. space:0 //兼容ios
  22. }
  23. },
  24. beforeCreate() {
  25. },
  26. created(){
  27. //ios首页输入兼容
  28. uni.getSystemInfo({
  29. success: (e) => {
  30. if(e.platform=='ios') this.space = -50
  31. }
  32. })
  33. uni.$on('showInput', () => {
  34. this.flag = true
  35. this.$nextTick(()=>{
  36. this.$refs.input.focus()
  37. })
  38. })
  39. },
  40. destroyed() {
  41. uni.$off('showInput')
  42. },
  43. methods: {
  44. hide() {
  45. uni.hideKeyboard()
  46. setTimeout(()=>{
  47. this.quit()
  48. },200)
  49. },
  50. heightChange(e){
  51. console.log(e.detail.height)
  52. if(e.detail.height<=0) this.quit()
  53. },
  54. clickSubmit(){
  55. if(this.message=='') return
  56. uni.$emit('sendComment',this.message)
  57. this.quit()
  58. },
  59. quit(){
  60. uni.hideKeyboard()
  61. this.message = ''
  62. uni.$emit('showComment')
  63. uni.getSubNVueById('input-box').hide();
  64. this.flag = false
  65. }
  66. },
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .subnvue {
  71. flex-direction: column;
  72. flex: 1;
  73. background-color: transparent;
  74. }
  75. .mask{
  76. flex: 1;
  77. opacity: 0.1;
  78. //background-color: #fff;
  79. }
  80. .bottom{
  81. box-shadow: 0 -1px 4px 1px rgba(0,0,0,0.1);
  82. background-color: #fff;
  83. padding: 30rpx 30rpx 0 30rpx;
  84. align-items: center;
  85. flex-direction: row;
  86. justify-content: space-between;
  87. }
  88. .input{
  89. flex: 1;
  90. font-size: 16px;
  91. height: 90rpx;
  92. padding: 0 0 50rpx 0;
  93. }
  94. .bottomBtn-box{
  95. height: 140rpx;
  96. padding: 10rpx 0 0 0;
  97. }
  98. .bottomBtn{
  99. padding: 5rpx 15rpx;
  100. border-radius:10rpx;
  101. margin-left: 30rpx;
  102. }
  103. .bottom-text{
  104. color: #fff;
  105. }
  106. </style>