소스 검색

添加关键字查询

asd123a20 2 년 전
부모
커밋
13ef3d560c
2개의 변경된 파일31개의 추가작업 그리고 9개의 파일을 삭제
  1. 7 1
      admin-content/src/store/index.js
  2. 24 8
      admin-content/src/views/home.vue

+ 7 - 1
admin-content/src/store/index.js

@@ -9,7 +9,8 @@ const api = {
   contentsFetch: '/api/cms/contents/fetch',
   menusQuery: '/api/cms/menus/query',
   userQuery: '/api/reader/user/query',
-  sourceQuery: '/api/code/dictionary/query'
+  sourceQuery: '/api/code/dictionary/query',
+  search: '/api/cms/contents/search'
 };
 Vue.use(Vuex);
 const state = () => ({
@@ -22,6 +23,11 @@ const state = () => ({
 });
 
 const actions = {
+  async search ({ commit }, { search }) {
+    const res = await $axios.get(api.search, { search });
+    commit('contentsQuery', { ...res, total: res.data.length });
+    return res;
+  },
   async sourceQuery ({ commit }) {
     const res = await $axios.get(api.sourceQuery, { parentCode: 'source' });
     commit('sourceQuery', res);

+ 24 - 8
admin-content/src/views/home.vue

@@ -19,6 +19,7 @@
             <el-select v-model="formInline[item.name]" placeholder="请选择菜单" v-if="item.name == 'bind'">
               <el-option v-for="item in menus" :key="item.code" :label="item.name" :value="item.code"></el-option>
             </el-select>
+            <el-input v-if="item.name == 'search'"  v-model="formInline[item.name]" placeholder="请输入关键字" clearable></el-input>
           </template>
         </filterList>
       </div>
@@ -95,7 +96,8 @@ export default {
       title: '',
       visibleSync: false,
       filed: [
-        { name: 'title', label: '标题', filter: true },
+        { name: 'title', label: '标题' },
+        { name: 'search', label: '关键字查询', formater: 'slot', filter: true, isshow: false },
         { name: 'recommend', label: '是否查询推荐', formater: 'slot', filter: true, isshow: false },
         { name: 'visit', label: '访问量', width: '150' }
       ],
@@ -168,7 +170,7 @@ export default {
     await this.sourceQuery();
   },
   methods: {
-    ...mapActions(['contentsQuery', 'contentsCreate', 'contentsUpdate', 'contentsDelete', 'contentsQuery', 'contentsFetch', 'menusQuery', 'userQuery', 'sourceQuery']),
+    ...mapActions(['contentsQuery', 'contentsCreate', 'contentsUpdate', 'contentsDelete', 'contentsFetch', 'menusQuery', 'userQuery', 'sourceQuery', 'search']),
     // 查询字典函数
     async querySearchAsync(queryString, cb) {
       await this.sourceQuery();
@@ -177,9 +179,14 @@ export default {
     // 作者查询函数
     async authorSelect(queryString, cb) {
       const authorList = localStorage.getItem('author');
-      let list = authorList.split(',');
-      list = list.map(e => ({ name: e }));
-      cb(list);
+      if (authorList && authorList !== null && authorList !== '') {
+        let list = authorList.split(',');
+        list = list.map(e => ({ name: e }));
+        cb(list);
+        return;
+      }
+      // eslint-disable-next-line standard/no-callback-literal
+      cb([]);
     },
     // 选择建议
     handleSelect(item) {
@@ -214,6 +221,11 @@ export default {
     },
     // 查询
     async filterQuery ({ filter = {}, paging = { page: 0, size: 10 } } = {}) {
+      console.log(filter);
+      if (filter.search) {
+        await this.search({ ...filter });
+        return;
+      }
       this.page = paging.page;
       if (this.types !== null) filter.bind = this.types;
       await this.contentsQuery({ filter, paging });
@@ -244,10 +256,14 @@ export default {
         this.$refs.filterList.resetPage(-1);
       }
       const author = localStorage.getItem('author');
-      if (!this.handleAuthor) localStorage.setItem('author', `${author}, ${e.author}`);
+      if (!this.handleAuthor) {
+        if (author) {
+          if (!author.includes(e.author)) localStorage.setItem('author', `${author}, ${e.author}`);
+        } else {
+          localStorage.setItem('author', e.author);
+        }
+      }
       this.$resChange(res, msg);
-      // const filter = { bind: this.types };
-      // this.filterQuery({ filter, paging });
       this.visibleSync = false;
       this.fileList = [];
       this.handleAuthor = false;