Files

268 lines
7.4 KiB
JavaScript
Raw Permalink Normal View History

2025-11-26 11:18:26 +08:00
/*
* Author: Abdullah A Almsaeed
* Date: 2014-01-04
* Description:
* 该文件仅用于主仪表盘的演示 index.html
**/
/* global moment:false, Chart:false, Sparkline:false */
$(function () {
'use strict'
// 使用 jQuery UI 使仪表盘小部件可排序
$('.connectedSortable').sortable({
placeholder: 'sort-highlight',
connectWith: '.connectedSortable',
handle: '.card-header, .nav-tabs',
forcePlaceholderSize: true,
zIndex: 999999
})
$('.connectedSortable .card-header').css('cursor', 'move')
// jQuery UI 可排序待办事项列表
$('.todo-list').sortable({
placeholder: 'sort-highlight',
handle: '.handle',
forcePlaceholderSize: true,
zIndex: 999999
})
// bootstrap WYSIHTML5 - 文本编辑器
$('.textarea').summernote()
$('.daterange').daterangepicker({locale:{applyLabel: '确定',cancelLabel: '取消',customRangeLabel: '自定义范围',},locale:{applyLabel: '确定',cancelLabel: '取消',customRangeLabel: '自定义范围',},
ranges: {
'今天': [moment(), moment()],
'昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'最近7天': [moment().subtract(6, 'days'), moment()],
'最近30天': [moment().subtract(29, 'days'), moment()],
'本月': [moment().startOf('month'), moment().endOf('month')],
'上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
startDate: moment().subtract(29, 'days'),
endDate: moment()
}, function (start, end) {
// eslint-disable-next-line no-alert
alert('你选择了: ' + start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
})
/* jQueryKnob */
$('.knob').knob()
// jvectormap 数据
var visitorsData = {
US: 398, // 美国
SA: 400, // 沙特阿拉伯
CA: 1000, // 加拿大
DE: 500, // 德国
FR: 760, // 法国
CN: 300, // 中国
AU: 700, // 澳大利亚
BR: 600, // 巴西
IN: 800, // 印度
GB: 320, // 大不列颠
RU: 3000 // 俄罗斯
}
// jvectormap 世界地图
$('#world-map').vectorMap({
map: 'usa_en',
backgroundColor: 'transparent',
regionStyle: {
initial: {
fill: 'rgba(255, 255, 255, 0.7)',
'fill-opacity': 1,
stroke: 'rgba(0,0,0,.2)',
'stroke-width': 1,
'stroke-opacity': 1
}
},
series: {
regions: [{
values: visitorsData,
scale: ['#ffffff', '#0154ad'],
normalizeFunction: 'polynomial'
}]
},
onRegionLabelShow: function (e, el, code) {
if (typeof visitorsData[code] !== 'undefined') {
el.html(el.html() + ': ' + visitorsData[code] + ' 新访客')
}
}
})
// Sparkline 图表
var sparkline1 = new Sparkline($('#sparkline-1')[0], { width: 80, height: 50, lineColor: '#92c1dc', endColor: '#ebf4f9' })
var sparkline2 = new Sparkline($('#sparkline-2')[0], { width: 80, height: 50, lineColor: '#92c1dc', endColor: '#ebf4f9' })
var sparkline3 = new Sparkline($('#sparkline-3')[0], { width: 80, height: 50, lineColor: '#92c1dc', endColor: '#ebf4f9' })
sparkline1.draw([1000, 1200, 920, 927, 931, 1027, 819, 930, 1021])
sparkline2.draw([515, 519, 520, 522, 652, 810, 370, 627, 319, 630, 921])
sparkline3.draw([15, 19, 20, 22, 33, 27, 31, 27, 19, 30, 21])
// 日历
$('#calendar').datetimepicker({
format: 'L',
inline: true
})
// SLIMSCROLL 聊天小工具
$('#chat-box').overlayScrollbars({
height: '250px'
})
/* Chart.js Charts */
// 销售图表
var salesChartCanvas = document.getElementById('revenue-chart-canvas').getContext('2d')
// $('#revenue-chart').get(0).getContext('2d');
var salesChartData = {
labels: ['一月', '二月', '三月', '四月', '五月', '六月', '七月'],
datasets: [
{
label: '数字商品',
backgroundColor: 'rgba(60,141,188,0.9)',
borderColor: 'rgba(60,141,188,0.8)',
pointRadius: false,
pointColor: '#3b8bba',
pointStrokeColor: 'rgba(60,141,188,1)',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(60,141,188,1)',
data: [28, 48, 40, 19, 86, 27, 90]
},
{
label: '电子产品',
backgroundColor: 'rgba(210, 214, 222, 1)',
borderColor: 'rgba(210, 214, 222, 1)',
pointRadius: false,
pointColor: 'rgba(210, 214, 222, 1)',
pointStrokeColor: '#c1c7d1',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(220,220,220,1)',
data: [65, 59, 80, 81, 56, 55, 40]
}
]
}
var salesChartOptions = {
maintainAspectRatio: false,
responsive: true,
legend: {
display: false
},
scales: {
xAxes: [{
gridLines: {
display: false
}
}],
yAxes: [{
gridLines: {
display: false
}
}]
}
}
// 这将获取 jQuery 中的第一个返回的节点。
// eslint-disable-next-line no-unused-vars
var salesChart = new Chart(salesChartCanvas, { // lgtm[js/unused-local-variable]
type: 'line',
data: salesChartData,
options: salesChartOptions
})
// 环形图
var pieChartCanvas = $('#sales-chart-canvas').get(0).getContext('2d')
var pieData = {
labels: [
'店内销售',
'下载销售',
'邮购销售'
],
datasets: [
{
data: [30, 12, 20],
backgroundColor: ['#f56954', '#00a65a', '#f39c12']
}
]
}
var pieOptions = {
legend: {
display: false
},
maintainAspectRatio: false,
responsive: true
}
// 创建饼形图或环形图
// 你可以使用以下方法在此之间进行切换。
// eslint-disable-next-line no-unused-vars
var pieChart = new Chart(pieChartCanvas, { // lgtm[js/unused-local-variable]
type: 'doughnut',
data: pieData,
options: pieOptions
})
// 销售图表
var salesGraphChartCanvas = $('#line-chart').get(0).getContext('2d')
// $('#revenue-chart').get(0).getContext('2d');
var salesGraphChartData = {
labels: ['2011 一季度', '2011 二季度', '2011 三季度', '2011 四季度', '2012 一季度', '2012 二季度', '2012 三季度', '2012 四季度', '2013 一季度', '2013 二季度'],
datasets: [
{
label: '数字商品',
fill: false,
borderWidth: 2,
lineTension: 0,
spanGaps: true,
borderColor: '#efefef',
pointRadius: 3,
pointHoverRadius: 7,
pointColor: '#efefef',
pointBackgroundColor: '#efefef',
data: [2666, 2778, 4912, 3767, 6810, 5670, 4820, 15073, 10687, 8432]
}
]
}
var salesGraphChartOptions = {
maintainAspectRatio: false,
responsive: true,
legend: {
display: false
},
scales: {
xAxes: [{
ticks: {
fontColor: '#efefef'
},
gridLines: {
display: false,
color: '#efefef',
drawBorder: false
}
}],
yAxes: [{
ticks: {
stepSize: 5000,
fontColor: '#efefef'
},
gridLines: {
display: true,
color: '#efefef',
drawBorder: false
}
}]
}
}
// 这将获取 jQuery 中的第一个返回的节点。
// eslint-disable-next-line no-unused-vars
var salesGraphChart = new Chart(salesGraphChartCanvas, { // lgtm[js/unused-local-variable]
type: 'line',
data: salesGraphChartData,
options: salesGraphChartOptions
})
})