liming 1 週間 前
コミット
74b10a9267
7 ファイル変更91 行追加38 行削除
  1. 5 2
      .env
  2. 23 4
      src/App.vue
  3. 2 2
      src/api/path/im.api.js
  4. 1 2
      src/main.js
  5. 6 3
      src/stores/modules/webSocketStore.js
  6. 51 18
      src/views/im/chat/index.vue
  7. 3 7
      src/views/im/index.vue

+ 5 - 2
.env

@@ -8,7 +8,10 @@ VITE_DEV_PATH='https://wallet.angeltokens.io'
 VITE_PRO_PATH='https://wallet.angeltokens.io'
 
 
-VITE_PRO_IM_PATH='https://nim.angeltokens.io'
-VITE_DEV_IM_PATH='https://nim.angeltokens.io'#https://nim.angeltokens.io
+# VITE_PRO_IM_PATH='https://nim.angeltokens.io'
+# VITE_DEV_IM_PATH='https://nim.angeltokens.io'#https://nim.angeltokens.io
+
+VITE_PRO_IM_PATH='http://192.168.0.59:8888'
+VITE_DEV_IM_PATH='http://192.168.0.59:8888'
 
 VITE_PRO_BACKEND_PATH='https://backend.angeltoken.net'

+ 23 - 4
src/App.vue

@@ -15,11 +15,16 @@
 <script setup>
 import { checkAndUpdate } from "@/updater/index";
 import { getNotchHeight } from "@/utils/statusBar";
-import { setupNotifications } from '@/utils/notifications.js';
+import { setupNotifications } from "@/utils/notifications.js";
+import { useWalletStore } from "@/stores/modules/walletStore";
+import { useWebSocketStore } from "@/stores/modules/webSocketStore.js";
 
 const route = useRoute();
 const router = useRouter();
 
+const walletStore = useWalletStore();
+const wsStore = useWebSocketStore();
+
 const height = ref(0);
 const notchStyle = ref({});
 
