Authored by 李奇

组件优化

1 <template> 1 <template>
2 <div class="resource-category"> 2 <div class="resource-category">
3 <a-link class="cate-label" :href="brandLink">品牌<i class="icon icon-right"></i></a-link> 3 <a-link class="cate-label" :href="brandLink">品牌<i class="icon icon-right"></i></a-link>
4 - <div v-for="(item, index) in value" v-if="item.sub"> 4 + <div v-for="(item, index) in sort" v-if="item.sub">
5 <p class="cate-label" @click="toggle(index)">{{item.category_name 5 <p class="cate-label" @click="toggle(index)">{{item.category_name
6 }}<i class="icon" :class="sortClass[index]"></i></p> 6 }}<i class="icon" :class="sortClass[index]"></i></p>
7 <div class="cate-items" v-if="show[index]"> 7 <div class="cate-items" v-if="show[index]">
@@ -24,10 +24,7 @@ import Resource from './resource'; @@ -24,10 +24,7 @@ import Resource from './resource';
24 export default { 24 export default {
25 name: 'ResourceCategory', 25 name: 'ResourceCategory',
26 props: { 26 props: {
27 - value: Array,  
28 - gender: {  
29 - type: String  
30 - } 27 + value: Object
31 }, 28 },
32 data() { 29 data() {
33 return { 30 return {
@@ -41,6 +38,12 @@ export default { @@ -41,6 +38,12 @@ export default {
41 }, 38 },
42 genderCvt() { 39 genderCvt() {
43 return { men: '1,3', women: '2,3' }[this.gender]; 40 return { men: '1,3', women: '2,3' }[this.gender];
  41 + },
  42 + gender() {
  43 + return this.value.gender;
  44 + },
  45 + sort() {
  46 + return this.value.sort;
44 } 47 }
45 }, 48 },
46 methods: { 49 methods: {
@@ -52,11 +55,11 @@ export default { @@ -52,11 +55,11 @@ export default {
52 }); 55 });
53 }, 56 },
54 getAllSortId(idx) { 57 getAllSortId(idx) {
55 - return this.value[idx].sub.map(sort=>sort.relation_parameter.sort).join(',') + ','; 58 + return this.value.sort[idx].sub.map(sort=>sort.relation_parameter.sort).join(',') + ',';
56 } 59 }
57 }, 60 },
58 created() { 61 created() {
59 - const len = this.value.length; 62 + const len = this.sort.length;
60 63
61 this.show = []; 64 this.show = [];
62 for (let i = 0; i < len; i++) { 65 for (let i = 0; i < len; i++) {
@@ -10,19 +10,11 @@ @@ -10,19 +10,11 @@
10 <i class="icon icon-search-new" @click="searchSliderSwitch"></i> 10 <i class="icon icon-search-new" @click="searchSliderSwitch"></i>
11 </span> 11 </span>
12 </header-box> 12 </header-box>
13 - <div class="resources" v-for="floor in data.data">  
14 - <resource-category :gender="gender" :value="data.sort" v-if="floor.category"></resource-category>  
15 - <resource-focus-image v-if="floor.template_name=='focus'" :value="floor.data"></resource-focus-image>  
16 - <resource-single-image v-if="floor.template_name =='newSingleImage'"  
17 - :value="floor.data.list[0]"></resource-single-image>  
18 - <div class="shop-floor" v-if="floor.template_name=='shopFloor'">  
19 - <resource-single-image :value="floor.data.list[0]"></resource-single-image>  
20 - <resource-product-list :value="products"></resource-product-list>  
21 - </div>  
22 - <div class="new-arrival-floor" v-if="floor.template_name=='BlkNewProductFloorResource'">  
23 - <resource-product-list :value="floor.data.list"></resource-product-list>  
24 - </div>  
25 - </div> 13 + <component
  14 + :is="component.template_name"
  15 + v-for="(component, index) in floors.filter(c => ['focus', 'category', 'newSingleImage'].some(k => k === c.template_name) )"
  16 + :value="component.data"
  17 + :key="index"></component>
26 </layout-body> 18 </layout-body>
27 </div> 19 </div>
28 </template> 20 </template>
@@ -102,8 +94,8 @@ @@ -102,8 +94,8 @@
102 gender() { 94 gender() {
103 return this.$store.state.channel.gender; 95 return this.$store.state.channel.gender;
104 }, 96 },
105 - data() {  
106 - return this.$store.state.channel[this.gender]; 97 + floors() {
  98 + return this.$store.state.channel[this.gender].floors;
107 } 99 }
108 }, 100 },
109 asyncData({store, router: to}) { 101 asyncData({store, router: to}) {
@@ -111,9 +103,9 @@ @@ -111,9 +103,9 @@
111 return store.dispatch(FETCH_CHANNEL_REQUEST, gender); 103 return store.dispatch(FETCH_CHANNEL_REQUEST, gender);
112 }, 104 },
113 components: { 105 components: {
114 - ResourceCategory,  
115 - ResourceFocusImage,  
116 - ResourceSingleImage, 106 + focus: ResourceFocusImage,
  107 + newSingleImage: ResourceSingleImage,
  108 + category: ResourceCategory,
117 ResourceProductList, 109 ResourceProductList,
118 SearchSlider 110 SearchSlider
119 } 111 }
@@ -23,12 +23,12 @@ export default { @@ -23,12 +23,12 @@ export default {
23 gender: 'men', 23 gender: 'men',
24 men: { 24 men: {
25 sort: {}, 25 sort: {},
26 - data: {}, 26 + floors: {},
27 isFetching: false 27 isFetching: false
28 }, 28 },
29 women: { 29 women: {
30 sort: {}, 30 sort: {},
31 - data: {}, 31 + floors: {},
32 isFetching: false 32 isFetching: false
33 }, 33 },
34 fethingHome: false, 34 fethingHome: false,
@@ -72,9 +72,14 @@ export default { @@ -72,9 +72,14 @@ export default {
72 72
73 // mock data 73 // mock data
74 data.splice(1, 0 , { 74 data.splice(1, 0 , {
75 - category: true 75 + template_name: 'category',
  76 + data: {
  77 + gender: 'men',
  78 + sort: sort[keyCvt[state.gender]]
  79 +
  80 + }
76 }); 81 });
77 - state[state.gender].data = data; 82 + state[state.gender].floors = data;
78 state[state.gender].sort = sort[keyCvt[state.gender]]; 83 state[state.gender].sort = sort[keyCvt[state.gender]];
79 }, 84 },
80 }, 85 },