luwenna 4 سال پیش
والد
کامیت
2b20ebdf93

+ 4 - 0
jydocs-mobile/src/App.vue

@@ -11,6 +11,7 @@
 </template>
 <script>
 import layout from '@/components/layout.vue'
+import { hiddenBottomBar } from '@/utils/globalFunctionsForApp'
 export default {
   name: 'App',
   components: {
@@ -30,6 +31,9 @@ export default {
       // cashViews: ['home', 'share-list', 'auth-partner'],
       env: this.$env
     }
+  },
+  mounted () {
+    hiddenBottomBar()
   }
 }
 </script>

+ 6 - 2
jydocs-mobile/src/components/Search.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="search-container van-fade-an">
       <div class="click-pop" v-if="type === 'click'"  @click="onClick"></div>
-      <van-search @input="$emit('input', $event)" @search="onSearch" class="my-search" left-icon="diy-search" v-model.trim="input" placeholder="搜索文档" />
+      <van-search @input="$emit('input', $event)" @search="onSearch" class="my-search" left-icon="diy-search" v-model="input" placeholder="搜索文档" />
   </div>
 </template>
 
@@ -23,13 +23,17 @@ export default class Empty extends Vue {
     input = ''
 
     created () {
-      this.input = this.defalultValue || ''
+      this.setSearchContent(this.defalultValue || '')
     }
 
     onSearch () {
       this.$emit('submit', this.input)
     }
 
+    setSearchContent (v: any) {
+      this.input = v
+    }
+
     onClick () {
       if (this.type === 'click') {
         this.$emit('click')

+ 6 - 2
jydocs-mobile/src/views/Search.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="pages--search">
     <div class="j-header">
-      <search id="mySearch" key="search-page" :defalultValue="listState.value" @input="onInput" @submit="doSearch"></search>
+      <search id="mySearch" ref="input" key="search-page" :defalultValue="listState.value" @input="onInput" @submit="doSearch"></search>
       <van-tabs v-model="docsTypeConf.active"
         v-if="docsTypeConf.list.length"
         title-active-color="#2ABED1"
@@ -184,7 +184,7 @@ export default class extends Vue {
   }
 
   onInput (search: string) {
-    this.listState.value = search
+    this.listState.value = search.trim().replace(/\s+/g, ' ')
   }
 
   docTypeChange () {
@@ -214,6 +214,10 @@ export default class extends Vue {
 
   doSearch () {
     if (!this.listState.value) return
+
+    const inputComponent = this.$refs.input as any
+    inputComponent.setSearchContent(this.listState.value)
+
     this.resetListState()
     this.setScrollTop()
     this.listState.finished = false

+ 12 - 11
jydocs-pc/src/components/Search.vue

@@ -2,12 +2,12 @@
     <div class="search-input">
         <el-input
                 placeholder="搜索文档"
-                v-model.trim="input"
-                @keyup.enter.native="submitSearch"
+                v-model="input"
+                @keyup.enter.native="submitSearch('onEnter')"
                 clearable>
-            <el-button @click="submitSearch" slot="append" icon="el-icon-jy-search"></el-button>
+            <el-button @click="submitSearch('onSubmit')" slot="append" icon="el-icon-jy-search"></el-button>
         </el-input>
-        <el-tabs v-model="type" v-show="tabs.length" @tab-click="submitSearch">
+        <el-tabs v-model="type" v-show="tabs.length" @tab-click="submitSearch('onChangeType')">
           <el-tab-pane v-for="item in tabs" :key="item.type" :label="item.label" :name="item.type"></el-tab-pane>
         </el-tabs>
     </div>
@@ -36,7 +36,7 @@ export default {
       tabs: []
     }
   },
-  beforeMount () {
+  mounted () {
     this.tabs = recoveryPageData('jy-docs-search-tags-pc')
     this.getTags()
     const qUrl = this.$route.query
@@ -45,7 +45,7 @@ export default {
       this.input = qUrl.text
       this.$emit('recovery', {
         type: this.type,
-        text: this.input
+        text: this.input.trim().replace(/\s+/g, ' ')
       })
     }
   },
@@ -66,13 +66,14 @@ export default {
         }
       })
     },
-    submitSearch () {
-      if (!this.input.length) {
-        return
-      }
+    setSearchContent: function (v) {
+      this.input = v
+    },
+    submitSearch (e) {
       this.$emit('submit', {
         type: this.type,
-        text: this.input
+        text: this.input.trim().replace(/\s+/g, ' '),
+        events: e
       })
     }
   }

+ 7 - 1
jydocs-pc/src/views/Home.vue

@@ -236,9 +236,15 @@ export default {
       })
     },
     goSubmit (search) {
+      if (!search.text.replace(/\s+/g, '')) {
+        return
+      }
       this.$router.push({
         name: 'search',
-        query: search
+        query: {
+          type: search.type,
+          text: search.text
+        }
       })
     },
     getLoginStatus: function () {

+ 44 - 8
jydocs-pc/src/views/Search.vue

@@ -115,29 +115,63 @@ export default {
         loaded: false,
         loading: false,
         pageNum: 1,
+        total: 0,
         list: []
       }
       Object.assign(this.listState, state)
     },
-    doSearch (search) {
+    setUrlQuery: function () {
+      const arr = []
+      for (const key in this.searchQuery) {
+        arr.push(this.searchQuery[key] === this.$route.query[key])
+      }
+      // 如果当前url和设置的url完全相同或者搜索值为空时候,则直接返回
+      // 是否所有元素都为true
+      const isSame = arr.every(item => item)
+      if (isSame || !this.searchQuery.text) {
+        return
+      }
+      this.$router.replace({
+        name: 'search',
+        query: {
+          type: this.searchQuery.type,
+          text: this.searchQuery.text
+        }
+      })
+    },
+    getSearchState: function (search) {
       if (search) {
         Object.assign(this.searchQuery, search)
       } else {
         this.searchQuery.type = this.$refs.search.type
-        this.searchQuery.text = this.$refs.search.input
+        this.searchQuery.text = this.$refs.search.input.trim().replace(/\s+/g, ' ')
       }
-      this.getList()
     },
-    async getList () {
-      if (!this.searchQuery.text) return
+    doSearch (search) {
+      this.getSearchState(search)
+      if (!this.searchQuery.text) {
+        if (search.events === 'onSubmit') {
+          this.$router.push('/')
+        }
+        return
+      }
+      this.resetListState()
+      this.getList(search)
+    },
+    async getList (search) {
       const query = {
-        keyWord: this.searchQuery.text,
+        keyWord: this.searchQuery.text.trim().replace(/\s+/g, ' '),
         tag: this.searchQuery.type === '全部' ? '' : this.searchQuery.type,
         sort: this.activeSortList.type,
         num: this.listState.pageNum,
         size: this.listState.pageSize
       }
+
       console.log(query)
+      // 设置url
+      this.setUrlQuery()
+      // 搜索内容去多余的空格并设置
+      this.$refs.search.setSearchContent(query.keyWord)
 
       this.listState.loading = true
       this.listState.loaded = false
@@ -149,6 +183,9 @@ export default {
       if (res.error_code === 0) {
         this.listState.total = res.data.total
         this.listState.list = res.data.list || []
+      } else {
+        this.listState.total = 0
+        this.listState.list = []
       }
     },
     sortAndSearch (item, index) {
@@ -161,7 +198,6 @@ export default {
         })
         item.active = true
       }
-      this.resetListState()
       this.doSearch()
     },
     toDocDetail (item) {
@@ -174,7 +210,7 @@ export default {
     },
     onPageChange (p) {
       this.listState.pageNum = p
-      this.doSearch()
+      this.getList()
     },
     calcSubInfo (item) {
       const { docFileSize: size, downTimes, uploadDate, docPageSize } = item