index.vue
3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
<div class="resources">
<div v-for="(floor, index) in resources" :key="index">
<focus v-if="floor.focus && floor.focus_type === '1'" :floor="floor.data" :style="{height: '9.1rem'}">
<!-- 轮播图,通栏 -->
</focus>
<focus-left-right v-if="floor.focus && floor.focus_type === '2'" :floor="floor.data">
<!-- 轮播图,左右滑动 -->
</focus-left-right>
<title-image v-if="floor.titleImage" :floor="floor.data">
<!-- 标题图片 -->
</title-image>
<title-floor v-if="floor.titleFloor" :title="floor.data.title">
<!-- 楼层标题 -->
</title-floor>
<recommend-content-five v-if="floor.recommendContentFive" :floor="floor.data.list">
<!-- 带标题的12个小图推荐 -->
</recommend-content-five>
<goods v-if="floor.goods" :floor="floor.data">
<!-- 商品 -->
</goods>
</div>
</div>
</template>
<script>
import $ from 'jquery';
import tip from 'common/tip';
import bus from 'common/vue-bus';
import contentCode from 'content-code';
import focus from './focus.vue';
import focusLeftRight from './focus-left-right.vue';
import titleImage from './title-image.vue';
import titleFloor from './title-floor.vue';
import recommendContentFive from './recommend-content-five.vue';
import goods from './goods.vue';
const dataCache = {};
export default {
props: {
contentCode: {
type: String,
default: contentCode.channel.men
}
},
data() {
return {
scroll_y: 0,
objY: {},
resources: [],
currentContentCode: this.contentCode,
};
},
components: {
focus,
focusLeftRight,
titleImage,
titleFloor,
recommendContentFive,
goods
},
watch: {
contentCode(val) {
this.currentContentCode = val;
this.load();
}
},
methods: {
load() {
this.getResourcesData();
bus.$emit('contentCode.change', this.currentContentCode);
setTimeout(()=> {
window.scrollTo(0, this.scroll_y);
}, 1);
},
getResourcesData() {
let data = {};
if (this.currentContentCode) {
data.contentCode = this.currentContentCode;
}
let param = $.param(data);
if (dataCache[param]) {
this.resources = dataCache[param];
return;
}
return $.ajax({
url: '/channel/resources.json',
data: data
}).then(result => {
this.resources = result;
if (result.length) {
dataCache[param] = result;
}
setTimeout(()=> {
$('#ssr').remove();
}, 1000);
}).fail(() => {
tip('网络错误');
});
}
},
created() {
this.getResourcesData();
bus.$on('channel.change', (page, channel, objY) => {
if (objY) {
this.objY = Object.assign(this.objY, objY);
}
this.scroll_y = this.objY[page + '_' + channel] || 0;
this.currentContentCode = contentCode[page][channel];
this.load();
});
}
};
</script>
<style>
.resources {
background: #f6f6f6;
}
</style>