Authored by ccbikai

优化资源位

@@ -5,7 +5,7 @@ const resourcesProcess = require('../../../utils/resources-process'); @@ -5,7 +5,7 @@ const resourcesProcess = require('../../../utils/resources-process');
5 let channel = { 5 let channel = {
6 getResourcesData(params) { 6 getResourcesData(params) {
7 if (!params.contentCode) { 7 if (!params.contentCode) {
8 - return Promise.reject([]); 8 + return Promise.resolve([]);
9 } 9 }
10 return api.get('operations/api/v5/resource/get', { 10 return api.get('operations/api/v5/resource/get', {
11 content_code: params.contentCode 11 content_code: params.contentCode
1 -<div id="app">  
2 - <tab></tab>  
3 - <resources></resources> 1 +<div id="channel">
  2 + <tab v-bind:page="page"></tab>
  3 + <resources v-bind:content-code.sync="contentCode"></resources>
4 </div> 4 </div>
1 const Vue = require('yoho-vue'); 1 const Vue = require('yoho-vue');
2 const lazyload = require('yoho-vue-lazyload'); 2 const lazyload = require('yoho-vue-lazyload');
  3 +const qs = require('yoho-qs');
  4 +const contentCode = require('content-code');
3 5
4 const tab = require('channel/tab.vue'); 6 const tab = require('channel/tab.vue');
5 const resources = require('channel/resources.vue'); 7 const resources = require('channel/resources.vue');
6 8
7 require('common/vue-filter'); 9 require('common/vue-filter');
8 10
9 -Vue.use(lazyload, {  
10 - try: 2  
11 -}); 11 +Vue.use(lazyload);
12 12
13 new Vue({ 13 new Vue({
14 - el: '#app', 14 + el: '#channel',
  15 + data() {
  16 + return {
  17 + page: 'channel',
  18 + contentCode: contentCode.channel[qs.channel || 'men']
  19 + };
  20 + },
15 components: { 21 components: {
16 tab: tab, 22 tab: tab,
17 resources: resources 23 resources: resources
@@ -39,7 +39,12 @@ @@ -39,7 +39,12 @@
39 const dataCache = {}; 39 const dataCache = {};
40 40
41 module.exports = { 41 module.exports = {
42 - props: ['contentCode'], 42 + props: {
  43 + contentCode: {
  44 + type: String,
  45 + default: contentCode.channel.men
  46 + }
  47 + },
43 data() { 48 data() {
44 return { 49 return {
45 resources: [] 50 resources: []
@@ -64,8 +69,6 @@ @@ -64,8 +69,6 @@
64 69
65 if (this.contentCode) { 70 if (this.contentCode) {
66 data.contentCode = this.contentCode; 71 data.contentCode = this.contentCode;
67 - } else {  
68 - data.contentCode = contentCode.channel.men;  
69 } 72 }
70 73
71 let param = $.param(data); 74 let param = $.param(data);
@@ -91,8 +94,8 @@ @@ -91,8 +94,8 @@
91 }, 94 },
92 created() { 95 created() {
93 this.getResourcesData(); 96 this.getResourcesData();
94 - bus.$on('changeChannel', channel => {  
95 - this.contentCode = contentCode.channel[channel]; 97 + bus.$on('changeChannel', (page, channel) => {
  98 + this.contentCode = contentCode[page][channel];
96 }); 99 });
97 } 100 }
98 }; 101 };
@@ -15,6 +15,10 @@ @@ -15,6 +15,10 @@
15 type: Number, 15 type: Number,
16 default: 0 16 default: 0
17 }, 17 },
  18 + page: {
  19 + type: String,
  20 + default: 'channel'
  21 + },
18 }, 22 },
19 data() { 23 data() {
20 return { 24 return {
@@ -33,7 +37,7 @@ @@ -33,7 +37,7 @@
33 methods: { 37 methods: {
34 changeChannel(index) { 38 changeChannel(index) {
35 this.current = index; 39 this.current = index;
36 - bus.$emit('changeChannel', this.channel[index].channel); 40 + bus.$emit('changeChannel', this.page, this.channel[index].channel);
37 } 41 }
38 } 42 }
39 }; 43 };