Ver Fonte

feat: 新增tags接口

zhangyuhan há 4 anos atrás
pai
commit
c966a935f5

+ 11 - 0
jydocs-mobile/src/api/mock/indexTag.json

@@ -0,0 +1,11 @@
+{
+  "error_code": 0,
+  "error_msg": "",
+  "data": [
+    "全部",
+    "招标",
+    "法律法规",
+    "行业报告",
+    "测试"
+  ]
+}

+ 11 - 0
jydocs-pc/src/api/mock/indexTag.json

@@ -0,0 +1,11 @@
+{
+  "error_code": 0,
+  "error_msg": "",
+  "data": [
+    "全部",
+    "招标",
+    "法律法规",
+    "行业报告",
+    "测试"
+  ]
+}

+ 7 - 0
jydocs-pc/src/api/modules/home.js

@@ -17,6 +17,13 @@ export function getHomeHot (data) {
   })
 }
 
+export function getSearchTag () {
+  return request({
+    url: '/indexTag',
+    method: 'post'
+  })
+}
+
 export function getHomeActivity (data) {
   return request({
     url: '/activityList',

+ 22 - 20
jydocs-pc/src/components/Search.vue

@@ -7,7 +7,7 @@
                 clearable>
             <el-button @click="submitSearch" slot="append" icon="el-icon-jy-search"></el-button>
         </el-input>
-        <el-tabs v-model="type">
+        <el-tabs v-model="type" v-show="tabs.length">
           <el-tab-pane v-for="item in tabs" :key="item.type" :label="item.label" :name="item.type"></el-tab-pane>
         </el-tabs>
     </div>
@@ -15,6 +15,9 @@
 
 <script>
 import { Input, Button, Tabs, TabPane } from 'element-ui'
+import { getSearchTag } from '../api/modules/home'
+import { recoveryPageData } from '../utils'
+
 export default {
   name: 'Search-Input',
   props: {
@@ -29,28 +32,13 @@ export default {
   data () {
     return {
       input: '',
-      type: 'all',
-      tabs: [
-        {
-          type: 'all',
-          label: '全部'
-        },
-        {
-          type: '招标',
-          label: '招标'
-        },
-        {
-          type: '法律法规',
-          label: '法律法规'
-        },
-        {
-          type: '行业报告',
-          label: '行业报告'
-        }
-      ]
+      type: '全部',
+      tabs: []
     }
   },
   beforeMount () {
+    this.tabs = recoveryPageData('jy-docs-search-tags-pc')
+    this.getTags()
     const qUrl = this.$route.query
     qUrl && qUrl.type && (this.type = qUrl.type)
     if (qUrl && qUrl.text) {
@@ -62,6 +50,20 @@ export default {
     }
   },
   methods: {
+    async getTags () {
+      getSearchTag().then(res => {
+        if (!res.data.error_msg.length) {
+          this.tabs = res.data.data.map(v => {
+            return {
+              type: v,
+              label: v
+            }
+          })
+          this.type = this.tabs[0].type
+          sessionStorage.setItem('jy-docs-search-tags-pc', JSON.stringify(this.tabs))
+        }
+      })
+    },
     submitSearch () {
       if (!this.input.length) {
         return

+ 4 - 0
jydocs-pc/src/utils/globalFunctions.js

@@ -328,3 +328,7 @@ export function replaceKeyword (value, oldChar, newChar) {
   }
   return value
 }
+
+export function recoveryPageData (key, defaultValues = {}) {
+  return sessionStorage.getItem(key) ? JSON.parse(sessionStorage.getItem(key) || '') : defaultValues
+}

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

@@ -125,9 +125,7 @@ import { ajaxGetTest } from '../api/modules/user'
 import { Button } from 'element-ui'
 import SearchInput from '../components/Search'
 import { getHomeActivity, getHomeHot } from '../api/modules/home'
-function recoveryPageData (key, defaultValues = {}) {
-  return sessionStorage.getItem(key) ? JSON.parse(sessionStorage.getItem(key) || '') : defaultValues
-}
+import { recoveryPageData } from '../utils'
 
 function checkType (type) {
   let typeStr = ''