mixin.js
7.76 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import module from './module';
import _ from 'underscore';
import moduleConfig from '../module.config';
const dayHideCharts = ['period_passenger_distribution', 'zone_passenger_distribution', 'format_period_passenger_flow_heat', 'floor_period_passenger_flow_heat', 'mall_period_passenger_flow_heat'];
/*节流阀函数*/
function throttle(fn, wait) {
let pre = Date.now();
return function() {
let context = this;
let args = arguments;
let now = Date.now();
if (now - pre >= wait) {
fn.apply(context, args);
pre = Date.now();
}
}
}
export default {
props: {
emitData: {
type: Object,
default: () => {}
}
},
provide() {
return {
addModule: this.addModule,
getChartId: this.getChartId,
getChartName: this.getChartName,
getCardIds: this.getCardIds,
getCardList: this.getCardList,
getChartList: this.getChartList,
evtReport: this.evtReport
}
},
watch: {
emitData: {
handler(newVal, val) {
if (Object.keys(newVal).length == 0) return;
this.checkReload(newVal);
},
immediate: true,
deep: true
}
},
components: {
module
},
data() {
return {
params: {},
chartIdsList: [], //图表chard_id集合
moduleList: [], //当前页面下的报表集合
cardList: [], //卡片列表
chartList: [], //报表列表
}
},
methods: {
/**
* 查询条件改变时候,检测是否触发当前页面刷新
* */
checkReload(emitData) {
let isSet = false;
Object.keys(emitData).forEach(key => {
if (emitData[key] != this.params[key]) {
if (emitData.radio == 'count' && key == 'floorIds') {
} else {
isSet = true;
}
}
})
if (true || isSet || emitData.force) {
let isGetChart = false;
if (emitData.mallIds != this.params.mallIds) {
isGetChart = true;
}
this.params = emitData;
this.resetLoaded(isGetChart);
}
},
pageScroll: _.throttle(function(evt) {
this.loadView();
}, 200),
/**
* 滚动事件触发时调用,是否需要加载指定图表
* */
loadView() {
let modules = this.getInToView();
modules.forEach(module => {
module.loadModuleData && module.loadModuleData(this.params);
})
},
/**
* 添加图表实例到当前页面
* */
addModule(module) {
this.moduleList.push(module);
},
/**
* 获取chart对应的 id
* */
getChartId(mkey) {
if (!mkey) return false;
let curChart = this.chartIdsList.find(item => {
return item.chartKey == mkey
});
if (!curChart) {
curChart = this.cardList.find(item => {
return item.chartKey == mkey
});
}
return curChart && curChart.id || false;
},
/**
* 获取chart对应的 title
* */
getChartName(mkey) {
if (!mkey) return false;
let curChart = this.chartIdsList.find(item => {
return item.chartKey == mkey
});
if (localStorage.lang.includes('en')) {
return curChart && curChart.titleEn || false;
}
return curChart && curChart.title || false;
},
/**
* 获取卡片对应的 [id]集合
* */
getCardIds() {
let orgType = this.params.orgType;
let radio = this.params.radio;
return this.chartIdsList.filter(item => {
return item.type == 'card' && (orgType == 'zone' ? (radio == 'count' ? item.style == 'front' : item.style != 'front') : true)
}).reduce((cards, card) => {
cards.push(card.id);
return cards;
}, []);
},
getCardList() {
return this.cardList;
},
getChartList() {
return this.chartList;
},
/**
* 检测图表是否滚动到可视区域
* */
getInToView() {
return this.moduleList.filter(module => {
if (module.loaded) return false;
let position = module.$el.getBoundingClientRect();
if ((0 < position.top && position.top < window.innerHeight) || (0 < position.bottom && position.top < 0)) {
return true;
}
})
},
/**
* 重置图表的加载状态
* */
resetLoaded(reset) {
this.moduleList.forEach(module => {
module.resetLoaded();
});
if (this.chartIdsList.length > 0 && !reset) {
this.loadView();
} else {
let title = localStorage.getItem('lang').toLowerCase() == 'en_us' ? 'titleEn' : 'title';
let mallId = this.params.mallIds || this.$cookie.get('mallId');
let accountId = this.$cookie.get('accountId');
this.$api.ipageReport.getCharts({ belongTo: this.reportType, showIndex: this.params.radio == 'detail' ? 2 : 1, mallId, accountId }).then(res => {
this.cardList = (res.data.data.cards || []).sort((it1, it2) => {
return it1.sort - it2.sort
});
let chartList = _.map((res.data.data.charts || []).sort((it1, it2) => {
return it1.sort - it2.sort
}), item => {
let otherConf = moduleConfig[item.chartKey] || {};
item.mallId = mallId;
Object.assign(item, otherConf, { title: item[title] });
return item;
});
if (this.cardList.length) {
chartList.unshift({
chartKey: 'card',
mkey: 'card',
mallId: mallId,
columnNum: 1
})
}
if (this.params.dateType == 'day') {
chartList = _.filter(chartList, item => {
return !dayHideCharts.includes(item.chartKey);
})
}
this.chartList = _.filter(chartList, item => {
return moduleConfig[item.chartKey] ? true : false;
});
this.chartIdsList = res.data.data.allCharts || [];
this.$nextTick(() => {
this.loadView();
})
})
// this.$api.baseReport.reportChart({ report: this.reportType }).then(res => {
// let { data } = res.data;
// this.chartIdsList = data;
// this.loadView();
// })
}
},
/**
* 图表逐层上报事件
* */
evtReport(data) {
debugger
this.$emit('reportEvt', data);
}
},
created: function() {
},
mounted() {
}
};