chatInput.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="chat-input-container" :class="{ 'parent-container-focused': isFocus }">
  3. <view class="x-f input-container" :class="{
  4. 'input-container-focused': isFocus,
  5. 'input-container-normal': !isFocus
  6. }">
  7. <input id="txgMsg" :placeholder="placeholderText" v-model="inputValue" placeholder-style="color:#e7e7e7;"
  8. placeholder-class="placeholder-style" class=" input-native input-field"
  9. :class="{ 'input-focused': isFocus }" @focus="handleFocus" @blur="handleBlur" cursor-spacing="100"
  10. :adjust-position="false" />
  11. <view class="send-btn" @click="handleSend">发送</view>
  12. </view>
  13. <view class="icon-container" :class="{ 'icon-hidden': isFocus }">
  14. <view class="icon-bg" @click="handleMoreClick">
  15. <image src="/static/images/live/more-icon.png" class="icon" />
  16. </view>
  17. <view class="icon-bg" @tap="handleOpenCart">
  18. <image src="/static/images/live/shopping.png" class="icon" />
  19. </view>
  20. <!-- <view class="icon-bg " @tap="handleShowGift">
  21. <image src="/static/images/live/gift.png" class="icon" />
  22. </view> -->
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'ChatInput',
  29. props: {
  30. placeholderText: {
  31. type: String,
  32. default: '说点什么...'
  33. },
  34. value: {
  35. type: String,
  36. default: ''
  37. },
  38. focused: {
  39. type: Boolean,
  40. default: false
  41. }
  42. },
  43. data() {
  44. return {
  45. isFocus: false,
  46. inputValue: ''
  47. };
  48. },
  49. watch: {
  50. focused: {
  51. immediate: true,
  52. handler(newVal) {
  53. this.isFocus = newVal;
  54. }
  55. },
  56. inputValue(newVal) {
  57. this.$emit('input', newVal);
  58. },
  59. value: {
  60. immediate: true,
  61. handler(newVal) {
  62. this.inputValue = newVal;
  63. }
  64. }
  65. },
  66. methods: {
  67. handleMoreClick() {
  68. this.$emit('show-more');
  69. },
  70. handleFocus() {
  71. this.isFocus = true;
  72. this.$emit('focus', this.inputValue);
  73. },
  74. handleBlur() {
  75. this.isFocus = false;
  76. this.$emit('blur', this.inputValue);
  77. },
  78. handleSend() {
  79. if (this.inputValue.trim()) {
  80. this.$emit('send', this.inputValue);
  81. this.inputValue = '';
  82. } else {
  83. uni.showToast({
  84. title: '不能发送空消息',
  85. icon: 'none'
  86. });
  87. }
  88. },
  89. handleOpenCart() {
  90. this.$emit('open-cart');
  91. },
  92. handleShowGift() {
  93. this.$emit('show-gift');
  94. },
  95. clearInput() {
  96. this.inputValue = '';
  97. },
  98. setInputValue(value) {
  99. this.inputValue = value;
  100. },
  101. getInputValue() {
  102. return this.inputValue;
  103. }
  104. }
  105. };
  106. </script>
  107. <style scoped lang="scss">
  108. .chat-input-container {
  109. display: flex;
  110. justify-content: space-between;
  111. align-items: center;
  112. padding: 24rpx;
  113. width: 100%;
  114. box-sizing: border-box;
  115. transition: all 0.3s ease;
  116. &.parent-container-focused {
  117. justify-content: flex-start;
  118. }
  119. }
  120. .input-container {
  121. background: rgba(0, 0, 0, 0.3);
  122. height: 90rpx;
  123. box-sizing: border-box;
  124. border-radius: 36rpx;
  125. display: flex;
  126. align-items: center;
  127. transition: all 0.3s ease;
  128. overflow: hidden;
  129. &.input-container-normal {
  130. padding: 10rpx 14rpx 10rpx 32rpx;
  131. flex: 1;
  132. justify-content: space-between;
  133. }
  134. &.input-container-focused {
  135. padding: 10rpx 10rpx 10rpx 20rpx;
  136. width: 100%;
  137. flex: 1 0 auto;
  138. justify-content: flex-start;
  139. gap: 20rpx;
  140. }
  141. }
  142. .input-field {
  143. border: none;
  144. font-size: 32rpx;
  145. color: #ffffff;
  146. background: transparent;
  147. flex: 1;
  148. min-width: 0;
  149. transition: all 0.3s ease;
  150. margin-left: 20rpx;
  151. &.input-focused {
  152. flex: 1;
  153. min-width: 0;
  154. }
  155. }
  156. .send-btn {
  157. background-color: #fafafa;
  158. border-radius: 28rpx;
  159. padding: 12rpx 16rpx;
  160. color: #181818;
  161. font-weight: 500;
  162. min-width: 80rpx;
  163. text-align: center;
  164. flex-shrink: 0;
  165. white-space: nowrap;
  166. cursor: pointer;
  167. transition: all 0.2s ease;
  168. &:active {
  169. opacity: 0.8;
  170. transform: scale(0.98);
  171. }
  172. }
  173. .icon-container {
  174. display: flex;
  175. align-items: center;
  176. justify-content: space-between;
  177. flex-shrink: 0;
  178. transition: all 0.3s ease;
  179. margin-left: 20rpx;
  180. &.icon-hidden {
  181. opacity: 0;
  182. visibility: hidden;
  183. width: 0;
  184. margin-left: 0;
  185. flex: 0;
  186. }
  187. }
  188. .icon-bg {
  189. background: rgba(0, 0, 0, 0.3);
  190. border-radius: 50%;
  191. width: 88rpx;
  192. height: 88rpx;
  193. display: flex;
  194. justify-content: center;
  195. align-items: center;
  196. transition: transform 0.2s ease;
  197. margin-left: 20rpx;
  198. cursor: pointer;
  199. &:active {
  200. transform: scale(0.95);
  201. }
  202. &+& {
  203. margin-left: 20rpx;
  204. }
  205. .icon {
  206. width: 58rpx;
  207. height: 58rpx;
  208. }
  209. }
  210. </style>