Browse Source

feat:修复样式问题

zhangwl 1 month ago
parent
commit
fbe57e272d
3 changed files with 27 additions and 14 deletions
  1. 23 2
      chat-ai-ui-main/src/stores/chat.ts
  2. 0 12
      chat-ai-ui-main/src/style.css
  3. 4 0
      chat-ai-ui-main/vite.config.ts

+ 23 - 2
chat-ai-ui-main/src/stores/chat.ts

@@ -70,10 +70,31 @@ const blankMeta = () => ({
   isStreaming: false,
 });
 
+// crypto.randomUUID() 在低版本 WebView 或非 HTTPS 环境不可用,提供回退方案
+function generateUUID(): string {
+  if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
+    return crypto.randomUUID();
+  }
+  // fallback: 用 crypto.getRandomValues 生成 UUID v4
+  if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
+    const bytes = new Uint8Array(16);
+    crypto.getRandomValues(bytes);
+    bytes[6] = (bytes[6] & 0x0f) | 0x40;
+    bytes[8] = (bytes[8] & 0x3f) | 0x80;
+    const hex = Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
+    return `${hex.slice(0,8)}-${hex.slice(8,12)}-${hex.slice(12,16)}-${hex.slice(16,20)}-${hex.slice(20)}`;
+  }
+  // 最终回退: Math.random
+  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
+    const r = Math.random() * 16 | 0;
+    return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
+  });
+}
+
 export const useChatStore = defineStore('chat', () => {
   const messages = ref<Message[]>([]);
   const isLoading = ref(false);
-  const sessionId = ref<string>(crypto.randomUUID());
+  const sessionId = ref<string>(generateUUID());
   const sessions = ref<Session[]>([]);
   const sidebarOpen = ref(false);
 
@@ -101,7 +122,7 @@ export const useChatStore = defineStore('chat', () => {
   };
 
   const newConversation = () => {
-    sessionId.value = crypto.randomUUID();
+    sessionId.value = generateUUID();
     messages.value = [];
     sidebarOpen.value = false;
   };

+ 0 - 12
chat-ai-ui-main/src/style.css

@@ -1,17 +1,5 @@
 @import 'tailwindcss';
 
-/* 竖屏锁定 */
-html {
-  orientation: portrait;
-}
-
-/* 防止横屏 */
-@media (orientation: landscape) {
-  body {
-    display: none;
-  }
-}
-
 /* 移动端优化 */
 @media (max-width: 640px) {
   body {

+ 4 - 0
chat-ai-ui-main/vite.config.ts

@@ -5,4 +5,8 @@ import tailwindcss from '@tailwindcss/vite';
 // https://vite.dev/config/
 export default defineConfig({
   plugins: [vue(), tailwindcss()],
+  build: {
+    // 兼容低版本手机 WebView(Android 7+ / iOS 12+)
+    target: ['es2015', 'chrome64', 'safari12'],
+  },
 });