index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <view class="TUI-message-input-container">
  3. <view class="TUI-message-input">
  4. <!-- #ifdef H5 -->
  5. <image
  6. class="TUI-icon"
  7. @tap="handleEmoji"
  8. src="../../../../assets/icon/emoji.svg"
  9. ></image>
  10. <!-- #endif -->
  11. <!-- #ifndef H5 -->
  12. <image
  13. class="TUI-icon"
  14. @tap="handleSwitchAudio"
  15. src="../../../../assets/icon/audio.svg"
  16. ></image>
  17. <!-- #endif -->
  18. <view v-if="!isAudio" class="TUI-message-input-main">
  19. <textarea
  20. class="TUI-message-input-area"
  21. placeholder-class="input-placeholder"
  22. v-model="inputText"
  23. placeholder="请输入想要咨询的问题..."
  24. auto-height
  25. confirm-type="send"
  26. confirm-hold="true"
  27. @confirm="handleSendTextMessage"
  28. />
  29. </view>
  30. <view v-else class="TUI-message-input-main">
  31. <AudioMessage></AudioMessage>
  32. </view>
  33. <view class="TUI-message-input-functions" hover-class="none">
  34. <image
  35. class="TUI-icon"
  36. @tap="handleEmoji"
  37. src="../../../../assets/icon/emoji.svg"
  38. ></image>
  39. <view @tap="handleExtensions">
  40. <image
  41. class="TUI-icon"
  42. src="../../../../assets/icon/more.svg"
  43. ></image>
  44. </view>
  45. </view>
  46. </view>
  47. <view v-if="displayFlag === 'emoji'" class="TUI-Emoji-area">
  48. <Face
  49. :show="displayFlag === 'emoji'"
  50. @send="handleSend"
  51. @handleSendEmoji="handleSendTextMessage"
  52. ></Face>
  53. </view>
  54. <view v-if="displayFlag === 'extension'" class="TUI-Extensions">
  55. <!-- TODO: 这里功能还没实现
  56. <! <camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>-->
  57. <view class="TUI-Extension-slot" @tap="handleSendImageMessage('camera')">
  58. <image
  59. class="TUI-Extension-icon"
  60. src="../../../../assets/icon/take-photo.svg"
  61. ></image>
  62. <view class="TUI-Extension-slot-name">拍照</view>
  63. </view>
  64. <view class="TUI-Extension-slot" @tap="handleSendImageMessage('album')">
  65. <image
  66. class="TUI-Extension-icon"
  67. src="../../../../assets/icon/send-img.svg"
  68. ></image>
  69. <view class="TUI-Extension-slot-name">图片</view>
  70. </view>
  71. <view class="TUI-Extension-slot" @tap="handleSendVideoMessage('album')">
  72. <image
  73. class="TUI-Extension-icon"
  74. src="../../../../assets/icon/take-video.svg"
  75. ></image>
  76. <view class="TUI-Extension-slot-name">视频</view>
  77. </view>
  78. <view class="TUI-Extension-slot" @tap="handleSendVideoMessage('camera')">
  79. <image
  80. class="TUI-Extension-icon"
  81. src="../../../../assets/icon/take-photo.svg"
  82. ></image>
  83. <view class="TUI-Extension-slot-name">录像</view>
  84. </view>
  85. <!-- #ifndef H5 -->
  86. <view v-if="(imType==1&&orderType==2)||imType==2" class="TUI-Extension-slot" @tap="handleCalling(1)">
  87. <image
  88. class="TUI-Extension-icon"
  89. src="../../../../assets/icon/audio-calling.svg"
  90. ></image>
  91. <view class="TUI-Extension-slot-name">语音通话</view>
  92. </view>
  93. <view v-if="(imType==1&&orderType==2)||imType==2" class="TUI-Extension-slot" @tap="handleCalling(2)">
  94. <image
  95. class="TUI-Extension-icon"
  96. src="../../../../assets/icon/take-video.svg"
  97. ></image>
  98. <view class="TUI-Extension-slot-name">视频通话</view>
  99. </view>
  100. <!-- #endif -->
  101. <view v-if="imType==1" class="TUI-Extension-slot" @tap="handleOrder()">
  102. <image
  103. class="TUI-Extension-icon"
  104. src="../../../../assets/icon/inquiry.svg"
  105. ></image>
  106. <view class="TUI-Extension-slot-name">问诊订单</view>
  107. </view>
  108. <view v-if="imType==2" class="TUI-Extension-slot" @tap="handleFollow()">
  109. <image
  110. class="TUI-Extension-icon"
  111. src="../../../../assets/icon/inquiry.svg"
  112. ></image>
  113. <view class="TUI-Extension-slot-name">随访单</view>
  114. </view>
  115. <view v-if="imType==2" class="TUI-Extension-slot" @tap="handleStoreOrder()">
  116. <image
  117. class="TUI-Extension-icon"
  118. src="../../../../assets/icon/inquiry.svg"
  119. ></image>
  120. <view class="TUI-Extension-slot-name">药品订单</view>
  121. </view>
  122. </view>
  123. </view>
  124. </template>
  125. <script lang="ts">
  126. import {
  127. defineComponent,
  128. watchEffect,
  129. reactive,
  130. toRefs,
  131. onMounted,
  132. computed,
  133. } from "vue";
  134. import Face from "./message/face.vue";
  135. import AudioMessage from "./message/audio.vue";
  136. import store from "@/store";
  137. const TUIChatInput = defineComponent({
  138. components: {
  139. Face,
  140. AudioMessage,
  141. },
  142. props: {
  143. text: {
  144. type: String,
  145. default: () => {
  146. return "";
  147. },
  148. },
  149. conversationData: {
  150. type: Object,
  151. default: () => {
  152. return "";
  153. },
  154. },
  155. },
  156. setup(props) {
  157. const TUIServer: any = uni.$TUIKit.TUIChatServer;
  158. const data = reactive({
  159. imType:computed(() => store.state.timStore.imType),
  160. orderType:computed(() => store.state.timStore.orderType),
  161. firstSendMessage: true,
  162. inputText: "",
  163. extensionArea: false,
  164. sendMessageBtn: false,
  165. displayFlag: "",
  166. isAudio: false,
  167. displayServiceEvaluation: false,
  168. displayCommonWords: false,
  169. displayOrderList: false,
  170. conversation: computed(() => store.state.timStore.conversation),
  171. });
  172. watchEffect(() => {
  173. data.inputText = props.text;
  174. });
  175. const handleSwitchAudio = () => {
  176. data.isAudio = !data.isAudio;
  177. };
  178. const handleEmoji = () => {
  179. data.displayFlag = data.displayFlag === "emoji" ? "" : "emoji";
  180. };
  181. const handleExtensions = (e: any) => {
  182. data.displayFlag = data.displayFlag === "extension" ? "" : "extension";
  183. };
  184. // 发送消息
  185. const handleSendTextMessage = (e: any) => {
  186. if (data.inputText.trimEnd()) {
  187. uni.$TUIKit.TUIChatServer.sendTextMessage(
  188. JSON.parse(JSON.stringify(data.inputText))
  189. );
  190. }
  191. data.inputText = " ";
  192. };
  193. const handleOrder = (value: any) => {
  194. uni.navigateTo({
  195. url: '/pages_order/inquiryOrderDetails?orderId='+store.state.timStore.orderId
  196. })
  197. };
  198. const handleFollow = (value: any) => {
  199. uni.navigateTo({
  200. url: '/pages_user/followDetails?followId='+store.state.timStore.followId
  201. })
  202. };
  203. const handleStoreOrder = (value: any) => {
  204. uni.navigateTo({
  205. url: '/pages_order/storeOrderDetail?orderId='+store.state.timStore.orderId
  206. })
  207. };
  208. // 处理需要合并的数据
  209. const handleSend = (emo: any) => {
  210. data.inputText += emo.name;
  211. // inputEle.value.focus();
  212. };
  213. const handleSendImageMessage = (type: any) => {
  214. uni.chooseImage({
  215. sourceType: [type],
  216. count: 1,
  217. success: (res) => {
  218. uni.getImageInfo({
  219. src: res.tempFilePaths[0],
  220. success(image) {
  221. console.error(image);
  222. setTimeout(function(){
  223. TUIServer.sendImageMessage(res, image);
  224. },500);
  225. },
  226. });
  227. },
  228. });
  229. };
  230. const handleSendVideoMessage = (type: any) => {
  231. uni.chooseVideo({
  232. sourceType: [type],
  233. // 来源相册或者拍摄
  234. maxDuration: 60,
  235. // 设置最长时间60s
  236. camera: "back",
  237. // 后置摄像头
  238. success: (res) => {
  239. if (res) {
  240. setTimeout(function(){
  241. TUIServer.sendVideoMessage(res);
  242. },500);
  243. }
  244. },
  245. });
  246. };
  247. const handleCalling = (value: any) => {
  248. // todo 目前支持单聊
  249. if (data.conversation.type === "GROUP") {
  250. uni.showToast({
  251. title: "群聊暂不支持",
  252. icon: "none",
  253. });
  254. return;
  255. }
  256. const { userID } = data.conversation.userProfile;
  257. // #ifdef APP-PLUS
  258. if (typeof uni.$TUICallKit === "undefined") {
  259. console.error(
  260. "请集成 TUICallKit 插件,使用真机运行并且自定义基座调试,请参考官网文档:https://cloud.tencent.com/document/product/269/83857"
  261. );
  262. uni.showToast({
  263. title: "请集成 TUICallKit 插件哦 ~ ",
  264. icon: "none",
  265. duration: 3000,
  266. });
  267. } else {
  268. uni.$TUICallKit.call(
  269. {
  270. userID: userID,
  271. callMediaType: value,
  272. },
  273. (res) => {
  274. console.log(JSON.stringify(res));
  275. }
  276. );
  277. }
  278. // #endif
  279. // #ifdef MP-WEIXIN
  280. if (typeof uni.$TUICallKit !== "undefined" && uni.$TUICallKit.value !== null) {
  281. console.log(uni.$TUICallKit)
  282. uni.$TUICallKit.value.call({
  283. userID: userID,
  284. type: value
  285. })
  286. } else {
  287. console.error(
  288. "请集成 TUICallKit 插件哦~,请参考官网文档:https://cloud.tencent.com/document/product/269/83858"
  289. );
  290. uni.showToast({
  291. title: "请集成 TUICallKit 插件哦 ~ ",
  292. icon: "none",
  293. duration: 3000,
  294. });
  295. }
  296. // #endif
  297. // #ifdef H5
  298. uni.showToast({
  299. title: "暂不支持",
  300. icon: "none",
  301. });
  302. // #endif
  303. };
  304. return {
  305. ...toRefs(data),
  306. handleExtensions,
  307. handleSendImageMessage,
  308. handleSendTextMessage,
  309. handleSendVideoMessage,
  310. handleEmoji,
  311. handleSend,
  312. handleSwitchAudio,
  313. handleCalling,
  314. handleOrder,
  315. handleFollow,
  316. handleStoreOrder
  317. };
  318. },
  319. });
  320. export default TUIChatInput;
  321. </script>
  322. <style lang="scss" scoped>
  323. .TUI-message-input-container {
  324. background-color: #f1f1f1;
  325. padding-bottom: 20rpx;
  326. }
  327. .TUI-message-input {
  328. display: flex;
  329. padding: 16rpx;
  330. background-color: #f1f1f1;
  331. width: 100vw;
  332. }
  333. .TUI-commom-function {
  334. display: flex;
  335. flex-wrap: nowrap;
  336. width: 750rpx;
  337. height: 106rpx;
  338. background-color: #f1f1f1;
  339. align-items: center;
  340. }
  341. .TUI-commom-function-item {
  342. display: flex;
  343. width: 136rpx;
  344. justify-content: center;
  345. align-items: center;
  346. font-size: 24rpx;
  347. color: #ffffff;
  348. height: 48rpx;
  349. margin-left: 16rpx;
  350. border-radius: 24rpx;
  351. background-color: #00c8dc;
  352. }
  353. .TUI-commom-function-item:first-child {
  354. margin-left: 48rpx;
  355. }
  356. .TUI-message-input-functions {
  357. display: flex;
  358. }
  359. .TUI-message-input-main {
  360. background-color: #fff;
  361. flex: 1;
  362. min-height: 66rpx;
  363. margin: 0 10rpx;
  364. padding: 0 5rpx;
  365. border-radius: 5rpx;
  366. display: flex;
  367. align-items: center;
  368. }
  369. .TUI-message-input-area {
  370. width: 100%;
  371. height: 100%;
  372. }
  373. .TUI-icon {
  374. width: 56rpx;
  375. height: 56rpx;
  376. margin: 0 16rpx;
  377. }
  378. .TUI-Extensions {
  379. display: flex;
  380. width: 100%;
  381. overflow-y: scroll;
  382. flex-wrap: wrap;
  383. width: 100vw;
  384. height: 400rpx;
  385. margin-left: 14rpx;
  386. margin-right: 14rpx;
  387. }
  388. .TUI-Extension-slot {
  389. width: 128rpx;
  390. height: 170rpx;
  391. margin-left: 26rpx;
  392. margin-right: 26rpx;
  393. margin-top: 24rpx;
  394. }
  395. .TUI-Extension-icon {
  396. width: 128rpx;
  397. height: 128rpx;
  398. }
  399. .TUI-sendMessage-btn {
  400. display: flex;
  401. align-items: center;
  402. margin: 0 10rpx;
  403. }
  404. .TUI-Emoji-area {
  405. width: 100vw;
  406. height: 450rpx;
  407. }
  408. .TUI-Extension-slot-name {
  409. line-height: 34rpx;
  410. font-size: 24rpx;
  411. color: #333333;
  412. letter-spacing: 0;
  413. text-align: center;
  414. }
  415. .record-modal {
  416. height: 300rpx;
  417. width: 60vw;
  418. background-color: #000;
  419. opacity: 0.8;
  420. position: fixed;
  421. top: 670rpx;
  422. z-index: 9999;
  423. left: 20vw;
  424. border-radius: 24rpx;
  425. display: flex;
  426. flex-direction: column;
  427. }
  428. .record-modal .wrapper {
  429. display: flex;
  430. height: 200rpx;
  431. box-sizing: border-box;
  432. padding: 10vw;
  433. }
  434. .record-modal .wrapper .modal-loading {
  435. opacity: 1;
  436. width: 40rpx;
  437. height: 16rpx;
  438. border-radius: 4rpx;
  439. background-color: #006fff;
  440. animation: loading 2s cubic-bezier(0.17, 0.37, 0.43, 0.67) infinite;
  441. }
  442. .modal-title {
  443. text-align: center;
  444. color: #fff;
  445. }
  446. @keyframes loading {
  447. 0% {
  448. transform: translate(0, 0);
  449. }
  450. 50% {
  451. transform: translate(30vw, 0);
  452. background-color: #f5634a;
  453. width: 40px;
  454. }
  455. 100% {
  456. transform: translate(0, 0);
  457. }
  458. }
  459. </style>