229 lines
10 KiB
JavaScript
229 lines
10 KiB
JavaScript
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||
|
||
var Controller = {
|
||
index: function () {
|
||
Table.api.init({
|
||
extend: {
|
||
index_url: 'history/index' + location.search,
|
||
add_url: 'history/add',
|
||
edit_url: 'history/edit',
|
||
del_url: 'history/del',
|
||
multi_url: 'history/multi',
|
||
import_url: 'history/import',
|
||
table: 'history',
|
||
}
|
||
});
|
||
|
||
var table = $("#table");
|
||
|
||
// 从后端获取颜色映射
|
||
Controller.api.loadColorMap(function () {
|
||
table.bootstrapTable({
|
||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||
pk: 'expect',
|
||
sortName: 'expect',
|
||
columns: [
|
||
[
|
||
{checkbox: true},
|
||
{field: 'expect', title: __('Expect')},
|
||
{field: 'num1', title: __('Num1'), formatter: Controller.api.formatter.numBall},
|
||
{field: 'num2', title: __('Num2'), formatter: Controller.api.formatter.numBall},
|
||
{field: 'num3', title: __('Num3'), formatter: Controller.api.formatter.numBall},
|
||
{field: 'num4', title: __('Num4'), formatter: Controller.api.formatter.numBall},
|
||
{field: 'num5', title: __('Num5'), formatter: Controller.api.formatter.numBall},
|
||
{field: 'num6', title: __('Num6'), formatter: Controller.api.formatter.numBall},
|
||
{field: 'num7', title: __('Num7'), formatter: Controller.api.formatter.numBall},
|
||
{field: 'openTime', title: __('OpenTime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
||
]
|
||
]
|
||
});
|
||
|
||
Table.api.bindevent(table);
|
||
});
|
||
|
||
// 遗漏号码按钮事件
|
||
$(document).off('click', '.btn-missingnum').on('click', '.btn-missingnum', function () {
|
||
Controller.api.showMissingNumDialog();
|
||
});
|
||
},
|
||
add: function () {
|
||
Controller.api.bindevent();
|
||
},
|
||
edit: function () {
|
||
Controller.api.bindevent();
|
||
},
|
||
api: {
|
||
colorMap: {},
|
||
colorMapLoaded: false,
|
||
|
||
/**
|
||
* 从后端加载颜色映射并缓存
|
||
*/
|
||
loadColorMap: function (callback) {
|
||
if (Controller.api.colorMapLoaded) {
|
||
callback();
|
||
return;
|
||
}
|
||
$.ajax({
|
||
url: 'num/getColorMap',
|
||
type: 'GET',
|
||
dataType: 'json',
|
||
success: function (ret) {
|
||
if (ret.code == 1) {
|
||
Controller.api.colorMap = ret.msg;
|
||
}
|
||
Controller.api.colorMapLoaded = true;
|
||
callback();
|
||
}
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 根据数字从映射表中获取颜色
|
||
*/
|
||
getColorByNum: function (num) {
|
||
var color = Controller.api.colorMap[num];
|
||
if (!color) return '#95a5a6';
|
||
// 后端返回中文波色,前端映射为CSS颜色
|
||
if (color.indexOf('红') !== -1) return '#e74c3c';
|
||
if (color.indexOf('蓝') !== -1) return '#3498db';
|
||
if (color.indexOf('绿') !== -1) return '#2ecc71';
|
||
return '#95a5a6';
|
||
},
|
||
|
||
formatter: {
|
||
numBall: function (value, row, index) {
|
||
if (value === null || value === undefined || value === '') return '';
|
||
var num = parseInt(value);
|
||
var color = Controller.api.getColorByNum(num);
|
||
return '<span class="num-ball" style="display:inline-block;width:32px;height:32px;line-height:32px;text-align:center;border-radius:50%;color:#fff;background-color:' + color + ';font-weight:bold;">' + value + '</span>';
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 显示遗漏号码分析弹窗
|
||
*/
|
||
showMissingNumDialog: 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="missing-type" value="all" checked> ' + __('All Numbers') +
|
||
' </label>' +
|
||
' <label class="radio-inline">' +
|
||
' <input type="radio" name="missing-type" value="special"> ' + __('Special Only') +
|
||
' </label>' +
|
||
'</div>' +
|
||
'<div class="form-group">' +
|
||
' <label>' + __('Query Periods') + ':</label>' +
|
||
' <input type="number" id="missing-periods" class="form-control" value="10" min="1" max="100" style="width:120px;display:inline-block;">' +
|
||
' <button class="btn btn-primary" id="btn-missing-query" style="margin-left:10px;"><i class="fa fa-search"></i> ' + __('Query') + '</button>' +
|
||
'</div>' +
|
||
'<div id="missing-result" style="margin-top:15px;"></div>' +
|
||
'</div>';
|
||
|
||
Layer.open({
|
||
type: 1,
|
||
title: __('Missing Number Analysis'),
|
||
area: ['650px', '550px'],
|
||
content: html,
|
||
shadeClose: true,
|
||
success: function (layero, index) {
|
||
// 绑定查询按钮事件
|
||
$('#btn-missing-query', layero).on('click', function () {
|
||
var periods = parseInt($('#missing-periods', layero).val()) || 10;
|
||
var type = $('input[name="missing-type"]:checked', layero).val();
|
||
Controller.api.queryMissingNum(periods, type, layero);
|
||
});
|
||
// 切换类型时自动查询
|
||
$('input[name="missing-type"]', layero).on('change', function () {
|
||
var periods = parseInt($('#missing-periods', layero).val()) || 10;
|
||
Controller.api.queryMissingNum(periods, $(this).val(), layero);
|
||
});
|
||
}
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 查询遗漏号码
|
||
*/
|
||
queryMissingNum: function (periods, type, layero) {
|
||
// 确保颜色映射已加载
|
||
if (!Controller.api.colorMapLoaded) {
|
||
Controller.api.loadColorMap(function () {
|
||
Controller.api._doQueryMissingNum(periods, type, layero);
|
||
});
|
||
} else {
|
||
Controller.api._doQueryMissingNum(periods, type, layero);
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 执行遗漏号码查询(内部方法)
|
||
*/
|
||
_doQueryMissingNum: function (periods, type, layero) {
|
||
var $btn = $('#btn-missing-query', layero);
|
||
$btn.prop('disabled', true);
|
||
$('#missing-result', layero).html('<div class="text-center"><i class="fa fa-spinner fa-spin"></i> ' + __('Loading') + '</div>');
|
||
$.ajax({
|
||
url: 'history/missingNum',
|
||
type: 'GET',
|
||
data: {periods: periods, type: type},
|
||
dataType: 'json',
|
||
success: function (ret) {
|
||
if (ret.code == 1) {
|
||
Controller.api.renderMissingNum(ret.data, periods, layero);
|
||
} else {
|
||
$('#missing-result', layero).html('<div class="alert alert-danger">' + (ret.msg || __('Query failed')) + '</div>');
|
||
}
|
||
},
|
||
error: function () {
|
||
$('#missing-result', layero).html('<div class="alert alert-danger">' + __('Query failed') + '</div>');
|
||
},
|
||
complete: function () {
|
||
$btn.prop('disabled', false);
|
||
}
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 渲染遗漏号码结果
|
||
*/
|
||
renderMissingNum: function (data, periods, layero) {
|
||
if (!data || data.length === 0) {
|
||
$('#missing-result', layero).html('<div class="alert alert-info">' + __('No missing numbers found') + '</div>');
|
||
return;
|
||
}
|
||
var container = $('<div style="display:flex;flex-wrap:wrap;gap:12px;"></div>');
|
||
for (var i = 0; i < data.length; i++) {
|
||
var color = Controller.api.getColorByNum(data[i].num);
|
||
var $item = $('<div style="text-align:center;"></div>');
|
||
var $ball = $('<span class="num-ball"></span>').css({
|
||
'display': 'inline-block',
|
||
'width': '48px',
|
||
'height': '48px',
|
||
'line-height': '48px',
|
||
'text-align': 'center',
|
||
'border-radius': '50%',
|
||
'color': '#fff',
|
||
'background-color': color,
|
||
'font-weight': 'bold',
|
||
'font-size': '18px'
|
||
}).text(data[i].num);
|
||
var $label = $('<div style="margin-top:5px;font-size:12px;color:#666;"></div>').text(
|
||
__('Missing') + ' ' + data[i].omit + ' ' + __('periods')
|
||
);
|
||
$item.append($ball).append($label);
|
||
container.append($item);
|
||
}
|
||
$('#missing-result', layero).html('').append(container);
|
||
},
|
||
|
||
bindevent: function () {
|
||
Form.api.bindevent($("form[role=form]"));
|
||
}
|
||
}
|
||
};
|
||
return Controller;
|
||
});
|