messageInput.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="send-wrap ss-flex">
  3. <view class="left ss-flex ss-flex-1">
  4. <uni-easyinput class="ss-flex-1 ss-p-l-22" :inputBorder="false" :clearable="false" v-model="message"
  5. placeholder="请输入你要咨询的问题"></uni-easyinput>
  6. </view>
  7. <text class="sicon-basic bq" @tap.stop="onTools('emoji')"></text>
  8. <text v-if="!message" class="sicon-edit" :class="{ 'is-active': toolsMode === 'tools' }"
  9. @tap.stop="onTools('tools')"></text>
  10. <button v-if="message" class="ss-reset-button send-btn" :disabled="loading" @tap="sendMessage">
  11. {{ loading ? '发送中...' : '发送' }}
  12. </button>
  13. </view>
  14. </template>
  15. <script setup>
  16. import { computed, ref } from 'vue';
  17. /**
  18. * 消息发送组件
  19. */
  20. const props = defineProps({
  21. // 消息
  22. modelValue: {
  23. type: String,
  24. default: '',
  25. },
  26. // 工具模式
  27. toolsMode: {
  28. type: String,
  29. default: '',
  30. },
  31. loading: {
  32. type: Boolean,
  33. default: false,
  34. },
  35. });
  36. const emits = defineEmits(['update:modelValue', 'onTools', 'sendMessage']);
  37. const message = computed({
  38. get() {
  39. return props.modelValue;
  40. },
  41. set(newValue) {
  42. emits(`update:modelValue`, newValue);
  43. }
  44. });
  45. // 打开工具菜单
  46. function onTools(mode) {
  47. emits('onTools', mode);
  48. }
  49. // 发送消息
  50. async function sendMessage() {
  51. if (props.loading) return;
  52. try {
  53. await emits('sendMessage');
  54. } finally {
  55. }
  56. }
  57. </script>
  58. <style scoped lang="scss">
  59. .send-wrap {
  60. padding: 18rpx 20rpx;
  61. background: #fff;
  62. .left {
  63. height: 64rpx;
  64. border-radius: 32rpx;
  65. background: var(--ui-BG-1);
  66. }
  67. .bq {
  68. font-size: 50rpx;
  69. margin-left: 10rpx;
  70. }
  71. .sicon-edit {
  72. font-size: 50rpx;
  73. margin-left: 10rpx;
  74. transform: rotate(0deg);
  75. transition: all linear 0.2s;
  76. &.is-active {
  77. transform: rotate(45deg);
  78. }
  79. }
  80. .send-btn {
  81. width: 100rpx;
  82. height: 60rpx;
  83. line-height: 60rpx;
  84. border-radius: 30rpx;
  85. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  86. font-size: 26rpx;
  87. color: #fff;
  88. margin-left: 11rpx;
  89. &:disabled {
  90. opacity: 0.6;
  91. }
  92. }
  93. }
  94. </style>