App.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div :class="['home']" :id="'preloadedImages'">
  3. <main class="home-main">
  4. <div class="home-main-box">
  5. <div class="home-TUIKit">
  6. <div class="home-TUIKit-main">
  7. <div class="conversation">
  8. <n-tabs
  9. style="padding-left: 22px; --n-tab-padding: 6px 0; --n-tab-gap: 34px; --n-tab-text-color: #000; --n-tab-text-color-hover: #0f0f0f; --n-tab-text-color-active: #000; --n-tab-font-weight-active: 600; padding-top: 6px; --n-bar-color: #198cfe"
  10. :bar-width="20"
  11. :value="currentModel"
  12. @update:value="
  13. (val: any) => {
  14. currentModel = val;
  15. }
  16. "
  17. >
  18. <n-tab-pane name="message" tab="聊天"></n-tab-pane>
  19. <n-tab-pane name="group" tab="群聊" v-if="platform != 'orchestra'"></n-tab-pane>
  20. <n-tab-pane name="contact" tab="联系人" v-if="platform != 'orchestra'"></n-tab-pane>
  21. </n-tabs>
  22. <TUIConversation v-show="currentModel === 'message'" @current="handleCurrentConversation" :displayOnlineStatus="displayOnlineStatus" />
  23. <TUIGroup v-if="platform != 'orchestra' && currentModel === 'group'" @current="handleCurrentConversation" :displayOnlineStatus="displayOnlineStatus" />
  24. <TUIPerson v-if="platform != 'orchestra' && currentModel === 'contact'" @current="handleCurrentConversation" :displayOnlineStatus="displayOnlineStatus" />
  25. <div class="imDisconnent" v-if="disconnectStatus">
  26. <p>
  27. <img src="./assets/icon-tips.png" class="iconTips" />
  28. {{ disconnentContent }}
  29. </p>
  30. <span class="btnConnent" @click="dialogShow = true">{{ disconnectBtnText }}</span>
  31. </div>
  32. </div>
  33. <div class="chat">
  34. <TUIChat :isMsgNeedReadReceipt="isMsgNeedReadReceipt" :isNeedTyping="true" :isNeedEmojiReact="true">
  35. <div class="chat-default"></div>
  36. </TUIChat>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. </main>
  42. <i class="closeModal" @click="onClose"></i>
  43. <DialogTUI :show="dialogShow" :isHeaderShow="true" title="提示" :is-footer-show="true" @submit="handleManage()" @update:show="(e) => (dialogShow = e)">
  44. <p>聊天功能已断开,是否重新连接?</p>
  45. </DialogTUI>
  46. </div>
  47. </template>
  48. <script lang="ts">
  49. import { computed, defineComponent, getCurrentInstance, onMounted, onUnmounted, reactive, toRefs } from "vue";
  50. // import { useI18nLocale } from '../../TUIKit/TUIPlugin/TUIi18n';
  51. import { genTestUserSig } from "./TUIKit";
  52. import { useStore } from "vuex";
  53. // import DialogTUI from "../../components/dialogTUi/index.vue";
  54. import DialogTUI from "./TUIKit/TUIComponents/components/dialogTUi/index.vue";
  55. import { SDKAppID, secretKey, userID } from "./main.ts";
  56. import { eventGlobal } from "./helpers";
  57. export default defineComponent({
  58. components: {
  59. DialogTUI,
  60. },
  61. setup(props, context) {
  62. const instance = getCurrentInstance();
  63. // const locale = useI18nLocale();
  64. const TUIKit: any = instance?.appContext.config.globalProperties.$TUIKit;
  65. const store = useStore && useStore();
  66. // const taskList = computed(() => store.state.taskList);
  67. // const dragRef = ref();
  68. const isMsgNeedReadReceipt = computed(() => JSON.parse(store.state.isMsgNeedReadReceipt));
  69. const displayOnlineStatus = computed(() => JSON.parse(store.state.displayOnlineStatus));
  70. const data = reactive({
  71. currentConversationID: "",
  72. currentModel: "message",
  73. platform: sessionStorage.getItem("platform"), // 平台
  74. // env: TUIKit.TUIEnv
  75. disconnectStatus: false, // 是否断开链接
  76. disconnentContent: "聊天功能已断开,是否重新连接?",
  77. disconnectBtnText: "连接",
  78. dialogShow: false,
  79. });
  80. const onClose = () => {
  81. if (window.parent) {
  82. window.parent.postMessage(
  83. {
  84. api: "onImClose",
  85. },
  86. "*"
  87. );
  88. }
  89. };
  90. const handleCurrentConversation = (value: string) => {
  91. data.currentModel = "message";
  92. data.currentConversationID = value;
  93. };
  94. /** 账号被挤下线 */
  95. const onKiicedOut = (e?: any) => {
  96. data.dialogShow = true;
  97. data.disconnectStatus = true;
  98. store?.commit("setImConnent", false);
  99. };
  100. const handleManage = () => {
  101. console.log("manage", userID);
  102. TUIKit.login({
  103. userID: userID,
  104. userSig: genTestUserSig({
  105. SDKAppID,
  106. secretKey,
  107. userID,
  108. }).userSig, // The password with which the user logs in to IM. It is the ciphertext generated by encrypting information such as userID.For the detailed generation method, see Generating UserSig
  109. })
  110. .then(() => {
  111. data.disconnectStatus = false;
  112. store?.commit("setImConnent", true);
  113. })
  114. .catch(() => {
  115. data.disconnentContent = "连接失败,请重试";
  116. data.disconnectBtnText = "重新连接";
  117. store?.commit("setImConnent", false);
  118. });
  119. };
  120. onMounted(() => {
  121. /** 账号被挤下线 */
  122. TUIKit.tim.on(TUIKit.TIM.EVENT.KICKED_OUT, (e: any) => onKiicedOut(e));
  123. eventGlobal.on("reConnectIm", (state: boolean) => {
  124. if (state) {
  125. data.dialogShow = true;
  126. data.disconnectStatus = true;
  127. store?.commit("setImConnent", false);
  128. }
  129. });
  130. });
  131. onUnmounted(() => {
  132. TUIKit.tim.off(TUIKit.TIM.EVENT.KICKED_OUT, onKiicedOut);
  133. });
  134. return {
  135. ...toRefs(data),
  136. // dragRef,
  137. // taskList,
  138. handleCurrentConversation,
  139. isMsgNeedReadReceipt,
  140. displayOnlineStatus,
  141. onClose,
  142. handleManage,
  143. };
  144. },
  145. });
  146. </script>
  147. <style scoped lang="scss" src="./index.scss"></style>