@@ -60,7 +65,6 @@ onBeforeMount(async () => {
 });
 
 onMounted(() => {
-  
   // 0.5秒后执行
   // setTimeout(() => {
   //    setupNotifications(2);
@@ -74,7 +78,6 @@ onMounted(() => {
   //  setTimeout(() => {
   //    setupNotifications(5);
   // }, 500);
-
   //  setTimeout(() => {
   //    setupNotifications(5);
   // }, 2500);
@@ -82,7 +85,23 @@ onMounted(() => {
   //    setupNotifications(15);
   // }, 1500);
   // setupNotifications(5);
-  // setupNotifications(6); 
+  // setupNotifications(6);
+});
+
+watch(
+  () => walletStore.account,
+  (val) => {
+    if (val) {
+      wsStore.connect(walletStore.getAccount);
+    }
+  },
+  {
+    immediate: true, // 默认立即执行
+  }
+);
+
+onUnmounted(() => {
+  wsStore.close();
 });
 </script>
 

+ 2 - 2
src/api/path/im.api.js

@@ -18,7 +18,7 @@ export function userInfoEdit(param) {
 
 // 获取用户列表 
 export function userList(params) {
-  return service.post('user', params);
+  return service.get('user', { params});
 }
 
 // 添加好友
@@ -33,7 +33,7 @@ export function userUuid(uuid) {
 
 // 获取消息
 export function getmessage(params) {
-  return service.get('message', { params });
+  return service.post('message', { params });
 }
 
 // 获取好友申请审核列表

+ 1 - 2
src/main.js

@@ -6,7 +6,6 @@ import { setupStore } from "@/stores";
 // ui 
 import Vant, { Lazyload } from 'vant';
 import 'vant/lib/index.css';
-
 // 
 
 // 字体
@@ -46,5 +45,5 @@ async function appInit() {
 
 
 appInit().then(() => {
-
+  
 })

+ 6 - 3
src/stores/modules/webSocketStore.js

@@ -3,9 +3,12 @@ import { defineStore } from 'pinia'
 import { ref } from 'vue' 
 import { $root as protobuf } from '@/common/proto/proto'
 import * as Constant from '@/common/constant/Constant'
+import { useWalletStore } from "@/stores/modules/walletStore";
 
 //  MessageType = $root.lookupType("protocol.Message");
 
+
+
 export const useWebSocketStore = defineStore('webSocketStore', () => {
   const socket = ref(null) // 创建WebSocket对象
   const peer = ref(null) // 创建RTCPeerConnection对象
@@ -149,11 +152,11 @@ export const useWebSocketStore = defineStore('webSocketStore', () => {
   // 发送消息
   const sendMessage = (messageData) => {
     if (!socket.value) return
-    
+    const walletStore = useWalletStore()
     const data = {
       ...messageData,
-      fromUsername: localStorage.username,
-      from: localStorage.uuid,
+      fromUsername: walletStore.username,
+      from: walletStore.account,
     }
     
     const message = protobuf.lookup("protocol.Message")

+ 51 - 18
src/views/im/chat/index.vue

@@ -1,9 +1,12 @@
 <template>
-  <div class="container" :style="{height: `calc(100% - ${currentBottomHeight}px)`}"> 
+  <div
+    class="container"
+    :style="{ height: `calc(100% - ${currentBottomHeight}px)` }"
+  >
     <div class="chat-bg"></div>
     <div class="header-chat">
       <svg-icon class="page-icon" name="lf-arrow" @click="goBack" />
-      <div class="header-title">群聊2(8) </div>
+      <div class="header-title">群聊2(8)</div>
       <svg-icon class="page-icon" name="more" @click="goDetail" />
     </div>
     <div class="chat-list">
@@ -58,20 +61,32 @@
           class="input"
           v-model="text"
           @focus="onFocus"
-          placeholder="输入文本" 
+          placeholder="输入文本"
+          @keyup.enter="sendMessage"
         />
-        <svg-icon class="page-icon mr12" name="emoji" @click="toggleAppBox(1)"/>
-        <svg-icon class="page-icon" name="add2" @click="toggleAppBox(2)"/>
+        <svg-icon
+          class="page-icon mr12"
+          name="emoji"
+          @click="toggleAppBox(1)"
+        />
+        <svg-icon class="page-icon" name="add2" @click="toggleAppBox(2)" />
       </div>
-      
+
       <!-- 表情面板 -->
-      <div class="app-box" v-show="showEmoji" :style="{height: `${appBoxHeight}px`}">
+      <div
+        class="app-box"
+        v-show="showEmoji"
+        :style="{ height: `${appBoxHeight}px` }"
+      >
         😀 😃 😄 😁 😆 😅 😂 🤣 😊 😇 🙂 🙃 😉 😌 😍
-        
       </div>
-      
+
       <!-- 工具栏面板 -->
-      <div class="app-box" v-show="showTools" :style="{height: `${appBoxHeight}px`}">
+      <div
+        class="app-box"
+        v-show="showTools"
+        :style="{ height: `${appBoxHeight}px` }"
+      >
         <!-- 工具栏内容:可放按钮、图标等 -->
         <div class="tool-btn">照片</div>
         <div class="tool-btn">视频</div>
@@ -85,11 +100,14 @@
 <script setup>
 import { ref, computed } from "vue";
 import { useRouter } from "vue-router";
-import { Keyboard } from '@capacitor/keyboard';
+import { Keyboard } from "@capacitor/keyboard";
+import { useWebSocketStore } from "@/stores/modules/webSocketStore.js";
 
 const router = useRouter();
 const text = ref("");
 
+const wsStore = useWebSocketStore();
+
 // 状态管理
 const keyboardHeight = ref(0);
 const showEmoji = ref(false);
@@ -113,7 +131,7 @@ const toggleAppBox = async (type) => {
   // 先隐藏键盘(如果正在显示)
   await Keyboard.hide();
   keyboardHeight.value = 0; // 立即重置键盘高度
-  
+
   // 切换面板状态
   if (type === 1) {
     showEmoji.value = !showEmoji.value;
@@ -133,11 +151,11 @@ const onFocus = () => {
 
 // 键盘监听
 const setupKeyboardListeners = async () => {
-  Keyboard.addListener('keyboardWillShow', (info) => {
+  Keyboard.addListener("keyboardWillShow", (info) => {
     keyboardHeight.value = info.keyboardHeight;
   });
-  
-  Keyboard.addListener('keyboardWillHide', () => {
+
+  Keyboard.addListener("keyboardWillHide", () => {
     keyboardHeight.value = 0;
   });
 };
@@ -147,10 +165,25 @@ const goBack = () => {
 };
 const goDetail = () => {
   router.push("detail");
-}
+};
+
+// 发送消息
+const sendMessage = () => {
+  if (!text.value.trim()) {
+    return; // 空消息不发送
+  }
+
+  let message = {
+    content: text.value,
+    contentType: 1,
+  };
+  wsStore.sendMessage(message);
+  // 清空输入框
+  text.value = "";
+};
 
 onUnmounted(() => {
-  if (Capacitor.getPlatform() !== 'web') {
+  if (Capacitor.getPlatform() !== "web") {
     Keyboard.removeAllListeners();
   }
 });
@@ -339,7 +372,7 @@ onUnmounted(() => {
   transition: transform 0.3s ease;
   transform: translateY(100%);
   background-color: yellow;
-  
+
   &.visible {
     transform: translateY(0);
   }

+ 3 - 7
src/views/im/index.vue

@@ -79,12 +79,10 @@ import { userList } from "@/api/path/im.api";
 import { ref } from 'vue'
 import { useRouter } from 'vue-router'
 import Discover from './components/Discover/Discover.vue'
-import { useWebSocketStore } from "@/stores/modules/webSocketStore.js"
 
 
-const walletStore = useWalletStore();
+const walletStore = useWalletStore(); 
 const router = useRouter();
-const wsStore = useWebSocketStore()
 
 
 const activeTab = ref(0)
@@ -110,11 +108,9 @@ const goToPage = (url) => {
 onMounted(()=>{
   getuserList();
 
-  wsStore.connect(walletStore.getAccount)
+ 
 })
-// onUnmounted(() => {
-//   wsStore.close()
-// })
+
 
 </script>