index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <Dialog
  3. :visible="showDialog"
  4. :styleConfig="styleConfig"
  5. :handleClose="handleClose"
  6. >
  7. <view
  8. v-for="(item, index) in chatList"
  9. :key="index"
  10. class="chat-container"
  11. @click.stop="handleContentClick(item)"
  12. >
  13. <image
  14. class="item-icon"
  15. v-if="item.imgType === 'SINGLE'"
  16. src="../../assets/icon/singlePerson.svg"
  17. />
  18. <image class="item-icon" v-else src="../../assets/icon/multiPerson.svg" />
  19. <view>{{ item.content }}</view>
  20. </view>
  21. </Dialog>
  22. <view class="TUI-conversation">
  23. <!-- <view class="create-group" @click="handleShow"> + 发起聊天</view> -->
  24. <TUIConversationList
  25. :currentID="currrentConversationID"
  26. :conversationList="conversationList"
  27. @handleGotoItem="handleCurrrentConversation"
  28. />
  29. </view>
  30. </template>
  31. <script lang="ts">
  32. import { defineComponent, reactive, toRefs, computed, onMounted } from "vue";
  33. import { onNavigationBarButtonTap, onShow, onUnload } from "@dcloudio/uni-app";
  34. import TUIConversationList from "./conversation-list";
  35. import Dialog from "./components/dialog.vue";
  36. import store from "@/store";
  37. import { TUIConversationServer, TUIProfileServer } from "../../TUICore/server";
  38. import {getOrderIdByIm} from '@/api/inquiryOrder.js'
  39. const TUIConversation = defineComponent({
  40. name: "TUIConversation",
  41. components: {
  42. TUIConversationList,
  43. Dialog,
  44. },
  45. setup(props) {
  46. const timStore = store.state.timStore;
  47. // uni.$TUIKit.TUIConversationServer = new TUIConversationServer();
  48. // uni.$TUIKit.TUIProfileServer = new TUIProfileServer();
  49. // const { t } = uni.$TUIKit.config.i18n.useI18n();
  50. const data: any = reactive({
  51. conversationList: computed(() => timStore.conversationList),
  52. currrentConversationID: "",
  53. open: false,
  54. searchUserID: "",
  55. selectedList: [],
  56. searchUserList: [],
  57. step: 1,
  58. showDialog: false,
  59. item: {
  60. flow: "out",
  61. status: "success",
  62. },
  63. styleConfig: {
  64. width: "150px",
  65. // height: '160px',
  66. padding: "16px 16px 0px",
  67. top: "8px",
  68. right: "8px",
  69. },
  70. chatList: [
  71. {
  72. imgType: "SINGLE",
  73. type: uni.$TIM.TYPES.CONV_C2C,
  74. id: 1,
  75. content: "发起会话",
  76. },
  77. {
  78. imgType: "GROUP",
  79. type: uni.$TIM.TYPES.GRP_WORK,
  80. id: 1,
  81. content: "工作群",
  82. },
  83. {
  84. imgType: "GROUP",
  85. type: uni.$TIM.TYPES.GRP_PUBLIC,
  86. id: 2,
  87. content: "社交群",
  88. },
  89. {
  90. imgType: "GROUP",
  91. type: uni.$TIM.TYPES.GRP_MEETING,
  92. id: 3,
  93. content: "会议群",
  94. },
  95. ],
  96. });
  97. onUnload(() => {
  98. uni.$TUIKit.TUIConversationServer.destroyed();
  99. });
  100. onNavigationBarButtonTap(() => {
  101. data.showDialog = !data.showDialog;
  102. });
  103. onShow(() => {
  104. uni.$emit('refreshIM');
  105. store.commit("timStore/setConversationID", "");
  106. });
  107. // 切换当前会话
  108. const handleCurrrentConversation = (value: any) => {
  109. if(value.lastMessage.cloudCustomData!=null){
  110. try{
  111. var json=JSON.parse(value.lastMessage.cloudCustomData)
  112. store.commit("timStore/setImType", json.imType);
  113. store.commit("timStore/setOrderType", json.orderType);
  114. store.commit("timStore/setOrderId", json.orderId);
  115. store.commit("timStore/setFollowId", json.followId);
  116. store.commit("timStore/setType", json.type);
  117. }
  118. catch(e){
  119. }
  120. }
  121. data.currrentConversationID = value.conversationID;
  122. store.commit("timStore/setConversationID", value.conversationID);
  123. //uni.$TUIKit.TUIChatServer.updateStore(value.conversationID)
  124. uni.navigateTo({
  125. url: `../TUIChat/index?conversationName=${handleItemName(value)}`,
  126. });
  127. uni.$TUIKit.TUIConversationServer.setMessageRead(value.conversationID);
  128. const curConversation = data.conversationList.filter((item: any) => {
  129. return item.conversationID === value.conversationID;
  130. });
  131. store.commit("timStore/setConversation", curConversation);
  132. uni.$TUIKit.TUIConversationServer.getConversationProfile(
  133. value.conversationID
  134. ).then((res: any) => {
  135. // 通知 TUIChat 关闭当前会话
  136. store.commit("timStore/setConversation", res.data.conversation);
  137. // uni.$TUIKit.getStore()['TUIChat'].conversation = res.data.conversation;
  138. });
  139. };
  140. const handleShow = () => {
  141. data.showDialog = true;
  142. };
  143. // dialog 内部有效区域点击
  144. const handleContentClick = (item) => {
  145. data.showDialog = false;
  146. uni.navigateTo({
  147. url: `../TUIConversation/create?title=${item.content}&type=${item.type}`,
  148. });
  149. };
  150. // 关闭 dialog
  151. const handleClose = () => {
  152. data.showDialog = false;
  153. };
  154. const handleItemName = (item: any) => {
  155. let name = "";
  156. switch (item.type) {
  157. case uni.$TIM.TYPES.CONV_C2C:
  158. name = item?.userProfile.nick || item?.userProfile?.userID || "";
  159. break;
  160. case uni.$TIM.TYPES.CONV_GROUP:
  161. name = item.groupProfile.name || item?.groupProfile?.groupID || "";
  162. break;
  163. case uni.$TIM.TYPES.CONV_SYSTEM:
  164. name = "系统通知";
  165. break;
  166. }
  167. return name;
  168. };
  169. return {
  170. ...toRefs(data),
  171. handleCurrrentConversation,
  172. handleContentClick,
  173. handleItemName,
  174. handleClose,
  175. handleShow,
  176. };
  177. },
  178. });
  179. export default TUIConversation;
  180. </script>
  181. <style lang="scss" scoped>
  182. .TUI-conversation {
  183. .create-group {
  184. font-weight: 800px;
  185. padding: 10px;
  186. font-size: 14px;
  187. text-align: center;
  188. }
  189. }
  190. .chat-container {
  191. display: flex;
  192. align-items: center;
  193. margin-bottom: 16px;
  194. color: #444444;
  195. .item-icon {
  196. display: inline-block;
  197. width: 21px;
  198. height: 21px;
  199. margin-right: 12px;
  200. }
  201. }
  202. </style>