chenlei 7 月之前
父节点
当前提交
7403a642c7

+ 5 - 1
packages/mobile/src/components/Topbar.vue

@@ -2,7 +2,11 @@
   <div class="topbar" :class="{ 'no-search': route.meta.hideSearch }">
     <img src="@/assets/images/button-min.png" @click="visible = true" />
 
-    <div v-if="!route.meta.hideSearch" class="topbar-search">
+    <div
+      v-if="!route.meta.hideSearch"
+      class="topbar-search"
+      @click="$router.push({ name: 'antiquity', query: { focus: 1 } })"
+    >
       <p>请输入要查找的文字内容</p>
     </div>
   </div>

+ 2 - 1
packages/mobile/src/router/index.js

@@ -1,4 +1,5 @@
 import { createRouter, createWebHashHistory } from "vue-router";
+import Antiquity from "../views/Antiquity/index.vue";
 
 const router = createRouter({
   history: createWebHashHistory(import.meta.env.BASE_URL),
@@ -33,7 +34,7 @@ const router = createRouter({
       meta: {
         hideSearch: true,
       },
-      component: () => import("../views/Antiquity/index.vue"),
+      component: Antiquity,
     },
     {
       path: "/antiquity/detail/:id",

+ 16 - 2
packages/mobile/src/views/Antiquity/index.vue

@@ -1,7 +1,12 @@
 <template>
   <div class="antiquity">
     <div class="antiquity-search">
-      <input v-model="keyword" type="search" placeholder="请输入文物名称" />
+      <input
+        v-model="keyword"
+        ref="search"
+        type="search"
+        placeholder="请输入文物名称"
+      />
       <img src="@/assets/images/search-min.png" />
     </div>
 
@@ -14,11 +19,20 @@
 </template>
 
 <script setup>
-import { ref, computed } from "vue";
+import { ref, computed, onMounted } from "vue";
 import { antiquityData } from "@lbc/base";
 import List from "./components/List.vue";
+import { useRoute } from "vue-router";
 
 const keyword = ref("");
+const route = useRoute();
+const search = ref();
+
+onMounted(() => {
+  if (route.query.focus) {
+    search.value.focus();
+  }
+});
 
 const tabs = computed(() => {
   const regex = new RegExp(keyword.value, "i");

+ 3 - 0
packages/mobile/vite.config.js

@@ -9,6 +9,9 @@ import { VantResolver } from "@vant/auto-import-resolver";
 // https://vite.dev/config/
 export default defineConfig({
   base: "./",
+  server: {
+    host: "0.0.0.0",
+  },
   plugins: [
     vue(),
     AutoImport({