出现规则:
数组a包含着所有的推荐弹窗的内容和最大显示次数
先从数组a随机挑选一个数组记录次数 记录时间戳 再次打开是记录时间戳 比较这两个的时间
function pushDialog(){
var current_time = new Date().getTime();
var last_time = $api.getStorage('dialog_lastest_time');
if(current_time <= last_time + 3600 * 1000){
return;
}
var current_day = new Date().setHours(0, 0, 0, 0)/1000;
console.log('===============' + current_day);
sjzRequest({
url: apiUrl.settings.getdialog,
method: 'get',
success: function(ret, err){
if(ret.code == 0){
return;
}
if(!ret.data || ret.data.length == 0){
return;
}
var d = ret.data;
console.log(JSON.stringify(d));
while(true){
if(d.length <= 0){
console.log('it\'s over -----');
return;
}
var item = getDialogItem(d);
console.log(JSON.stringify(item));
count = $api.getStorage('dialog_times_' + current_day + '_' + item[1].id);
count = count ? count : 0;
console.log(count);
if(count <= item[1].show_num){
break;
}else{
d.splice(item[0], 1);
}
}
$api.setStorage('dialog_lastest_time', current_time);
count++;
$api.setStorage('dialog_times_' + current_day + '_' + item[1].id , count);
var pageParam = {
'title':item[1].title,
'img':item[1].img_url
}
// console.log(item[1].title);
showDialogFrame(pageParam);
}
});
}
function getDialogItem(d){
var index = Math.floor(Math.random() * d.length);
return [index, d[index]];
}
function showDialogFrame(pageParam){
api.openFrame({
name: 'recomcom1',
url: 'recomcom_frm.html',
rect: {
x:0,
y:0,
w:api.winWidth,
h:api.winHeight
},
pageParam: pageParam,
bgColor: 'rgba(0,0,0,0.6)',
bounces: false
});
}