fix: rewrite dashboard JS as proper RequireJS module, remove inline script
This commit is contained in:
@@ -30,126 +30,3 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
|
||||||
<script>
|
|
||||||
$(function () {
|
|
||||||
var getColor = function (color) {
|
|
||||||
if (!color || color === '—') return '#95a5a6';
|
|
||||||
if (color.indexOf('红') !== -1) return '#e74c3c';
|
|
||||||
if (color.indexOf('蓝') !== -1) return '#3498db';
|
|
||||||
if (color.indexOf('绿') !== -1) return '#2ecc71';
|
|
||||||
return '#95a5a6';
|
|
||||||
};
|
|
||||||
|
|
||||||
var ball = function (num, color) {
|
|
||||||
return '<span class="num-ball-sm" style="background-color:' + getColor(color) + ';">' + num + '</span>';
|
|
||||||
};
|
|
||||||
|
|
||||||
function loadData() {
|
|
||||||
var periods = parseInt($('#dash-periods').val()) || 30;
|
|
||||||
if (periods < 10) periods = 10;
|
|
||||||
if (periods > 100) periods = 100;
|
|
||||||
$('#dash-content').html('<div class="text-center" style="padding:60px;"><i class="fa fa-spinner fa-spin fa-2x"></i><br><span class="text-muted">{:__("Loading")}</span></div>');
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: 'history/dashboard',
|
|
||||||
type: 'GET',
|
|
||||||
data: {periods: periods},
|
|
||||||
dataType: 'json',
|
|
||||||
success: function (ret) {
|
|
||||||
if (ret.code != 1) {
|
|
||||||
$('#dash-content').html('<div class="alert alert-danger">' + (ret.msg || '加载失败') + '</div>');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
render(ret.data);
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
$('#dash-content').html('<div class="alert alert-danger">请求失败,请重试</div>');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function render(data) {
|
|
||||||
var hc = data.hotcold, cw = data.colorwave, zo = data.zodiac;
|
|
||||||
var oe = data.oddeven, bs = data.bigsmall, sm = data.sum, tn = data.tailnumbers;
|
|
||||||
|
|
||||||
var html = '';
|
|
||||||
|
|
||||||
// 冷热号码
|
|
||||||
html += '<div class="dash-section"><h4>🔥❄️ 冷热号码</h4><div class="row">';
|
|
||||||
html += '<div class="col-sm-6"><div class="dash-card" style="border-left:3px solid #e74c3c;"><div style="color:#e74c3c;font-weight:bold;margin-bottom:8px;">热号 Top 5</div>';
|
|
||||||
for (var i = 0; i < 5; i++) html += ball(hc.hot[i].num, hc.hot[i].color) + ' ';
|
|
||||||
html += '</div></div>';
|
|
||||||
html += '<div class="col-sm-6"><div class="dash-card" style="border-left:3px solid #3498db;"><div style="color:#3498db;font-weight:bold;margin-bottom:8px;">冷号 Top 5</div>';
|
|
||||||
for (var i = 0; i < 5; i++) html += ball(hc.cold[i].num, hc.cold[i].color) + ' ';
|
|
||||||
html += '</div></div></div></div>';
|
|
||||||
|
|
||||||
// 波色 & 奇偶 & 大小
|
|
||||||
html += '<div class="dash-section"><h4>📊 比例分析</h4><div class="row">';
|
|
||||||
|
|
||||||
// 波色
|
|
||||||
html += '<div class="col-sm-4"><div class="dash-card"><div style="font-weight:bold;margin-bottom:8px;">🎨 波色</div>';
|
|
||||||
html += '<div style="display:flex;justify-content:space-around;">';
|
|
||||||
html += '<div><div style="font-size:24px;font-weight:bold;color:#e74c3c;">' + cw.red + '</div><div class="label-text">红波 ' + cw.red_pct + '%</div></div>';
|
|
||||||
html += '<div><div style="font-size:24px;font-weight:bold;color:#3498db;">' + cw.blue + '</div><div class="label-text">蓝波 ' + cw.blue_pct + '%</div></div>';
|
|
||||||
html += '<div><div style="font-size:24px;font-weight:bold;color:#2ecc71;">' + cw.green + '</div><div class="label-text">绿波 ' + cw.green_pct + '%</div></div>';
|
|
||||||
html += '</div></div></div>';
|
|
||||||
|
|
||||||
// 奇偶
|
|
||||||
html += '<div class="col-sm-4"><div class="dash-card"><div style="font-weight:bold;margin-bottom:8px;">⚖️ 奇偶</div>';
|
|
||||||
html += '<div style="display:flex;justify-content:space-around;">';
|
|
||||||
html += '<div><div style="font-size:24px;font-weight:bold;color:#e74c3c;">' + oe.odd + '</div><div class="label-text">奇数 ' + oe.odd_pct + '%</div></div>';
|
|
||||||
html += '<div><div style="font-size:24px;font-weight:bold;color:#3498db;">' + oe.even + '</div><div class="label-text">偶数 ' + oe.even_pct + '%</div></div>';
|
|
||||||
html += '</div></div></div>';
|
|
||||||
|
|
||||||
// 大小
|
|
||||||
html += '<div class="col-sm-4"><div class="dash-card"><div style="font-weight:bold;margin-bottom:8px;">📏 大小</div>';
|
|
||||||
html += '<div style="display:flex;justify-content:space-around;">';
|
|
||||||
html += '<div><div style="font-size:24px;font-weight:bold;color:#f39c12;">' + bs.big + '</div><div class="label-text">大数 ' + bs.big_pct + '%</div></div>';
|
|
||||||
html += '<div><div style="font-size:24px;font-weight:bold;color:#2ecc71;">' + bs.small + '</div><div class="label-text">小数 ' + bs.small_pct + '%</div></div>';
|
|
||||||
html += '</div></div></div>';
|
|
||||||
|
|
||||||
html += '</div></div>';
|
|
||||||
|
|
||||||
// 生肖
|
|
||||||
html += '<div class="dash-section"><h4>⭐ 生肖排名</h4><div style="display:flex;flex-wrap:wrap;">';
|
|
||||||
for (var i = 0; i < Math.min(zo.list.length, 12); i++) {
|
|
||||||
var z = zo.list[i];
|
|
||||||
html += '<div class="mini-card"><div class="name">' + z.animal + '</div><div class="val">' + z.count + ' (' + z.percent + '%)</div></div>';
|
|
||||||
}
|
|
||||||
html += '</div></div>';
|
|
||||||
|
|
||||||
// 和值
|
|
||||||
html += '<div class="dash-section"><h4>📈 和值统计</h4><div class="row">';
|
|
||||||
html += '<div class="col-sm-4"><div class="dash-card"><div class="big-num">' + sm.avg + '</div><div class="label-text">平均和值</div></div></div>';
|
|
||||||
html += '<div class="col-sm-4"><div class="dash-card"><div class="big-num" style="color:#e74c3c;">' + sm.max + '</div><div class="label-text">最大和值</div></div></div>';
|
|
||||||
html += '<div class="col-sm-4"><div class="dash-card"><div class="big-num" style="color:#3498db;">' + sm.min + '</div><div class="label-text">最小和值</div></div></div>';
|
|
||||||
html += '</div><div id="dash-chart" style="margin-top:15px;"></div></div>';
|
|
||||||
|
|
||||||
// 尾数
|
|
||||||
html += '<div class="dash-section"><h4>🔢 尾数频率</h4><div style="display:flex;flex-wrap:wrap;">';
|
|
||||||
for (var i = 0; i < tn.all.length; i++) {
|
|
||||||
var t = tn.all[i];
|
|
||||||
html += '<div class="mini-card"><div class="name">' + t.tail + '</div><div class="val">' + t.count + ' (' + t.percent + '%)</div></div>';
|
|
||||||
}
|
|
||||||
html += '</div></div>';
|
|
||||||
|
|
||||||
$('#dash-content').html(html);
|
|
||||||
|
|
||||||
// 和值折线图
|
|
||||||
if (typeof echarts !== 'undefined' && sm.expects && sm.expects.length > 0) {
|
|
||||||
var chart = echarts.init(document.getElementById('dash-chart'));
|
|
||||||
chart.setOption({
|
|
||||||
tooltip: {trigger: 'axis'},
|
|
||||||
xAxis: {type: 'category', data: sm.expects, axisLabel: {rotate: 45, fontSize: 10}},
|
|
||||||
yAxis: {type: 'value'},
|
|
||||||
series: [{type: 'line', data: sm.sums, smooth: true, itemStyle: {color: '#3498db'}, areaStyle: {color: 'rgba(52,152,219,0.1)'}}],
|
|
||||||
grid: {left: 50, right: 20, bottom: 50, top: 20}
|
|
||||||
});
|
|
||||||
$(window).on('resize', function () { chart.resize(); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#btn-dash-refresh').on('click', loadData);
|
|
||||||
loadData();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -1,78 +1,115 @@
|
|||||||
define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {
|
define(['jquery'], function ($) {
|
||||||
|
|
||||||
var Controller = {
|
var Controller = {
|
||||||
index: function () {
|
index: function () {
|
||||||
// 基于准备好的dom,初始化echarts实例
|
var getColor = function (color) {
|
||||||
var myChart = Echarts.init(document.getElementById('echart'), 'walden');
|
if (!color || color === '—') return '#95a5a6';
|
||||||
|
if (color.indexOf('红') !== -1) return '#e74c3c';
|
||||||
// 指定图表的配置项和数据
|
if (color.indexOf('蓝') !== -1) return '#3498db';
|
||||||
var option = {
|
if (color.indexOf('绿') !== -1) return '#2ecc71';
|
||||||
title: {
|
return '#95a5a6';
|
||||||
text: '',
|
|
||||||
subtext: ''
|
|
||||||
},
|
|
||||||
color: [
|
|
||||||
"#18d1b1",
|
|
||||||
"#3fb1e3",
|
|
||||||
"#626c91",
|
|
||||||
"#a0a7e6",
|
|
||||||
"#c4ebad",
|
|
||||||
"#96dee8"
|
|
||||||
],
|
|
||||||
tooltip: {
|
|
||||||
trigger: 'axis'
|
|
||||||
},
|
|
||||||
legend: {
|
|
||||||
data: [__('Register user')]
|
|
||||||
},
|
|
||||||
toolbox: {
|
|
||||||
show: false,
|
|
||||||
feature: {
|
|
||||||
magicType: {show: true, type: ['stack', 'tiled']},
|
|
||||||
saveAsImage: {show: true}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
xAxis: {
|
|
||||||
type: 'category',
|
|
||||||
boundaryGap: false,
|
|
||||||
data: Config.column
|
|
||||||
},
|
|
||||||
yAxis: {},
|
|
||||||
grid: [{
|
|
||||||
left: 'left',
|
|
||||||
top: 'top',
|
|
||||||
right: '10',
|
|
||||||
bottom: 30
|
|
||||||
}],
|
|
||||||
series: [{
|
|
||||||
name: __('Register user'),
|
|
||||||
type: 'line',
|
|
||||||
smooth: true,
|
|
||||||
areaStyle: {
|
|
||||||
normal: {}
|
|
||||||
},
|
|
||||||
lineStyle: {
|
|
||||||
normal: {
|
|
||||||
width: 1.5
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data: Config.userdata
|
|
||||||
}]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 使用刚指定的配置项和数据显示图表。
|
var ball = function (num, color) {
|
||||||
myChart.setOption(option);
|
return '<span class="num-ball-sm" style="background-color:' + getColor(color) + ';">' + num + '</span>';
|
||||||
|
};
|
||||||
|
|
||||||
$(window).resize(function () {
|
function loadData() {
|
||||||
myChart.resize();
|
var periods = parseInt($('#dash-periods').val()) || 30;
|
||||||
|
if (periods < 10) periods = 10;
|
||||||
|
if (periods > 100) periods = 100;
|
||||||
|
$('#dash-content').html('<div class="text-center" style="padding:60px;"><i class="fa fa-spinner fa-spin fa-2x"></i><br><span class="text-muted">' + __('Loading') + '</span></div>');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'history/dashboard',
|
||||||
|
type: 'GET',
|
||||||
|
data: {periods: periods},
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (ret) {
|
||||||
|
if (ret.code != 1) {
|
||||||
|
$('#dash-content').html('<div class="alert alert-danger">' + (ret.msg || '加载失败') + '</div>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
render(ret.data);
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
$('#dash-content').html('<div class="alert alert-danger">请求失败,请重试</div>');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).on("click", ".btn-refresh", function () {
|
function render(data) {
|
||||||
setTimeout(function () {
|
var hc = data.hotcold, cw = data.colorwave, zo = data.zodiac;
|
||||||
myChart.resize();
|
var oe = data.oddeven, bs = data.bigsmall, sm = data.sum, tn = data.tailnumbers;
|
||||||
}, 0);
|
|
||||||
|
var html = '';
|
||||||
|
|
||||||
|
html += '<div class="dash-section"><h4>🔥❄️ 冷热号码</h4><div class="row">';
|
||||||
|
html += '<div class="col-sm-6"><div class="dash-card" style="border-left:3px solid #e74c3c;"><div style="color:#e74c3c;font-weight:bold;margin-bottom:8px;">热号 Top 5</div>';
|
||||||
|
for (var i = 0; i < 5; i++) html += ball(hc.hot[i].num, hc.hot[i].color) + ' ';
|
||||||
|
html += '</div></div>';
|
||||||
|
html += '<div class="col-sm-6"><div class="dash-card" style="border-left:3px solid #3498db;"><div style="color:#3498db;font-weight:bold;margin-bottom:8px;">冷号 Top 5</div>';
|
||||||
|
for (var i = 0; i < 5; i++) html += ball(hc.cold[i].num, hc.cold[i].color) + ' ';
|
||||||
|
html += '</div></div></div></div>';
|
||||||
|
|
||||||
|
html += '<div class="dash-section"><h4>📊 比例分析</h4><div class="row">';
|
||||||
|
html += '<div class="col-sm-4"><div class="dash-card"><div style="font-weight:bold;margin-bottom:8px;">🎨 波色</div>';
|
||||||
|
html += '<div style="display:flex;justify-content:space-around;">';
|
||||||
|
html += '<div><div style="font-size:24px;font-weight:bold;color:#e74c3c;">' + cw.red + '</div><div class="label-text">红波 ' + cw.red_pct + '%</div></div>';
|
||||||
|
html += '<div><div style="font-size:24px;font-weight:bold;color:#3498db;">' + cw.blue + '</div><div class="label-text">蓝波 ' + cw.blue_pct + '%</div></div>';
|
||||||
|
html += '<div><div style="font-size:24px;font-weight:bold;color:#2ecc71;">' + cw.green + '</div><div class="label-text">绿波 ' + cw.green_pct + '%</div></div>';
|
||||||
|
html += '</div></div></div>';
|
||||||
|
html += '<div class="col-sm-4"><div class="dash-card"><div style="font-weight:bold;margin-bottom:8px;">⚖️ 奇偶</div>';
|
||||||
|
html += '<div style="display:flex;justify-content:space-around;">';
|
||||||
|
html += '<div><div style="font-size:24px;font-weight:bold;color:#e74c3c;">' + oe.odd + '</div><div class="label-text">奇数 ' + oe.odd_pct + '%</div></div>';
|
||||||
|
html += '<div><div style="font-size:24px;font-weight:bold;color:#3498db;">' + oe.even + '</div><div class="label-text">偶数 ' + oe.even_pct + '%</div></div>';
|
||||||
|
html += '</div></div></div>';
|
||||||
|
html += '<div class="col-sm-4"><div class="dash-card"><div style="font-weight:bold;margin-bottom:8px;">📏 大小</div>';
|
||||||
|
html += '<div style="display:flex;justify-content:space-around;">';
|
||||||
|
html += '<div><div style="font-size:24px;font-weight:bold;color:#f39c12;">' + bs.big + '</div><div class="label-text">大数 ' + bs.big_pct + '%</div></div>';
|
||||||
|
html += '<div><div style="font-size:24px;font-weight:bold;color:#2ecc71;">' + bs.small + '</div><div class="label-text">小数 ' + bs.small_pct + '%</div></div>';
|
||||||
|
html += '</div></div></div>';
|
||||||
|
html += '</div></div>';
|
||||||
|
|
||||||
|
html += '<div class="dash-section"><h4>⭐ 生肖排名</h4><div style="display:flex;flex-wrap:wrap;">';
|
||||||
|
for (var i = 0; i < Math.min(zo.list.length, 12); i++) {
|
||||||
|
var z = zo.list[i];
|
||||||
|
html += '<div class="mini-card"><div class="name">' + z.animal + '</div><div class="val">' + z.count + ' (' + z.percent + '%)</div></div>';
|
||||||
|
}
|
||||||
|
html += '</div></div>';
|
||||||
|
|
||||||
|
html += '<div class="dash-section"><h4>📈 和值统计</h4><div class="row">';
|
||||||
|
html += '<div class="col-sm-4"><div class="dash-card"><div class="big-num">' + sm.avg + '</div><div class="label-text">平均和值</div></div></div>';
|
||||||
|
html += '<div class="col-sm-4"><div class="dash-card"><div class="big-num" style="color:#e74c3c;">' + sm.max + '</div><div class="label-text">最大和值</div></div></div>';
|
||||||
|
html += '<div class="col-sm-4"><div class="dash-card"><div class="big-num" style="color:#3498db;">' + sm.min + '</div><div class="label-text">最小和值</div></div></div>';
|
||||||
|
html += '</div><div id="dash-chart" style="margin-top:15px;"></div></div>';
|
||||||
|
|
||||||
|
html += '<div class="dash-section"><h4>🔢 尾数频率</h4><div style="display:flex;flex-wrap:wrap;">';
|
||||||
|
for (var i = 0; i < tn.all.length; i++) {
|
||||||
|
var t = tn.all[i];
|
||||||
|
html += '<div class="mini-card"><div class="name">' + t.tail + '</div><div class="val">' + t.count + ' (' + t.percent + '%)</div></div>';
|
||||||
|
}
|
||||||
|
html += '</div></div>';
|
||||||
|
|
||||||
|
$('#dash-content').html(html);
|
||||||
|
|
||||||
|
if (typeof echarts !== 'undefined' && sm.expects && sm.expects.length > 0) {
|
||||||
|
var chartDom = document.getElementById('dash-chart');
|
||||||
|
if (chartDom) {
|
||||||
|
var chart = echarts.init(chartDom);
|
||||||
|
chart.setOption({
|
||||||
|
tooltip: {trigger: 'axis'},
|
||||||
|
xAxis: {type: 'category', data: sm.expects, axisLabel: {rotate: 45, fontSize: 10}},
|
||||||
|
yAxis: {type: 'value'},
|
||||||
|
series: [{type: 'line', data: sm.sums, smooth: true, itemStyle: {color: '#3498db'}, areaStyle: {color: 'rgba(52,152,219,0.1)'}}],
|
||||||
|
grid: {left: 50, right: 20, bottom: 50, top: 20}
|
||||||
});
|
});
|
||||||
|
$(window).on('resize', function () { chart.resize(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#btn-dash-refresh').on('click', loadData);
|
||||||
|
loadData();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user