index.vue 11.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
<template>
  <view class="TUI-message-input-container">
    <view class="TUI-message-input flexA">
      <!-- #ifdef H5 -->
      <!-- <image class="TUI-icon" @tap="handleEmoji" src="../../../../assets/icon/emoji.svg" v-if="[10, '10', 21, '21'].includes(detailData.consultationWay)"></image> -->
      <!-- #endif -->
      <!-- #ifndef H5 -->
      <!-- 语音暂不开放 -->
      <!-- <image class="TUI-icon" @tap="handleSwitchAudio" src="../../../../assets/icon/audio.svg" v-if="[10, '10', 21, '21'].includes(detailData.consultationWay)"></image> -->
      <!-- #endif -->
      <view v-if="!isAudio" class="TUI-message-input-main">
        <input
          v-if="[10, '10', 21, '21'].includes(detailData.consultationWay)"
          class="TUI-message-input-area"
          :adjust-position="true"
          cursor-spacing="20"
          v-model="inputText"
          confirm-type="send"
          confirm-hold="true"
          @confirm="handleSendTextMessage"
          maxlength="140"
          type="text"
          placeholder-class="input-placeholder"
          placeholder="说点什么呢~"
        />
        <view v-else style="font-size: 18rpx">{{ proxy.$h.optObjectValue('consultationWay', detailData.consultationWay) + '暂不支持发送消息' }}</view>
      </view>
      <view v-else class="TUI-message-input-main">
        <AudioMessage></AudioMessage>
      </view>
      <!-- <up-button
        v-if="[10, '10', 21, '21'].includes(detailData.consultationWay)"
        color="#05B8D2"
        shape="circle"
        text="发送"
        throttleTime="1500"
        @click="handleSendTextMessage"
        :customStyle="{ width: '122rpx', height: '74rpx', marginRight: '16rpx' }"
      ></up-button> -->

      <view class="TUI-message-input-functions" hover-class="none">
        <image class="TUI-icon" @tap="handleEmoji" src="../../../../assets/icon/emoji.svg"></image>
        <view @tap="handleExtensions">
          <image class="TUI-icon" src="../../../../assets/icon/more.svg"></image>
        </view>
      </view>
    </view>
    <view v-if="displayFlag === 'emoji'" class="TUI-Emoji-area">
      <Face :show="displayFlag === 'emoji'" @send="handleSend" @handleSendEmoji="handleSendTextMessage"></Face>
    </view>
    <view v-if="displayFlag === 'extension'" class="TUI-Extensions">
      <!-- TODO: 这里功能还没实现
				<!       <camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>-->
      <view class="TUI-Extension-slot" @tap="handleSendImageMessage('camera')" v-if="[10, '10', 21, '21'].includes(detailData.consultationWay)">
        <image class="TUI-Extension-icon" src="../../../../assets/icon/take-photo.svg"></image>
        <view class="TUI-Extension-slot-name">拍照</view>
      </view>
      <view class="TUI-Extension-slot" @tap="handleSendImageMessage('album')" v-if="[10, '10', 21, '21'].includes(detailData.consultationWay)">
        <image class="TUI-Extension-icon" src="../../../../assets/icon/send-img.svg"></image>
        <view class="TUI-Extension-slot-name">图片</view>
      </view>
      <view class="TUI-Extension-slot" @tap="handleSendVideoMessage('album')" v-if="[10, '10', 21, '21'].includes(detailData.consultationWay)">
        <image class="TUI-Extension-icon" src="../../../../assets/icon/take-video.svg"></image>
        <view class="TUI-Extension-slot-name">视频</view>
      </view>
      <view class="TUI-Extension-slot" @tap="handleSendVideoMessage('camera')" v-if="false">
        <image class="TUI-Extension-icon" src="../../../../assets/icon/take-photo.svg"></image>
        <view class="TUI-Extension-slot-name">录像</view>
      </view>
      <!-- #ifndef H5 -->
      <view class="TUI-Extension-slot" @tap="handleCalling(1)" v-if="[23, '23'].includes(detailData.consultationWay)">
        <image class="TUI-Extension-icon" src="../../../../assets/icon/audio-calling.svg"></image>
        <view class="TUI-Extension-slot-name">语音通话</view>
      </view>
      <view class="TUI-Extension-slot" @tap="handleCalling(2)" v-if="[22, '22'].includes(detailData.consultationWay)">
        <image class="TUI-Extension-icon" src="../../../../assets/icon/take-video.svg"></image>
        <view class="TUI-Extension-slot-name">视频通话</view>
      </view>
      <!-- #endif -->
    </view>
  </view>
