Browse Source

添加工具栏

wkw 1 week ago
parent
commit
f55171bf22
6 changed files with 139 additions and 108 deletions
  1. 4 0
      src/assets/svg/mp.svg
  2. 10 0
      src/assets/svg/ps.svg
  3. 13 0
      src/assets/svg/spth.svg
  4. 8 0
      src/assets/svg/tp.svg
  5. 9 0
      src/assets/svg/yyth.svg
  6. 95 108
      src/views/im/chat/index.vue

File diff suppressed because it is too large
+ 4 - 0
src/assets/svg/mp.svg


+ 10 - 0
src/assets/svg/ps.svg

@@ -0,0 +1,10 @@
+<svg width="54" height="54" viewBox="0 0 54 54" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Frame 62">
+<g id="Group 3829">
+<rect id="Rectangle 1055" width="54" height="54" rx="12" fill="#F2F2F2"/>
+<g id="Frame">
+<path id="Vector" d="M26.8179 23.4536C24.39 23.4536 22.4207 25.411 22.4207 27.8256C22.4207 30.2401 24.39 32.1976 26.8179 32.1976C29.2466 32.1976 31.2158 30.2401 31.2158 27.8256C31.2158 25.411 29.2466 23.4536 26.8179 23.4536ZM41.0308 19.9343C41.0308 19.0738 40.3279 18.3756 39.4618 18.3756H33.97L33.1852 16.8153C33.1852 16.8153 32.483 15.255 31.6169 15.255H22.2017C21.3356 15.255 20.6335 16.8153 20.6335 16.8153L19.8486 18.3756H14.3568C13.4908 18.3756 12.7878 19.0738 12.7878 19.9343V37.0959C12.7878 37.958 13.4908 38.6563 14.3568 38.6563H39.4618C40.3278 38.6563 41.0308 37.958 41.0308 37.0959V34.9115L41.0174 35.2441L41.0308 29.5956V19.9343ZM26.8179 33.6553C23.5807 33.6553 20.9557 31.0439 20.9557 27.8256C20.9557 24.6057 23.5807 21.9958 26.8179 21.9958C30.0559 21.9958 32.6808 24.6057 32.6808 27.8256C32.6808 31.0439 30.0559 33.6553 26.8179 33.6553ZM36.1008 23.2062C35.4318 23.2062 34.8904 22.664 34.8904 21.9958C34.8904 21.3275 35.4318 20.7853 36.1008 20.7853C36.7691 20.7853 37.3113 21.3275 37.3113 21.9958C37.3113 22.664 36.7691 23.2062 36.1008 23.2062Z" fill="#C2C2C2"/>
+</g>
+</g>
+</g>
+</svg>

+ 13 - 0
src/assets/svg/spth.svg

@@ -0,0 +1,13 @@
+<svg width="54" height="54" viewBox="0 0 54 54" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Frame 64">
+<rect id="Rectangle 1057" width="54" height="54" rx="12" fill="#F2F2F2"/>
+<g id="Frame" clip-path="url(#clip0_295_618)">
+<path id="Vector" d="M31.526 17.4102H13.9452C13.9452 17.4102 11 17.4102 11 20.2647V34.7352C11 37.5897 13.9452 37.5897 13.9452 37.5897H31.526C31.526 37.5897 34.4712 37.5897 34.4712 34.7352V20.3555C34.4712 17.4102 31.526 17.4102 31.526 17.4102ZM43.571 18.887C43.3152 18.8045 43.0512 18.8045 42.878 18.9695L37.0782 23.474C36.905 23.6472 36.8225 23.8205 36.8225 23.9937V31.1877C36.8225 31.361 36.905 31.6167 37.0782 31.7075L42.8862 36.212C42.9687 36.2945 43.142 36.3852 43.3152 36.3852C43.3977 36.3852 43.4885 36.3852 43.6617 36.3027C43.9175 36.2202 44.0082 35.9562 44.0082 35.7005V19.4892C44 19.2335 43.8267 18.9695 43.571 18.887Z" fill="#C2C2C2"/>
+</g>
+</g>
+<defs>
+<clipPath id="clip0_295_618">
+<rect width="33" height="33" fill="white" transform="translate(11 11)"/>
+</clipPath>
+</defs>
+</svg>

+ 8 - 0
src/assets/svg/tp.svg

