chat.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="content">
  3. <view class="w h-88 flex ai_center jc_center mgt-88 p-rel">
  4. <image
  5. @click="$navBack()"
  6. class="w-48 h-48 abs_left"
  7. style="left: 32rpx"
  8. src="/static/image/common/left_arrow_icon.png"
  9. mode="scaleToFill"
  10. />
  11. <view class="text-36 text-500 text-070202">用户昵称123</view>
  12. </view>
  13. <view class="message-box pdx-32">
  14. <view class="w flex fd_c ai_center" v-for="item in 5" :key="item">
  15. <view class="text-20 text-500 text-B9B9B9 mgt-32 mgb-32">
  16. 2025/08/8 16:00
  17. </view>
  18. <view class="ims_item w flex ai_center mgb-24">
  19. <view class="ims_head">
  20. <image
  21. class="w-80 h-80 radio-circle"
  22. src="/static/image/my/my_default_avatar.png"
  23. mode="scaleToFill"
  24. />
  25. </view>
  26. <view class="ims_conten ims_conten_left mgl-16"
  27. >这是一条消息内容</view
  28. >
  29. </view>
  30. <view class="ims_item w flex ai_center jc_end mgb-24">
  31. <view class="ims_conten ims_conten_right mgl-16"
  32. >这是一条消息内容</view
  33. >
  34. <view class="ims_head">
  35. <image
  36. class="w-80 h-80 radio-circle"
  37. src="/static/image/my/user_avatar_80.png"
  38. mode="scaleToFill"
  39. />
  40. </view>
  41. </view>
  42. <view class="text-20 text-500 text-B9B9B9 mgt-32 mgb-32"> 16:00 </view>
  43. <view class="ims_item w flex ai_center mgb-24">
  44. <view class="ims_head">
  45. <image
  46. class="w-80 h-80 radio-circle"
  47. src="/static/image/my/my_default_avatar.png"
  48. mode="scaleToFill"
  49. />
  50. </view>
  51. <view class="ims_conten ims_conten_left mgl-16"
  52. >这是最新一条消息内容</view
  53. >
  54. </view>
  55. </view>
  56. </view>
  57. <view class="input_box" :style="{ bottom: bottomVal }">
  58. <!-- #ifndef APP-NVUE -->
  59. <u-input
  60. class="input"
  61. placeholder="请输入消息内容"
  62. :adjustPosition="false"
  63. @focus="inputBindFocus"
  64. @blur="inputBindBlur"
  65. >
  66. <!-- #endif -->
  67. <!-- #ifdef APP-NVUE -->
  68. <u--input
  69. class="input"
  70. placeholder="请输入消息内容"
  71. :adjustPosition="false"
  72. @focus="inputBindFocus"
  73. @blur="inputBindBlur"
  74. >
  75. <!-- #endif -->
  76. <template slot="suffix">
  77. <image
  78. class="w-48 h-48 radio-circle"
  79. src="/static/image/my/emoji_icon.png"
  80. mode="scaleToFill"
  81. />
  82. </template>
  83. <!-- #ifdef APP-NVUE -->
  84. </u--input>
  85. <!-- #endif -->
  86. <!-- #ifndef APP-NVUE -->
  87. </u-input>
  88. <!-- #endif -->
  89. </view>
  90. </view>
  91. </template>
  92. <script>
  93. export default {
  94. data() {
  95. return {
  96. bottomVal: "",
  97. };
  98. },
  99. onLoad() {},
  100. onReady() {
  101. uni.onKeyboardHeightChange((res) => {
  102. this.bottomVal = res.height + "px";
  103. console.log("监听到键盘高度:", res.height);
  104. });
  105. },
  106. methods: {
  107. inputBindFocus(e) {
  108. // 获取手机键盘的高度,赋值给input 所在盒子的 bottom 值
  109. // 注意!!! 这里的 px 至关重要!!! 我搜到的很多解决方案都没有说这里要添加 px
  110. // this.$emit("changeBottomVal", e.detail.height + "px");
  111. // console.log("e :===>>", e);
  112. // this.bottomVal = e.detail.height + "px";
  113. // console.log(" inputBindFocus:===>>", this.bottomVal);
  114. },
  115. inputBindBlur() {
  116. // input 失去焦点,键盘隐藏,设置 input 所在盒子的 bottom 值为0
  117. // this.$emit("changeBottomVal", 0);
  118. this.bottomVal = 0;
  119. console.log(" inputBindBlur:===>>", this.bottomVal);
  120. },
  121. },
  122. };
  123. </script>
  124. <style scoped lang="scss">
  125. .content {
  126. width: 100vw;
  127. height: 100vh;
  128. display: flex;
  129. flex-direction: column;
  130. .message-box {
  131. flex: 1;
  132. // background-color: #d2d1d1;
  133. display: flex;
  134. flex-direction: column;
  135. align-items: center;
  136. overflow-y: auto;
  137. padding-bottom: 800rpx;
  138. }
  139. }
  140. .ims_conten {
  141. display: inline-flex;
  142. height: 80rpx;
  143. padding: 20rpx 24rpx;
  144. justify-content: center;
  145. align-items: center;
  146. gap: 20rpx;
  147. flex-shrink: 0;
  148. border-radius: 0 24rpx 24rpx 24rpx;
  149. text-align: center;
  150. font-family: "MiSans VF";
  151. font-size: 32rpx;
  152. font-style: normal;
  153. font-weight: 400;
  154. line-height: normal;
  155. letter-spacing: -0.66rpx;
  156. }
  157. .ims_conten_left {
  158. color: #070202;
  159. background: #f3f4f4;
  160. }
  161. .ims_conten_right {
  162. color: #ffffff;
  163. background: #fe6505;
  164. }
  165. .input_box {
  166. position: absolute; // input 所在盒子设置绝对定位
  167. flex-shrink: 0;
  168. width: 100%;
  169. left: 0;
  170. bottom: 0; // 默认 0
  171. z-index: 199;
  172. padding: 16rpx 32rpx calc(env(safe-area-inset-bottom) + 24rpx);
  173. background: #ffffff;
  174. box-shadow: 0 -12rpx 24rpx 0 #0000000a;
  175. .input {
  176. width: 100%;
  177. height: 80rpx;
  178. flex-shrink: 0;
  179. border-radius: 64rpx;
  180. background: #f6f6f6;
  181. font-family: "MiSans VF";
  182. font-size: 28rpx;
  183. font-style: normal;
  184. font-weight: 400;
  185. line-height: 40rpx;
  186. letter-spacing: 0.66rpx;
  187. }
  188. }
  189. </style>