</template>

<script lang="ts">
import { defineComponent, defineEmits, watchEffect, reactive, toRefs, onMounted, computed, nextTick, getCurrentInstance, ComponentPublicInstance } from 'vue'
import Face from './message/face.vue'
import AudioMessage from './message/audio.vue'
import store from '../../../../TUICore/store'

const TUIChatInput = defineComponent({
  components: {
    Face,
    AudioMessage
  },
  props: {
    text: {
      type: String,
      default: () => {
        return ''
      }
    },
    conversationData: {
      type: Object,
      default: () => {
        return ''
      }
    },
    detailData: {
      type: Object,
      default: () => ({})
    }
  },
  emits: ['scrollbottomHandler', 'sendMessagehandler'],
  setup(props, { emit }) {
    const { proxy } = getCurrentInstance() as { proxy: ComponentPublicInstance }

    const TUIServer: any = uni.$TUIKit.TUIChatServer
    const data = reactive({
      firstSendMessage: true,
      inputText: '',
      extensionArea: false,
      sendMessageBtn: false,
      displayFlag: '',
      isAudio: false,
      displayServiceEvaluation: false,
      displayCommonWords: false,
      displayOrderList: false,

      conversation: computed(() => store.state.timStore.conversation)
    })

    // watchEffect(() => {
    //   data.inputText = props.text
    // })

    const handleSwitchAudio = () => {
      data.isAudio = !data.isAudio
    }

    const handleEmoji = () => {
      data.displayFlag = data.displayFlag === 'emoji' ? '' : 'emoji'
    }
    const handleExtensions = (e: any) => {
      data.displayFlag = data.displayFlag === 'extension' ? '' : 'extension'
    }

    // 发送消息
    const handleSendTextMessage = (e: any) => {
      // if (data.inputText.trimEnd()) {
      //   uni.$TUIKit.TUIChatServer.sendTextMessage(JSON.parse(JSON.stringify(data.inputText)))
      // }
      emit('sendMessagehandler', data.inputText)
      emit('scrollbottomHandler')
      data.inputText = ' '
    }

    // 处理需要合并的数据
    const handleSend = (emo: any) => {
      data.inputText += emo.name
      // inputEle.value.focus();
    }

    const handleSendImageMessage = (type: any) => {
      uni.chooseImage({
        sourceType: [type],
        count: 1,
        success: res => {
          uni.getImageInfo({
            src: res.tempFilePaths[0],
            success(image) {
              console.error(image)
              TUIServer.sendImageMessage(res, image)
              emit('scrollbottomHandler')
            }
          })
        }
      })
    }

    const handleSendVideoMessage = (type: any) => {
      uni.chooseVideo({
        sourceType: [type],
        // 来源相册或者拍摄
        maxDuration: 60,
        // 设置最长时间60s
        camera: 'back',
        // 后置摄像头
        success: res => {
          if (res) {
            TUIServer.sendVideoMessage(res)
          }
        }
      })
    }

    const handleCalling = (value: any) => {
      // todo 目前支持单聊
      if (data.conversation.type === 'GROUP') {
        uni.showToast({
          title: '群聊暂不支持',
          icon: 'none'
        })
        return
      }
      const { userID } = data.conversation.userProfile

      // #ifdef APP-PLUS
      const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit')
      console.warn(TUICallKit, 'TUICallKit | ok666666666666699999999999999999999999999999') // 本地日志
      uni.$TUICallKit = TUICallKit // 全局引入

      if (typeof uni.$TUICallKit === 'undefined') {
        console.error('请集成 TUICallKit 插件,使用真机运行并且自定义基座调试,请参考官网文档:https://cloud.tencent.com/document/product/269/83857')
        uni.showToast({
          title: '请集成 TUICallKit 插件哦 ~ ',
          icon: 'none',
          duration: 3000
        })
      } else {
        console.log(uni.$TUICallKit, '6666666666666666666666666666666666')

        nextTick(() => {
          uni.$TUICallKit.call(
            {
              userID: userID,
              callMediaType: value
            },
            res => {
              console.log(JSON.stringify(res), '有值嘛')
            }
          )
        })
      }
      // #endif

      // #ifdef MP-WEIXIN
      if (typeof uni.$TUICallKit !== 'undefined' && uni.$TUICallKit.value !== null) {
        uni.$TUICallKit.value.call({
          userID: userID,
          type: value
        })
      } else {
        console.error('请集成 TUICallKit 插件哦~,请参考官网文档:https://cloud.tencent.com/document/product/269/83858')
        uni.showToast({
          title: '请集成 TUICallKit 插件哦 ~ ',
          icon: 'none',
          duration: 3000
        })
      }
      // #endif

      // #ifdef H5
      uni.showToast({
        title: '暂不支持',
        icon: 'none'
      })
      // #endif
    }
    return {
      ...toRefs(data),
      proxy,
      handleExtensions,
      handleSendImageMessage,
      handleSendTextMessage,
      handleSendVideoMessage,
      handleEmoji,
      handleSend,
      handleSwitchAudio,
      handleCalling
    }
  }
})
export default TUIChatInput
</script>
<style lang="scss" scoped>
.TUI-message-input-container {
  background-color: #fff;
  padding-bottom: 20rpx;
}