@@ -0,0 +1,8 @@
+<svg width="54" height="54" viewBox="0 0 54 54" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Frame 61">
+<g id="Group 3828">
+<rect id="Rectangle 1054" width="54" height="54" rx="12" fill="#F2F2F2"/>
+<path id="Vector" d="M36.0471 15H17.9709C15.2234 15 13 17.2376 13 20.0028V32.9972C13 34.216 13.4519 35.3258 14.175 36.199C15.0788 37.2905 16.4345 38 17.9529 38H36.029C38.7766 38 41 35.7624 41 32.9972V20.0028C41 17.2376 38.7766 15 36.029 15H36.0471ZM20.9174 18.7034C22.9057 18.7034 24.5326 20.3407 24.5326 22.3418C24.5326 24.3429 22.9057 25.9802 20.9174 25.9802C18.929 25.9802 17.3021 24.3429 17.3021 22.3418C17.3021 20.3407 18.929 18.7034 20.9174 18.7034ZM38.3066 32.9972C38.3066 34.2524 37.2944 35.2712 36.0471 35.2712H17.9709C17.736 35.2712 17.519 35.1984 17.3021 35.1438L23.3576 29.4497L26.051 32.1603C26.3221 32.4332 26.7017 32.5969 27.0813 32.5606C27.4609 32.5424 27.8225 32.3605 28.0575 32.0512L34.1853 24.3377L38.2886 29.8499V33.0336L38.3066 32.9972Z" fill="#C2C2C2"/>
+</g>
+</g>
+</svg>

+ 9 - 0
src/assets/svg/yyth.svg

@@ -0,0 +1,9 @@
+<svg width="54" height="54" viewBox="0 0 54 54" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Frame 63">
+<rect id="Rectangle 1056" width="54" height="54" rx="12" fill="#F2F2F2"/>
+<g id="Frame">
+<path id="Vector" d="M21.47 16H15.825C15.4541 15.9999 15.0867 16.0728 14.744 16.2147C14.4013 16.3565 14.0898 16.5645 13.8275 16.8268C13.5651 17.089 13.357 17.4004 13.2151 17.7431C13.0731 18.0858 13 18.4531 13 18.824C13.3347 24.3309 15.6734 29.525 19.5746 33.4261C23.4759 37.3271 28.67 39.6655 34.177 40C34.9256 39.9997 35.6435 39.7022 36.1729 39.1729C36.7022 38.6435 36.9997 37.9256 37 37.177V31.529L29.941 28.706L27.824 32.236C24.7577 30.724 22.276 28.2423 20.764 25.176L24.294 23.059L21.471 16H21.47Z" fill="#C2C2C2"/>
+<path id="Vector_2" d="M27.7312 17.9857C27.7312 17.9857 27.0187 17.8669 26.5437 18.3419C26.0687 18.9357 26.0687 19.7669 26.5437 20.2419C26.9 20.5982 27.2562 20.5982 27.2562 20.5982C28.0875 20.7169 29.3937 21.0732 30.8187 22.4982C32.2437 23.9232 32.4812 25.2294 32.6 26.0607C32.6 26.0607 32.7187 26.5357 32.9562 26.7732C33.4312 27.2482 34.3812 27.2482 34.8562 26.7732C35.3312 26.2982 35.2125 25.5857 35.2125 25.5857C34.8562 23.6857 34.025 21.9044 32.6 20.4794C31.4125 19.2919 29.6312 18.3419 27.7312 17.9857ZM34.3812 19.0544C36.9937 21.6669 38.0625 24.5169 37.7062 26.8919C37.7062 26.8919 37.5875 27.6044 38.0625 28.0794C38.5375 28.5544 39.4875 28.6732 39.9625 28.0794C40.3187 27.7232 40.3187 27.2482 40.3187 27.2482C40.675 25.2294 40.2 21.0732 36.2812 17.0357C32.3625 12.9982 28.2062 12.7607 26.1875 13.1169C26.1875 13.1169 25.5937 13.2357 25.3562 13.4732C25.1187 13.7107 25 14.0669 25 14.4232C25 14.7794 25.1187 15.1357 25.3562 15.3732C25.8312 15.8482 26.5437 15.7294 26.5437 15.7294C28.9187 15.3732 31.7687 16.5607 34.3812 19.0544Z" fill="#C2C2C2"/>
+</g>
+</g>
+</svg>

+ 95 - 108
src/views/im/chat/index.vue

@@ -1,54 +1,38 @@
 <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({{ wsStore.messages.length }})</div>
       <svg-icon class="page-icon" name="more" @click="goDetail" />
     </div>
