Browse Source

修改添加

lex 1 year ago
parent
commit
563b3ba7d4

+ 12 - 0
src/App.vue

@@ -57,6 +57,7 @@ import { useStore } from "vuex";
 // import DialogTUI from "../../components/dialogTUi/index.vue";
 import DialogTUI from "./TUIKit/TUIComponents/components/dialogTUi/index.vue";
 import { SDKAppID, secretKey, userID } from "./main.ts";
+import { eventGlobal } from "./helpers";
 
 export default defineComponent({
   components: {
@@ -102,6 +103,7 @@ export default defineComponent({
     const onKiicedOut = (e?: any) => {
       data.dialogShow = true;
       data.disconnectStatus = true;
+      store?.commit("setImConnent", false);
     };
 
     const handleManage = () => {
@@ -116,16 +118,26 @@ export default defineComponent({
       })
         .then(() => {
           data.disconnectStatus = false;
+          store?.commit("setImConnent", true);
         })
         .catch(() => {
           data.disconnentContent = "连接失败,请重试";
           data.disconnectBtnText = "重新连接";
+          store?.commit("setImConnent", false);
         });
     };
 
     onMounted(() => {
       /** 账号被挤下线 */
       TUIKit.tim.on(TUIKit.TIM.EVENT.KICKED_OUT, (e: any) => onKiicedOut(e));
+
+      eventGlobal.on("reConnectIm", (state: boolean) => {
+        if (state) {
+          data.dialogShow = true;
+          data.disconnectStatus = true;
+          store?.commit("setImConnent", false);
+        }
+      });
     });
 
     onUnmounted(() => {

+ 9 - 1
src/TUIKit/TUIComponents/container/TUIChat/message-input/index.vue

@@ -27,6 +27,8 @@ import MessageInputButton from "./message-input-button.vue";
 import MessageInputReferenceOrReply from "./message-input-reference-or-reply.vue";
 import { JSONToObject } from "../utils/utils";
 import { handleErrorPrompts } from "../../utils";
+import { useStore } from "vuex";
+import { eventGlobal } from "@/helpers";
 
 const props = defineProps({
   placeholder: {
@@ -83,7 +85,7 @@ const emit = defineEmits(["sendMessage", "resetReplyOrReference", "onTyping"]);
 const { placeholder, isGroup, memberList, conversation, replyOrReference, env, enableTyping } = toRefs(props);
 const editor = ref();
 const isH5 = ref(props?.env?.isH5);
-
+const store = useStore && useStore();
 watch(
   () => conversation.value,
   (newVal: any, oldVal: any) => {
@@ -98,6 +100,12 @@ watch(
 );
 
 const sendMessage = async () => {
+  console.log(store.state.imConnent, "store.imConnent");
+  if (!store.state.imConnent) {
+    eventGlobal.emit("reConnectIm", true);
+    return;
+  }
+
   const TUIServer = (window as any)?.TUIKitTUICore?.TUIServer?.TUIChat;
   const messageList = editor?.value?.getEditorContent();
   const replyOrReferenceObject = replyOrReference.value;

+ 4 - 0
src/storex/index.ts

@@ -42,6 +42,7 @@ const state: any = {
   taskList,
   userInfo: {},
   platform: "classroom", // 平台
+  imConnent: true, // IM是否连接
   token: "", //
   isMsgNeedReadReceipt: true,
   displayOnlineStatus: true,
@@ -131,6 +132,9 @@ export default createStore({
       state.platform = platform;
       sessionStorage.setItem("platform", platform);
     },
+    setImConnent(state: any, connent: boolean) {
+      state.imConnent = connent;
+    },
   },
   actions: {},
   modules: {},