.TUI-message-input {
  display: flex;
  padding: 16rpx;
  background-color: #fff;
  width: 100vw;
}

.TUI-commom-function {
  display: flex;
  flex-wrap: nowrap;
  width: 750rpx;
  height: 106rpx;
  background-color: #fff;
  align-items: center;
}

.TUI-commom-function-item {
  display: flex;
  width: 136rpx;
  justify-content: center;
  align-items: center;
  font-size: 24rpx;
  color: #ffffff;
  height: 48rpx;
  margin-left: 16rpx;
  border-radius: 24rpx;
  background-color: #00c8dc;
}

.TUI-commom-function-item:first-child {
  margin-left: 48rpx;
}

.TUI-message-input-functions {
  display: flex;
}

.TUI-message-input-main {
  flex: 1;
  margin: 0 10rpx;
  padding: 0 5rpx;
  border-radius: 5rpx;
  display: flex;
  align-items: center;
  height: 74rpx;
  border-radius: 116rpx;
  background: #f4f5f7;
  box-sizing: border-box;
  padding: 0 24rpx;
}
.TUI-message-input-area {
  width: 100%;
  height: 100%;
}

.TUI-icon {
  width: 56rpx;
  height: 56rpx;
  margin: 0 16rpx;
}

.TUI-Extensions {
  display: flex;
  flex-wrap: wrap;
  width: 100vw;
  height: 450rpx;
  margin-left: 14rpx;
  margin-right: 14rpx;
}

.TUI-Extension-slot {
  width: 128rpx;
  height: 170rpx;
  margin-left: 26rpx;
  margin-right: 26rpx;
  margin-top: 24rpx;
}

.TUI-Extension-icon {
  width: 128rpx;
  height: 128rpx;
}

.TUI-sendMessage-btn {
  display: flex;
  align-items: center;
  margin: 0 10rpx;
}

.TUI-Emoji-area {
  width: 100vw;
  height: 450rpx;
}

.TUI-Extension-slot-name {
  line-height: 34rpx;
  font-size: 24rpx;
  color: #333333;
  letter-spacing: 0;
  text-align: center;
}

.record-modal {
  height: 300rpx;
  width: 60vw;
  background-color: #000;
  opacity: 0.8;
  position: fixed;
  top: 670rpx;
  z-index: 9999;
  left: 20vw;
  border-radius: 24rpx;
  display: flex;
  flex-direction: column;
}

.record-modal .wrapper {
  display: flex;
  height: 200rpx;
  box-sizing: border-box;
  padding: 10vw;
}

.record-modal .wrapper .modal-loading {
  opacity: 1;
  width: 40rpx;
  height: 16rpx;
  border-radius: 4rpx;
  background-color: #006fff;
  animation: loading 2s cubic-bezier(0.17, 0.37, 0.43, 0.67) infinite;
}

.modal-title {
  text-align: center;
  color: #fff;
}

@keyframes loading {
  0% {
    transform: translate(0, 0);
  }

  50% {
    transform: translate(30vw, 0);
    background-color: #f5634a;
    width: 40px;
  }

  100% {
    transform: translate(0, 0);
  }
}
</style>