+
+    <!-- 聊天消息区域 -->
     <div class="chat-list">
       <div v-for="(item, index) in wsStore.messages" :key="index">
-        <div class="chat-time">23:{{ 20 + index }}</div>
+        <div class="chat-time">{{ formatTime(item.timestamp || Date.now()) }}</div>
         <div class="box">
           <div class="list-item" :class="walletStore.account == item.toUsername ?'' : 'flex-reverse'">
+            <!-- 头像 -->
             <van-image
               class="list-img"
-              :class="index % 2 === 0 ? 'mr12' : 'ml12'"
+              :class="item.from === walletStore.account ? 'ml12' : 'mr12'"
               round
               src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
               @click="router.push('personal')"
             />
+            <!-- 内容 -->
             <div class="list-cont">
-              <div>{{ item.fromUsername }}</div>
-              <!-- 名片 -->
-              <!-- <div class="business-card" v-if="i % 2 === 0">
-                <div class="business-card-cont">
-                  <van-image
-                    class="list-img mr12"
-                    round
-                    src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
-                  />
-                  <div>名字名字</div>
-                </div>
-                <div class="line"></div>
-                <div class="business-card-text">个人名片</div>
-              </div> -->
-              <!-- 文本信息 -->
-              <div class="content" v-if="item.contentType === 1">
-                {{ item.content }}
-              </div>
+              <div>{{ item.fromUsername || '匿名用户' }}</div>
+              <div class="content" v-if="item.contentType === 1">{{ item.content }}</div>
+              <!-- 可扩展 contentType === 2 图片,3 名片等 -->
             </div>
           </div>
-          <!--消息撤回 -->
-          <!-- <div class="withdrawal">
-            <div class="withdrawal-text">哈哈哈撤回了一条消息</div>
-          </div> -->
         </div>
       </div>
     </div>
+
     <!-- 输入框 -->
     <div class="page-foot">
       <div class="flex-box">
@@ -64,130 +48,115 @@
           placeholder="输入文本"
           @keyup.enter="sendMessage"
         />
-        <svg-icon
-          class="page-icon mr12"
-          name="emoji"
-          @click="toggleAppBox(1)"
-        />
+        <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="tool-btn">照片</div>
-        <div class="tool-btn">视频</div>
-        <div class="tool-btn">语音通话</div>
-        <div class="tool-btn">名片</div>
+      <div class="app-box" v-show="showTools" :style="{ height: `${appBoxHeight}px` }">
+        <div class="tool-btn">
+          <svg-icon class="tool-icon" name="tp" />
+          <div>图片</div>
+        </div>
+        <div class="tool-btn"><svg-icon class="tool-icon" name="ps" /><div>拍摄</div></div>
+        <div class="tool-btn"><svg-icon class="tool-icon" name="yyth" /><div>语音通话</div></div>
+        <div class="tool-btn"><svg-icon class="tool-icon" name="spth" /><div>视频通话</div></div>
+        <div class="tool-btn"><svg-icon class="tool-icon" name="mp" /><div>名片</div></div>
       </div>
     </div>
   </div>
 </template>
 
-<script setup> 
-import { Keyboard } from "@capacitor/keyboard";
+<script setup>
+import { ref, computed, onMounted, onUnmounted } from "vue";
+import { useRouter, useRoute } from "vue-router";
 import { useWebSocketStore } from "@/stores/modules/webSocketStore.js";
 import { useWalletStore } from "@/stores/modules/walletStore.js";
+import { Keyboard } from "@capacitor/keyboard";
+import { Capacitor } from "@capacitor/core";
 
+// 路由 & store
 const router = useRouter();
-const route = useRoute()
-const text = ref("");
-
+const route = useRoute();
 const wsStore = useWebSocketStore();
 const walletStore = useWalletStore();
 
+// 输入框文本
+const text = ref("");
+
 // 状态管理
 const keyboardHeight = ref(0);
 const showEmoji = ref(false);
 const showTools = ref(false);
-const appBoxHeight = ref(260); // 面板高度,可根据需要调整
+const appBoxHeight = ref(210);
+
+// 平台判断
+const isMobile = Capacitor.getPlatform() !== "web";
 
