chatInput.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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="ml20 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 ml20" @click="handleMoreClick">
  15. <image src="/static/images/more-icon.png" class="w58 h58" />
  16. </view>
  17. <view class="icon-bg ml20" @tap="handleOpenCart">
  18. <image src="/static/images/shopping.png" class="w58 h58" />
  19. </view>
  20. <!-- <view class="icon-bg ml20" @tap="handleShowGift">
  21. <image src="/static/images/gift.png" class="w58 h58" />
  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. &.input-focused {
  151. flex: 1;
  152. min-width: 0;
  153. }
  154. }
  155. .send-btn {
  156. background-color: #fafafa;
  157. border-radius: 28rpx;
  158. padding: 12rpx 16rpx;
  159. color: #181818;
  160. font-weight: 500;
  161. min-width: 80rpx;
  162. text-align: center;
  163. flex-shrink: 0;
  164. white-space: nowrap;
  165. cursor: pointer;
  166. transition: all 0.2s ease;
  167. &:active {
  168. opacity: 0.8;
  169. transform: scale(0.98);
  170. }
  171. }
  172. .icon-container {
  173. display: flex;
  174. align-items: center;
  175. justify-content: space-between;
  176. flex-shrink: 0;
  177. transition: all 0.3s ease;
  178. margin-left: 20rpx;
  179. &.icon-hidden {
  180. opacity: 0;
  181. visibility: hidden;
  182. width: 0;
  183. margin-left: 0;
  184. flex: 0;
  185. }
  186. }
  187. .icon-bg {
  188. background: rgba(0, 0, 0, 0.3);
  189. border-radius: 50%;
  190. width: 88rpx;
  191. height: 88rpx;
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. transition: transform 0.2s ease;
  196. cursor: pointer;
  197. &:active {
  198. transform: scale(0.95);
  199. }
  200. &+& {
  201. margin-left: 20rpx;
  202. }
  203. }
  204. </style>