feat(phase-3): add hot/cold number analysis with period filter
This commit is contained in:
@@ -52,6 +52,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
$(document).off('click', '.btn-trend').on('click', '.btn-trend', function () {
|
||||
Controller.api.showTrendDialog();
|
||||
});
|
||||
|
||||
// 冷热分析按钮事件
|
||||
$(document).off('click', '.btn-hotcold').on('click', '.btn-hotcold', function () {
|
||||
Controller.api.showHotColdDialog();
|
||||
});
|
||||
},
|
||||
add: function () {
|
||||
Controller.api.bindevent();
|
||||
@@ -145,6 +150,112 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 显示冷热分析弹窗
|
||||
*/
|
||||
showHotColdDialog: function () {
|
||||
var html = '<div style="padding:20px;">' +
|
||||
'<div class="form-group" style="border-bottom:1px solid #eee;padding-bottom:10px;margin-bottom:10px;">' +
|
||||
' <label style="margin-right:15px;">' + __('Query Type') + ':</label>' +
|
||||
' <label class="radio-inline" style="margin-right:15px;">' +
|
||||
' <input type="radio" name="hc-type" value="all" checked> ' + __('All Numbers') +
|
||||
' </label>' +
|
||||
' <label class="radio-inline">' +
|
||||
' <input type="radio" name="hc-type" value="special"> ' + __('Special Only') +
|
||||
' </label>' +
|
||||
'</div>' +
|
||||
'<div class="form-group">' +
|
||||
' <label>' + __('Query Periods') + ':</label>' +
|
||||
' <input type="number" id="hc-periods" class="form-control" value="30" min="10" max="100" style="width:120px;display:inline-block;">' +
|
||||
' <button class="btn btn-primary" id="btn-hc-query" style="margin-left:10px;"><i class="fa fa-search"></i> ' + __('Query') + '</button>' +
|
||||
'</div>' +
|
||||
'<div id="hc-result" style="margin-top:15px;overflow-x:auto;"></div>' +
|
||||
'</div>';
|
||||
|
||||
Layer.open({
|
||||
type: 1,
|
||||
title: __('Hot/Cold Analysis'),
|
||||
area: ['700px', '600px'],
|
||||
content: html,
|
||||
shadeClose: true,
|
||||
success: function (layero, index) {
|
||||
$('#btn-hc-query', layero).on('click', function () {
|
||||
var periods = parseInt($('#hc-periods', layero).val()) || 30;
|
||||
var type = $('input[name="hc-type"]:checked', layero).val();
|
||||
Controller.api.queryHotCold(periods, type, layero);
|
||||
});
|
||||
$('input[name="hc-type"]', layero).on('change', function () {
|
||||
var periods = parseInt($('#hc-periods', layero).val()) || 30;
|
||||
Controller.api.queryHotCold(periods, $(this).val(), layero);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
queryHotCold: function (periods, type, layero) {
|
||||
var $btn = $('#btn-hc-query', layero);
|
||||
$btn.prop('disabled', true);
|
||||
$('#hc-result', layero).html('<div class="text-center"><i class="fa fa-spinner fa-spin"></i> ' + __('Loading') + '</div>');
|
||||
$.ajax({
|
||||
url: 'history/hotColdNumbers',
|
||||
type: 'GET',
|
||||
data: {periods: periods, type: type},
|
||||
dataType: 'json',
|
||||
success: function (ret) {
|
||||
if (ret.code == 1) {
|
||||
Controller.api.renderHotCold(ret.data, layero);
|
||||
} else {
|
||||
$('#hc-result', layero).html('<div class="alert alert-danger">' + (ret.msg || __('Query failed')) + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$('#hc-result', layero).html('<div class="alert alert-danger">' + __('Query failed') + '</div>');
|
||||
},
|
||||
complete: function () {
|
||||
$btn.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
renderHotCold: function (data, layero) {
|
||||
var getColor = function (num) {
|
||||
var color = data.all.find(function (item) { return item.num === num; });
|
||||
if (!color || !color.color) return '#95a5a6';
|
||||
if (color.color.indexOf('红') !== -1) return '#e74c3c';
|
||||
if (color.color.indexOf('蓝') !== -1) return '#3498db';
|
||||
if (color.color.indexOf('绿') !== -1) return '#2ecc71';
|
||||
return '#95a5a6';
|
||||
};
|
||||
|
||||
var getAnimal = function (num) {
|
||||
var item = data.all.find(function (item) { return item.num === num; });
|
||||
return item ? (item.animal || '') : '';
|
||||
};
|
||||
|
||||
var renderSection = function (title, items, icon) {
|
||||
var html = '<div style="margin-bottom:15px;"><h4 style="margin:0 0 8px 0;border-bottom:1px solid #eee;padding-bottom:5px;">' + icon + ' ' + title + '</h4>';
|
||||
html += '<div style="display:flex;flex-wrap:wrap;gap:8px;">';
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
var color = getColor(item.num);
|
||||
var animal = getAnimal(item.num);
|
||||
html += '<div style="text-align:center;background:#f9f9f9;padding:8px;border-radius:6px;min-width:70px;">' +
|
||||
'<span style="display:inline-block;width:36px;height:36px;line-height:36px;text-align:center;border-radius:50%;color:#fff;background-color:' + color + ';font-weight:bold;">' + item.num + '</span>' +
|
||||
'<div style="margin-top:4px;font-size:10px;color:#666;">' + (animal ? animal + '<br>' : '') + '<b>' + item.count + '</b> (' + item.percent + '%)</div>' +
|
||||
'</div>';
|
||||
}
|
||||
html += '</div></div>';
|
||||
return html;
|
||||
};
|
||||
|
||||
var html = '<div style="padding:10px;">' +
|
||||
renderSection('热号 Top 10', data.hot, '<span style="color:#e74c3c;">🔥</span>') +
|
||||
renderSection('冷号 Top 10', data.cold, '<span style="color:#3498db;">❄</span>') +
|
||||
'</div>';
|
||||
|
||||
$('#hc-result', layero).html(html);
|
||||
},
|
||||
|
||||
/**
|
||||
* 显示走势图弹窗
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user