-// 计算当前底部总高度
+// 底部高度动态计算
 const currentBottomHeight = computed(() => {
-  // 优先级:键盘 > 表情面板 > 工具面板 > 默认高度
-  if (keyboardHeight.value > 0) {
-    return keyboardHeight.value; // 只计算键盘高度
-  }
-  if (showEmoji.value || showTools.value) {
-    return appBoxHeight.value; // 只计算面板高度
-  }
-  return 0; // 默认底部间距
+  if (keyboardHeight.value > 0) return keyboardHeight.value;
+  if (showEmoji.value || showTools.value) return appBoxHeight.value;
+  return 0;
 });
 
-// 切换面板显示
-const toggleAppBox = async (type) => {
-  // 先隐藏键盘(如果正在显示)
-  await Keyboard.hide();
-  keyboardHeight.value = 0; // 立即重置键盘高度
-
-  // 切换面板状态
-  if (type === 1) {
-    showEmoji.value = !showEmoji.value;
-    showTools.value = false;
-  } else {
-    showTools.value = !showTools.value;
-    showEmoji.value = false;
-  }
-};
-
+// 输入框聚焦
 const onFocus = () => {
-  // 隐藏所有面板
   showEmoji.value = false;
   showTools.value = false;
-  // 判断是不是web
-  if (Capacitor.getPlatform() != "web") {
-    setupKeyboardListeners();
-  }
+  if (isMobile) setupKeyboardListeners();
 };
 
-// 键盘监听
-const setupKeyboardListeners = async () => {
+// 监听键盘高度
+const setupKeyboardListeners = () => {
   Keyboard.addListener("keyboardWillShow", (info) => {
     keyboardHeight.value = info.keyboardHeight;
   });
-
   Keyboard.addListener("keyboardWillHide", () => {
     keyboardHeight.value = 0;
   });
 };
 
-const goBack = () => {
-  router.push("im");
-};
-const goDetail = () => {
-  router.push("detail");
+// 切换表情/工具面板
+const toggleAppBox = async (type) => {
+  if (isMobile) await Keyboard.hide();
+  keyboardHeight.value = 0;
+  if (type === 1) {
+    showEmoji.value = !showEmoji.value;
+    showTools.value = false;
+  } else {
+    showTools.value = !showTools.value;
+    showEmoji.value = false;
+  }
 };
 
 // 发送消息
 const sendMessage = () => {
-  if (!text.value.trim()) {
-    return; // 空消息不发送
-  }
-
-  let message = {
+  if (!text.value.trim()) return;
+  const message = {
     content: text.value,
-    contentType: 1,  // 1: 文本消息 
-    messageType: 1, // 1: 单聊天
-    to:route.query.uuid, 
+    contentType: 1,
+    messageType: 1,
+    to: route.query.uuid,
   };
   wsStore.sendMessage(message);
-  // 清空输入框
   text.value = "";
 };
 
+// 时间格式化
+const formatTime = (timestamp) => {
+  const date = new Date(timestamp);
+  const h = date.getHours().toString().padStart(2, "0");
+  const m = date.getMinutes().toString().padStart(2, "0");
+  return `${h}:${m}`;
+};
+
+// 页面生命周期
 onMounted(() => {
   wsStore.getMessages({
     uuid: walletStore.account,
@@ -197,10 +166,12 @@ onMounted(() => {
 });
 
 onUnmounted(() => {
-  if (Capacitor.getPlatform() !== "web") {
-    Keyboard.removeAllListeners();
-  }
+  if (isMobile) Keyboard.removeAllListeners();
 });
+
+// 页面跳转
+const goBack = () => router.push("im");
+const goDetail = () => router.push("detail");
 </script>
 
 <style lang="less" scoped>
@@ -378,18 +349,34 @@ onUnmounted(() => {
 }
 .app-box {
   position: fixed;
-  bottom: 260px;
+  bottom: 210px;
   left: 0;
   right: 0;
-  height: 260px;
   background: white;
   transition: transform 0.3s ease;
   transform: translateY(100%);
-  background-color: yellow;
+  display: flex;
+  flex-wrap: wrap;
+  padding: 10px 0 0 32px;
 
   &.visible {
     transform: translateY(0);
   }
+  .tool-btn{
+    margin-right: 32px;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    font-family: PingFang SC, PingFang SC;
+    font-weight: 400;
+    font-size: 12px;
+    color: #000000;
+    .tool-icon{
+      width: 56px;
+      height: 56px;
+      margin-bottom: 4px;
+    }
+  }
 }
 
 .page-foot {

Some files were not shown because too many files changed in this diff