shaogen1995 2 years ago
parent
commit
05927b1ca1
1 changed files with 56 additions and 33 deletions
  1. 56 33
      web/src/views/Search/index.vue

+ 56 - 33
web/src/views/Search/index.vue

@@ -1,43 +1,50 @@
 <template>
   <div class="Search">
-    <div class="pos" data-aria-viewport-area tabindex="0"
-      aria-label aria-description="You've reached the path area; this area has three URLs; please use the tab key to go through the content."
+    <div
+      class="pos"
+      data-aria-viewport-area
+      tabindex="0"
+      aria-label
+      aria-description="You've reached the path area; this area has three URLs; please use the tab key to go through the content."
     >
       <span class="pos1" tabindex="0">Your Position:&nbsp;</span>
-      <Router-link to="/Layout/Home"
+      <Router-link
+        to="/Layout/Home"
         replace
         tabindex="0"
         aria-description="Home"
       >
         Home>
       </Router-link>
-      <span
-        tabindex="0"
-        aria-label="Link"
-        aria-description="Search"
-      >
+      <span tabindex="0" aria-label="Link" aria-description="Search">
         Search>
       </span>
-      <span
-        tabindex="0"
-        aria-label="Link"
-        aria-description="List"
-      >
+      <span tabindex="0" aria-label="Link" aria-description="List">
         List>
       </span>
     </div>
     <div class="titleBox" tabindex="0">
       Search
-      <span> {{num}} results</span>
+      <span> {{ num }} results</span>
     </div>
-    <div class="searchForm" data-aria-interaction-area tabindex="0"
-      aria-label aria-description="You've reached the Search interactive section, please use the tab key to go through the content."
+    <div
+      class="searchForm"
+      data-aria-interaction-area
+      tabindex="0"
+      aria-label
+      aria-description="You've reached the Search interactive section, please use the tab key to go through the content."
     >
-      <input class="searchWord" type="text" v-model="txt" 
+      <input
+        class="searchWord"
+        type="text"
+        v-model="txt"
         tabindex="0"
+        autofocus
+        @keydown.enter="searchBtn"
         :aria-description="txt || 'Input keyword'"
       />
-      <div class="searchBtn"
+      <div
+        class="searchBtn"
         @click="searchBtn"
         @keydown.enter.passive="searchBtn"
         tabindex="0"
@@ -47,10 +54,14 @@
       </div>
     </div>
     <!-- 切换tab动态路由 -->
-    <div class="searchMenu" data-aria-viewport-area tabindex="0"
-      aria-label aria-description="You've reached the content area of the Search results page, please use the tab key to navigate through the content."
+    <div
+      class="searchMenu"
+      data-aria-viewport-area
+      tabindex="0"
+      aria-label
+      aria-description="You've reached the content area of the Search results page, please use the tab key to navigate through the content."
     >
-      <div v-for="item in tabData" :key="item.id" >
+      <div v-for="item in tabData" :key="item.id">
         <span
           :class="{ active: cut === item.cut }"
           class="txt"
@@ -63,7 +74,8 @@
         </span>
         <span v-if="item.id !== 11"> | </span>
       </div>
-      <div class="more"
+      <div
+        class="more"
         v-if="moreShow"
         @click="more"
         @keydown.enter.passive="more"
@@ -76,10 +88,14 @@
       </div>
     </div>
     <!-- 动态组件 -->
-    <div class="comm" data-aria-viewport-area tabindex="0"
-      aria-label :aria-description="`You've reached the content area of ${cut} list, please use the tab key to navigate through the content.`"
+    <div
+      class="comm"
+      data-aria-viewport-area
+      tabindex="0"
+      aria-label
+      :aria-description="`You've reached the content area of ${cut} list, please use the tab key to navigate through the content.`"
     >
-      <component ref="comSon" :is="cut" :txt='txt' :num.sync='num' ></component>
+      <component ref="comSon" :is="cut" :txt="txt" :num.sync="num"></component>
     </div>
   </div>
 </template>
@@ -114,7 +130,7 @@ export default {
   data() {
     //这里存放数据
     return {
-      num:0,
+      num: 0,
       cut: "All",
       txt: "",
       moreShow: true,
@@ -136,10 +152,10 @@ export default {
   //方法集合
   methods: {
     // 点击搜索
-    searchBtn(){
-      this.$nextTick(()=>{
-      this.$refs.comSon.searchBtn(this.txt)
-      })
+    searchBtn() {
+      this.$nextTick(() => {
+        this.$refs.comSon.searchBtn(this.txt);
+      });
     },
     more() {
       this.tabData.push({ id: 8, name: "About", cut: "About" });
@@ -161,8 +177,15 @@ export default {
   },
   //生命周期 - 挂载完成(可以访问DOM元素)
   mounted() {
-    this.$eventBus.$emit('request-read', `You've reached the Search page. This page contains one navigation section, five window sections, and one interactive section. To choose an section, please hit the shortcut key.`)
-  },
+    this.$eventBus.$emit(
+      "request-read",
+      `You've reached the Search page. This page contains one navigation section, five window sections, and one interactive section. To choose an section, please hit the shortcut key.`
+    );
+    // 输入框获取焦点
+    this.$nextTick(()=>{
+      document.querySelector('.searchWord').focus()
+    })
+      },
   beforeCreate() {}, //生命周期 - 创建之前
   beforeMount() {}, //生命周期 - 挂载之前
   beforeUpdate() {}, //生命周期 - 更新之前
@@ -258,7 +281,7 @@ export default {
       cursor: pointer;
     }
   }
-  .comm{
+  .comm {
     width: 1200px;
     margin: 0 auto 20px;
     min-height: 514px;