guhongwei 5 년 전
부모
커밋
7789dfe8a3
3개의 변경된 파일34개의 추가작업 그리고 34개의 파일을 삭제
  1. 1 5
      src/store/news.js
  2. 8 23
      src/util/axios-wrapper.js
  3. 25 6
      src/views/pcenter/parts/infoAdmin.vue

+ 1 - 5
src/store/news.js

@@ -10,11 +10,7 @@ const mutations = {};
 
 const actions = {
   async query({ commit }, { skip = 0, limit = 10, ...info } = {}) {
-    const res = await this.$axios.$get(api.newsInfo, {
-      skip,
-      limit,
-      ...info,
-    });
+    const res = await this.$axios.$get(api.newsInfo, { skip, limit, ...info });
     return res;
   },
   async create({ commit }, payload) {

+ 8 - 23
src/util/axios-wrapper.js

@@ -37,29 +37,20 @@ export default class AxiosWrapper {
     });
     return uri;
   }
-  //替换路由方法
-  static routerChange(uri, router = {}) {
-    let keys = Object.keys(router);
-    keys.forEach(key => {
-      uri = _.replace(uri, `{${key}}`, router[key]);
-    });
-    return uri;
-  }
 
-  $get(uri, router, query, options) {
-    return this.$request(uri, null, query, options, router);
+  $get(uri, query, options) {
+    return this.$request(uri, null, query, options);
   }
 
-  $post(uri, data = {}, router, query, options) {
-    return this.$request(uri, data, query, options, router);
+  $post(uri, data = {}, query, options) {
+    return this.$request(uri, data, query, options);
   }
 
   $delete(uri, data = {}, router, query, options = {}) {
     options = { ...options, method: 'delete' };
     return this.$request(uri, data, query, options, router);
   }
-
-  async $request(uri, data, query, options, router) {
+  async $request(uri, data, query, options) {
     // TODO: 合并query和options
     if (_.isObject(query) && _.isObject(options)) {
       options = { ...options, params: query, method: 'get' };
@@ -70,11 +61,7 @@ export default class AxiosWrapper {
     }
     if (!options) options = {};
     if (options.params) options.params = trimData(options.params);
-    let url = AxiosWrapper.merge(uri, options.params);
-    //处理url部分需要替换参数的情况
-    if (_.isObject(router)) {
-      url = AxiosWrapper.routerChange(url, router);
-    }
+    const url = AxiosWrapper.merge(uri, options.params);
     currentRequests += 1;
     // Indicator.open({
     //   spinnerType: 'fading-circle',
@@ -84,9 +71,7 @@ export default class AxiosWrapper {
       const axios = Axios.create({
         baseURL: this.baseUrl,
       });
-      if (sessionStorage.getItem('token')) {
-        axios.defaults.headers.common.Authorization = util.token;
-      }
+      axios.defaults.headers.common.Authorization = util.token;
       let res = await axios.request({
         method: isNullOrUndefined(data) ? 'get' : 'post',
         url,
@@ -102,7 +87,7 @@ export default class AxiosWrapper {
       }
       // unwrap data
       if (this.unwrap) {
-        res = _.omit(res, ['errmsg', 'details']);
+        res = _.omit(res, ['details']);
         const keys = Object.keys(res);
         if (keys.length === 1 && keys.includes('data')) {
           res = res.data;

+ 25 - 6
src/views/pcenter/parts/infoAdmin.vue

@@ -11,13 +11,12 @@
               <el-table-column prop="title" label="标题" align="center"> </el-table-column>
               <el-table-column prop="publish_time" label="发布时间" align="center"> </el-table-column>
               <el-table-column prop="publish_unit" label="发布单位" align="center"> </el-table-column>
-              <el-table-column prop="publisher" label="发布人" align="center"> </el-table-column>
               <el-table-column label="状态" align="center">
                 <template slot-scope="scope">
                   <span>{{ scope.row.status == '0' ? '草稿' : scope.row.status == '1' ? '审核中' : scope.row.status == '2' ? '审核通过' : '未识别' }}</span>
                 </template>
               </el-table-column>
-              <el-table-column label="操作" align="center">
+              <el-table-column label="操作" align="center" width="220">
                 <template slot-scope="">
                   <el-button size="mini" type="primary">编辑</el-button>
                   <el-button size="mini" type="success">发布</el-button>
@@ -110,6 +109,7 @@
 import upload from '@/components/upload.vue';
 import wangEditor from '@/components/wang-editor.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: news } = createNamespacedHelpers('news');
 export default {
   name: 'infoAdmin',
   props: {},
@@ -163,8 +163,17 @@ export default {
       },
     };
   },
-  created() {},
+  created() {
+    this.searchInfo();
+  },
   methods: {
+    ...news({ newsQuery: 'query', newsCreate: 'create' }),
+    async searchInfo({ skip = 0, limit = 0, col_name = '工作动态', ...info } = {}) {
+      let res = await this.newsQuery({ skip, limit, col_name, ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+      }
+    },
     // 添加
     add() {
       this.display = 'detail';
@@ -175,9 +184,14 @@ export default {
     },
     // 保存草稿
     submitDraft(formName) {
-      this.$refs[formName].validate(valid => {
+      this.$refs[formName].validate(async valid => {
         if (valid) {
           this.form.uid = this.user.uid;
+          this.form.status = '0';
+          let res = await this.newsCreate(this.form);
+          if (this.$checkRes(res)) {
+            console.log(res);
+          }
           console.log(this.form);
         } else {
           console.log('error submit!!');
@@ -187,9 +201,14 @@ export default {
     },
     // 提交
     submitForm(formName) {
-      this.$refs[formName].validate(valid => {
+      this.$refs[formName].validate(async valid => {
         if (valid) {
-          console.log(this.form);
+          this.form.publisher = this.user.uid;
+          this.form.status = '1';
+          let res = await this.newsCreate(this.form);
+          if (this.$checkRes(res)) {
+            console.log(res);
+          }
         } else {
           console.log('error submit!!');
           return false;