index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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/store/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/store/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. // #ifdef APP-PLUS
  215. if(!plus.runtime.isAgreePrivacy()) {
  216. uni.showToast({title: "请同意隐私政策",icon: "none"});
  217. return;
  218. }
  219. // #endif
  220. uni.chooseImage({
  221. sourceType: [type],
  222. count: 1,
  223. success: (res) => {
  224. uni.getImageInfo({
  225. src: res.tempFilePaths[0],
  226. success(image) {
  227. console.error(image);
  228. setTimeout(function(){
  229. TUIServer.sendImageMessage(res, image);
  230. },500);
  231. },
  232. });
  233. },
  234. });
  235. };
  236. const handleSendVideoMessage = (type: any) => {
  237. // #ifdef APP-PLUS
  238. if(!plus.runtime.isAgreePrivacy()) {
  239. uni.showToast({title: "请同意隐私政策",icon: "none"});
  240. return;
  241. }
  242. // #endif
  243. uni.chooseVideo({
  244. sourceType: [type],
  245. // 来源相册或者拍摄
  246. maxDuration: 60,
  247. // 设置最长时间60s
  248. camera: "back",
  249. // 后置摄像头
  250. success: (res) => {
  251. if (res) {
  252. setTimeout(function(){
  253. TUIServer.sendVideoMessage(res);
  254. },500);
  255. }
  256. },
  257. });
  258. };
  259. const handleCalling = (value: any) => {
  260. // todo 目前支持单聊
  261. if (data.conversation.type === "GROUP") {
  262. uni.showToast({
  263. title: "群聊暂不支持",
  264. icon: "none",
  265. });
  266. return;
  267. }
  268. const { userID } = data.conversation.userProfile;
  269. // #ifdef APP-PLUS
  270. if (typeof uni.$TUICallKit === "undefined") {
  271. console.error(
  272. "请集成 TUICallKit 插件,使用真机运行并且自定义基座调试,请参考官网文档:https://cloud.tencent.com/document/product/269/83857"
  273. );
  274. uni.showToast({
  275. title: "请集成 TUICallKit 插件哦 ~ ",
  276. icon: "none",
  277. duration: 3000,
  278. });
  279. } else {
  280. uni.$TUICallKit.call(
  281. {
  282. userID: userID,
  283. callMediaType: value,
  284. },
  285. (res) => {
  286. console.log(JSON.stringify(res));
  287. }
  288. );
  289. }
  290. // #endif
  291. // #ifdef MP-WEIXIN
  292. if (typeof uni.$TUICallKit !== "undefined" && uni.$TUICallKit.value !== null) {
  293. console.log(uni.$TUICallKit)
  294. uni.$TUICallKit.value.call({
  295. userID: userID,
  296. type: value
  297. })
  298. } else {
  299. console.error(
  300. "请集成 TUICallKit 插件哦~,请参考官网文档:https://cloud.tencent.com/document/product/269/83858"
  301. );
  302. uni.showToast({
  303. title: "请集成 TUICallKit 插件哦 ~ ",
  304. icon: "none",
  305. duration: 3000,
  306. });
  307. }
  308. // #endif
  309. // #ifdef H5
  310. uni.showToast({
  311. title: "暂不支持",
  312. icon: "none",
  313. });
  314. // #endif
  315. };
  316. return {
  317. ...toRefs(data),
  318. handleExtensions,
  319. handleSendImageMessage,
  320. handleSendTextMessage,
  321. handleSendVideoMessage,
  322. handleEmoji,
  323. handleSend,
  324. handleSwitchAudio,
  325. handleCalling,
  326. handleOrder,
  327. handleFollow,
  328. handleStoreOrder
  329. };
  330. },
  331. });
  332. export default TUIChatInput;
  333. </script>
  334. <style lang="scss" scoped>
  335. .TUI-message-input-container {
  336. background-color: #f1f1f1;
  337. padding-bottom: 20rpx;
  338. }
  339. .TUI-message-input {
  340. display: flex;
  341. padding: 16rpx;
  342. background-color: #f1f1f1;
  343. width: 100vw;
  344. }
  345. .TUI-commom-function {
  346. display: flex;
  347. flex-wrap: nowrap;
  348. width: 750rpx;
  349. height: 106rpx;
  350. background-color: #f1f1f1;
  351. align-items: center;
  352. }
  353. .TUI-commom-function-item {
  354. display: flex;
  355. width: 136rpx;
  356. justify-content: center;
  357. align-items: center;
  358. font-size: 24rpx;
  359. color: #ffffff;
  360. height: 48rpx;
  361. margin-left: 16rpx;
  362. border-radius: 24rpx;
  363. background-color: #00c8dc;
  364. }
  365. .TUI-commom-function-item:first-child {
  366. margin-left: 48rpx;
  367. }
  368. .TUI-message-input-functions {
  369. display: flex;
  370. }
  371. .TUI-message-input-main {
  372. background-color: #fff;
  373. flex: 1;
  374. min-height: 66rpx;
  375. margin: 0 10rpx;
  376. padding: 0 5rpx;
  377. border-radius: 5rpx;
  378. display: flex;
  379. align-items: center;
  380. }
  381. .TUI-message-input-area {
  382. width: 100%;
  383. height: 100%;
  384. }
  385. .TUI-icon {
  386. width: 56rpx;
  387. height: 56rpx;
  388. margin: 0 16rpx;
  389. }
  390. .TUI-Extensions {
  391. display: flex;
  392. width: 100%;
  393. overflow-y: scroll;
  394. flex-wrap: wrap;
  395. width: 100vw;
  396. height: 400rpx;
  397. margin-left: 14rpx;
  398. margin-right: 14rpx;
  399. }
  400. .TUI-Extension-slot {
  401. width: 128rpx;
  402. height: 170rpx;
  403. margin-left: 26rpx;
  404. margin-right: 26rpx;
  405. margin-top: 24rpx;
  406. }
  407. .TUI-Extension-icon {
  408. width: 128rpx;
  409. height: 128rpx;
  410. }
  411. .TUI-sendMessage-btn {
  412. display: flex;
  413. align-items: center;
  414. margin: 0 10rpx;
  415. }
  416. .TUI-Emoji-area {
  417. width: 100vw;
  418. height: 450rpx;
  419. }
  420. .TUI-Extension-slot-name {
  421. line-height: 34rpx;
  422. font-size: 24rpx;
  423. color: #333333;
  424. letter-spacing: 0;
  425. text-align: center;
  426. }
  427. .record-modal {
  428. height: 300rpx;
  429. width: 60vw;
  430. background-color: #000;
  431. opacity: 0.8;
  432. position: fixed;
  433. top: 670rpx;
  434. z-index: 9999;
  435. left: 20vw;
  436. border-radius: 24rpx;
  437. display: flex;
  438. flex-direction: column;
  439. }
  440. .record-modal .wrapper {
  441. display: flex;
  442. height: 200rpx;
  443. box-sizing: border-box;
  444. padding: 10vw;
  445. }
  446. .record-modal .wrapper .modal-loading {
  447. opacity: 1;
  448. width: 40rpx;
  449. height: 16rpx;
  450. border-radius: 4rpx;
  451. background-color: #006fff;
  452. animation: loading 2s cubic-bezier(0.17, 0.37, 0.43, 0.67) infinite;
  453. }
  454. .modal-title {
  455. text-align: center;
  456. color: #fff;
  457. }
  458. @keyframes loading {
  459. 0% {
  460. transform: translate(0, 0);
  461. }
  462. 50% {
  463. transform: translate(30vw, 0);
  464. background-color: #f5634a;
  465. width: 40px;
  466. }
  467. 100% {
  468. transform: translate(0, 0);
  469. }
  470. }
  471. </style>