diff --git a/application/admin/view/dashboard/index.html b/application/admin/view/dashboard/index.html index 215e172..977aa53 100644 --- a/application/admin/view/dashboard/index.html +++ b/application/admin/view/dashboard/index.html @@ -30,126 +30,3 @@ - diff --git a/public/assets/js/backend/dashboard.js b/public/assets/js/backend/dashboard.js index ab8409c..75d468e 100644 --- a/public/assets/js/backend/dashboard.js +++ b/public/assets/js/backend/dashboard.js @@ -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 = { index: function () { - // 基于准备好的dom,初始化echarts实例 - var myChart = Echarts.init(document.getElementById('echart'), 'walden'); - - // 指定图表的配置项和数据 - var option = { - title: { - 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 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'; }; - // 使用刚指定的配置项和数据显示图表。 - myChart.setOption(option); + var ball = function (num, color) { + return '' + num + ''; + }; - $(window).resize(function () { - myChart.resize(); - }); + function loadData() { + var periods = parseInt($('#dash-periods').val()) || 30; + if (periods < 10) periods = 10; + if (periods > 100) periods = 100; + $('#dash-content').html('

' + __('Loading') + '
'); - $(document).on("click", ".btn-refresh", function () { - setTimeout(function () { - myChart.resize(); - }, 0); - }); + $.ajax({ + url: 'history/dashboard', + type: 'GET', + data: {periods: periods}, + dataType: 'json', + success: function (ret) { + if (ret.code != 1) { + $('#dash-content').html('
' + (ret.msg || '加载失败') + '
'); + return; + } + render(ret.data); + }, + error: function () { + $('#dash-content').html('
请求失败,请重试
'); + } + }); + } + 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 += '

🔥❄️ 冷热号码

'; + html += '
热号 Top 5
'; + for (var i = 0; i < 5; i++) html += ball(hc.hot[i].num, hc.hot[i].color) + ' '; + html += '
'; + html += '
冷号 Top 5
'; + for (var i = 0; i < 5; i++) html += ball(hc.cold[i].num, hc.cold[i].color) + ' '; + html += '
'; + + html += '

📊 比例分析

'; + html += '
🎨 波色
'; + html += '
'; + html += '
' + cw.red + '
红波 ' + cw.red_pct + '%
'; + html += '
' + cw.blue + '
蓝波 ' + cw.blue_pct + '%
'; + html += '
' + cw.green + '
绿波 ' + cw.green_pct + '%
'; + html += '
'; + html += '
⚖️ 奇偶
'; + html += '
'; + html += '
' + oe.odd + '
奇数 ' + oe.odd_pct + '%
'; + html += '
' + oe.even + '
偶数 ' + oe.even_pct + '%
'; + html += '
'; + html += '
📏 大小
'; + html += '
'; + html += '
' + bs.big + '
大数 ' + bs.big_pct + '%
'; + html += '
' + bs.small + '
小数 ' + bs.small_pct + '%
'; + html += '
'; + html += '
'; + + html += '

⭐ 生肖排名

'; + for (var i = 0; i < Math.min(zo.list.length, 12); i++) { + var z = zo.list[i]; + html += '
' + z.animal + '
' + z.count + ' (' + z.percent + '%)
'; + } + html += '
'; + + html += '

📈 和值统计

'; + html += '
' + sm.avg + '
平均和值
'; + html += '
' + sm.max + '
最大和值
'; + html += '
' + sm.min + '
最小和值
'; + html += '
'; + + html += '

🔢 尾数频率

'; + for (var i = 0; i < tn.all.length; i++) { + var t = tn.all[i]; + html += '
' + t.tail + '
' + t.count + ' (' + t.percent + '%)
'; + } + html += '
'; + + $('#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(); } };