Procházet zdrojové kódy

添加作者输入建议, 存储本地缓存

asd123a20 před 2 roky
rodič
revize
da1111ddd3
1 změnil soubory, kde provedl 20 přidání a 1 odebrání
  1. 20 1
      admin-content/src/views/home.vue

+ 20 - 1
admin-content/src/views/home.vue

@@ -59,6 +59,8 @@
             </el-upload>
             <!-- 来源输入带建议 -->
             <el-autocomplete value-key="name" v-if="item.name == 'source'" v-model="formdata[item.name]" :fetch-suggestions="querySearchAsync" placeholder="请输入内容" @select="handleSelect"></el-autocomplete>
+            <!-- 作者输入带建议 -->
+            <el-autocomplete value-key="name" v-if="item.name == 'author'" v-model="formdata[item.name]" :fetch-suggestions="authorSelect" placeholder="请输入内容" @select="handleAuthorSelect"></el-autocomplete>
           </template>
         </formData>
         <filterList v-else ref="filterList" :tableData="userList"  :filter="false" :readOnly="true" :filed="userfiled" @query="userfilterQuery" :total="userTotal"></filterList>
@@ -84,6 +86,7 @@ export default {
   },
   data() {
     return {
+      handleAuthor: false,
       types: null,
       info: {},
       lookUser: false,
@@ -107,7 +110,7 @@ export default {
         { name: 'curtTitle', label: '副标题' },
         { name: 'source', label: '来源', formater: 'slot' },
         { name: 'recommend', label: '推荐', formater: 'slot' },
-        { name: 'author', label: '作者' },
+        { name: 'author', label: '作者', formater: 'slot' },
         { name: 'bind', label: '绑定菜单', formater: 'dict:menus' },
         { name: 'date', label: '时间', formater: 'date:datetime' },
         { name: 'istop', label: '置顶', formater: 'slot' },
@@ -171,10 +174,23 @@ export default {
       await this.sourceQuery();
       cb(this.dict.source);
     },
+    // 作者查询函数
+    async authorSelect(queryString, cb) {
+      const authorList = localStorage.getItem('author');
+      let list = authorList.split(',');
+      list = list.map(e => ({ name: e }));
+      console.log(list);
+      cb(list);
+    },
     // 选择建议
     handleSelect(item) {
       console.log(item);
     },
+    // 作者选择建议
+    handleAuthorSelect(e) {
+      console.log(e);
+      this.handleAuthor = true;
+    },
     // 添加
     addcontents () {
       this.formdata = {};
@@ -222,12 +238,15 @@ export default {
         res = await this.contentsCreate(e);
         msg = '文章添加成功';
       }
+      const author = localStorage.getItem('author');
+      if (!this.handleAuthor) localStorage.setItem('author', `${author}, ${e.author}`);
       this.$resChange(res, msg);
       const filter = { bind: this.types };
       this.filterQuery({ filter });
       this.visibleSync = false;
       this.$refs.filterList.resetPage(-1);
       this.fileList = [];
+      this.handleAuthor = false;
     },
     // 富文本改变
     editChage (e) {