lrf402788946 5 éve
szülő
commit
359acc5e56
2 módosított fájl, 30 hozzáadás és 16 törlés
  1. 2 2
      src/components/index.vue
  2. 28 14
      src/views/index.vue

+ 2 - 2
src/components/index.vue

@@ -36,7 +36,7 @@
               <daohang :list="list" v-on="$listeners"></daohang>
             </el-col>
           </el-col>
-          <el-col :span="24" class="main_3" v-if="adv.adv1">
+          <el-col :span="24" class="main_3" v-if="adv.adv1_use">
             <weilai :info="adv.adv1"></weilai>
           </el-col>
           <el-col :span="24" class="main_4">
@@ -54,7 +54,7 @@
         <el-col :span="24" class="main_5">
           <recruit :recruitList="recruitList" :zixunList="zixunList"></recruit>
         </el-col>
-        <el-col :span="24" class="main_3" v-if="adv.adv2">
+        <el-col :span="24" class="main_3" v-if="adv.adv2_use">
           <div class="w_1270">
             <weilai :info="adv.adv2"></weilai>
           </div>

+ 28 - 14
src/views/index.vue

@@ -108,6 +108,7 @@ export default {
     this.toGetModule(); //获取模块信息
     this.toGetJobInfo(); //获取招聘信息
     this.getAdv();
+    this.setJSONConfig(); //设置JSON格式配置
     // this.toGetLinks(); //招聘信息+网站链接
     // this.self();
   },
@@ -286,23 +287,36 @@ export default {
         this.$router.push({ path: '/quiet', query: { title: title } });
       }
     },
+    //处理JSON设置
+    setJSONConfig() {
+      let configs = _.get(this.site, 'configs');
+      if (_.isString(configs)) {
+        let con = JSON.parse(configs);
+        let adv = con.advert;
+        if (_.isArray(adv)) {
+          adv.map(i => {
+            this.$set(this.adv, `adv${i}_use`, true);
+          });
+        }
+      }
+    },
     //请求广告列表
     async getAdv() {
-      let res = await this.advQuery({ skip: 0, limit: 2 });
-      if (this.$checkRes(res)) {
-        let adv1 = res.data[0];
-        let adv2 = res.data[1];
-        if (adv1 && adv1.type == '0') {
-          let Obj = JSON.parse(adv1.url);
-          adv1.url = `/newsList/module/${Obj.id}?title=${Obj.title}`;
-        }
-        this.$set(this, `adv`, { ...this.adv, adv1 });
-        if (adv2 && adv2.type == '0') {
-          let Obj = JSON.parse(adv2.url);
-          adv2.url = `/newsList/module/${Obj.id}?title=${Obj.title}`;
+      let res1 = await this.advQuery({ skip: 0, limit: 1, is_use: '0', type: '1' });
+      let res0 = await this.advQuery({ skip: 0, limit: 1, is_use: '0', type: '0' });
+      let method = (res, index) => {
+        if (this.$checkRes(res)) {
+          let adv = res.data[0];
+          if (adv && adv.type == '0') {
+            let Obj = JSON.parse(adv.url);
+            adv.url = `/newsList/module/${Obj.id}?title=${Obj.title}`;
+          }
+          if (index == '1') this.$set(this, `adv`, { ...this.adv, adv1: adv });
+          else this.$set(this, `adv`, { ...this.adv, adv2: adv });
         }
-        this.$set(this, `adv`, { ...this.adv, adv2 });
-      }
+      };
+      method(res1, 1);
+      method(res0, 0);
     },
   },
 };