function formatNumber(n) { const str = n.toString(); return str[1] ? str : `0${str}`; } export function getNowDate() { var date = new Date(); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); return `${year}${month}${day}`; } export function formatTime(date) { if (date.length <= 11) { date = date * 1000; } var date = new Date(date); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); return year + "/" + month + "/" + day; } export function formatTimeAnother(date) { var date = new Date(date * 1000); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); return year + "-" + month + "-" + day; } export function formatAllTime(date) { if (date.length <= 11) { date = date * 1000; } var date = new Date(date); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); const minutes = date.getMinutes(); return year + "/" + month + "/" + day + " " + hour + ":" + minutes; } export function formatTimeForSeconds(date) { if (date.length <= 11) { date = date * 1000; } var date = new Date(date); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); const minute = date.getMinutes(); return year + "/" + month + "/" + day + " " + hour + ":" + minute; } export function timestampTwoNum(timestamp) { var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 var Y = date.getFullYear() + "."; var M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "."; // (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()) var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()); // var h = date.getHours() + ":"; // var m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) ; // var s = (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()); return (Y + M + D); } export function formatValidityTime(date) { if (date.toString().length <= 11) { date = date * 1000; } var date = new Date(date); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); return year + "/" + month + "/" + day + " " + hour + "时"; } export function formatBirthday(date) { var date = new Date(date * 1000); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); const t1 = [year, month, day].map(formatNumber).join("-"); return `${t1}`; } // 专注力与放松力图表 小乌龟 function getLineOption(lineData_att, lineData_med, lineData_amp) { const that = this; var option = { color: ["#FFB400", "#40FF31", "#D4327A"], legend: { data: ["Att(专注度)", "Med(放松度)", "Amp(和谐度)"], top: -5, left: 210, // left: 'center', orient: "horizontal", icon: "circle", itemWidth: 8, itemGap: 5, // 解决部分安卓手机图例字体显示太小的问题 textStyle: { // fontWeight: 'bold', fontSize: 10, color: "#CFCFCF", }, selectedMode: false, show: false, }, grid: { left: 20, right: 20, bottom: 16, top: 16, // show:true, containLabel: true, zlevel: 1, }, tooltip: { show: true, trigger: "axis", }, yAxis: { x: "center", type: "value", splitLine: { lineStyle: { type: "dashed", }, }, axisLine: { lineStyle: { color: "#ccc", }, show: false, }, axisLabel: { color: "#ccc", }, max: 100, // data: ["0", "20", "40", "60", "80", "100"] // show: false }, xAxis: { type: "category", boundaryGap: false, splitLine: { lineStyle: { type: "dashed", }, }, axisLine: { lineStyle: { color: "#ccc", }, }, axisLabel: { color: "#ccc", }, show: false, }, series: [{ name: "Att(专注度)", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: lineData_att, }, { name: "Med(放松度)", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: lineData_med, }, { name: "Amp(和谐度)", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: lineData_amp, }, ], animation: false, }; return option; } // alpha beta function getABOption(lineData_alphaL, lineData_alphaH, lineData_betaL, lineData_betaH) { const that = this; var option = { color: ["#38FF49", "#00AD0E", "#0060F1", "#00CCFF"], legend: { data: ["alphaL", "alphaH", "betaL", "betaH"], top: -5, left: 210, // left: 'center', orient: "horizontal", icon: "circle", itemWidth: 8, itemGap: 5, // 解决部分安卓手机图例字体显示太小的问题 textStyle: { // fontWeight: 'bold', fontSize: 10, color: "#CFCFCF", }, selectedMode: false, show: false, }, grid: { left: 20, right: 20, bottom: 16, top: 16, // show:true, containLabel: true, zlevel: 1, }, tooltip: { show: true, trigger: "axis", }, yAxis: { x: "center", type: "value", splitLine: { lineStyle: { type: "dashed", }, }, axisLine: { lineStyle: { color: "#ccc", }, show: false, }, axisLabel: { color: "#ccc", }, // max: 100, // data: ["0", "20", "40", "60", "80", "100"] // show: false }, xAxis: { type: "category", boundaryGap: false, splitLine: { lineStyle: { type: "dashed", }, }, axisLine: { lineStyle: { color: "#ccc", }, }, axisLabel: { color: "#ccc", }, show: false, }, series: [{ name: "alphaL", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: lineData_alphaL, }, { name: "alphaH", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: lineData_alphaH, }, { name: "betaL", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: lineData_betaL, }, { name: "betaH", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: lineData_betaH, }, ], animation: false, }; return option; } // delta theta function getDTOption(delta, theta) { const that = this; var option = { color: ["#FF77B3", "#FFE838"], legend: { data: ["Delta", "Theta"], top: -5, left: 210, // left: 'center', orient: "horizontal", icon: "circle", itemWidth: 8, itemGap: 5, // 解决部分安卓手机图例字体显示太小的问题 textStyle: { // fontWeight: 'bold', fontSize: 10, color: "#CFCFCF", }, selectedMode: false, show: false, }, grid: { left: 20, right: 20, bottom: 16, top: 16, // show:true, containLabel: true, zlevel: 1, }, tooltip: { show: true, trigger: "axis", }, yAxis: { x: "center", type: "value", splitLine: { lineStyle: { type: "dashed", }, }, axisLine: { lineStyle: { color: "#ccc", }, show: false, }, axisLabel: { color: "#ccc", }, // max: 100, // data: ["0", "20", "40", "60", "80", "100"] // show: false }, xAxis: { type: "category", boundaryGap: false, splitLine: { lineStyle: { type: "dashed", }, }, axisLine: { lineStyle: { color: "#ccc", }, }, axisLabel: { color: "#ccc", }, show: false, }, series: [ { name: "Delta", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: delta, }, { name: "Theta", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: theta, }, ], animation: false, }; return option; } // 基本脑波图 function getBaseOption(delta, theta, low_beta, high_beta, low_alpha, high_alpha) { const that = this; var option = { color: ["#FF77B3", "#FFE838", "#0060F1", "#00CCFF", "#38FF49", "#00AD0E"], legend: { data: ["Delta", "Theta", "Low_Beta", "High_Beta","Low_Alpha", "High_Alpha",], left: "center", bottom: 20, icon: "circle", itemWidth: 8, itemGap: 25, // 解决部分安卓手机图例字体显示太小的问题 textStyle: { // fontWeight: 'bold', fontSize: 10, color: "#CFCFCF", }, show: false, }, grid: { left: 20, right: 20, bottom: 16, top: 16, // show:false, containLabel: true, }, tooltip: { show: true, trigger: "axis", }, yAxis: { x: "center", type: "value", splitLine: { lineStyle: { type: "dashed", }, }, axisLine: { lineStyle: { color: "#ccc", }, show: false, }, axisLabel: { color: "#ccc", }, // max: 100, // data: ["0", "20", "40", "60", "80", "100"] // show: false }, xAxis: { type: "category", boundaryGap: false, splitLine: { lineStyle: { type: "dashed", }, }, axisLine: { lineStyle: { color: "#ccc", }, }, axisLabel: { color: "#ccc", }, show: false, }, series: [{ name: "Delta", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: delta, }, { name: "Theta", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: theta, }, { name: "Low_Beta", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: low_beta, }, { name: "High_Beta", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: high_beta, }, { name: "Low_Alpha", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: low_alpha, }, { name: "High_Alpha", symbol: "none", //取消折点圆圈 type: "line", smooth: true, data: high_alpha, }, ], animation: false, }; return option; } export function formatSeconds(value) { var secondTime = parseInt(value); // 秒 var minuteTime = 0; // 分 var hourTime = 0; // 小时 if (secondTime > 60) { //如果秒数大于60,将秒数转换成整数 //获取分钟,除以60取整数,得到整数分钟 minuteTime = parseInt(secondTime / 60); //获取秒数,秒数取佘,得到整数秒数 secondTime = parseInt(secondTime % 60); //如果分钟大于60,将分钟转换成小时 if (minuteTime > 60) { //获取小时,获取分钟除以60,得到整数小时 hourTime = parseInt(minuteTime / 60); //获取小时后取佘的分,获取分钟除以60取佘的分 minuteTime = parseInt(minuteTime % 60); } } var result = "" + parseInt(secondTime) + "秒"; if (minuteTime > 0) { result = "" + parseInt(minuteTime) + "分" + result; } if (hourTime > 0) { result = "" + parseInt(hourTime) + "小时" + result; } return result; } //获取等级名称 // function get_level_name($level_id) { // let $level = [ // "普通用户", // "体验会员", // "黄金会员", // "白金会员", // "钻石会员", // "创客代理", // "区域代理", // "合伙人", // "店员", // "店长", // "老师", // ]; // return $level[$level_id]; // } export function cal_down_time($final_time) { let $today = new Date().getTime(); let $differ = $final_time * 1000 - $today; //计算出相差天数 var days = Math.floor($differ / (24 * 3600 * 1000)); //计算出小时数 var leave1 = $differ % (24 * 3600 * 1000); //计算天数后剩余的毫秒数 var hours = Math.floor(leave1 / (3600 * 1000)); //计算相差分钟数 var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数 var minutes = Math.floor(leave2 / (60 * 1000)); //计算相差秒数 var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数 var seconds = Math.round(leave3 / 1000); return { differ: $differ, days, hours, minutes, seconds, }; } export function getHightPieChartOption($params, $total) { let $option = { tooltip: { // trigger: 'item' show: false, }, series: [{ silent: true, name: "访问来源", type: "pie", radius: ["58%", "85%"], labelLine: { show: false, }, data: [ // {value: $params, name: '高专注占比'}, // {value: Math.abs(100-$params), name: '直接访问'}, { value: $params, name: '', itemStyle: { normal: { color: "#FFB72D", }, }, }, { value: Math.abs($total - $params), name: '', itemStyle: { normal: { color: "#E6E6E6", }, }, }, ] }] }; return $option; } // 雷达图 export function getRadarChartOption($params) { var i = -1; let $option = { tooltip: {}, color: "#ffb72d", radar: { radius: "65%", indicator: [{ name: "专注力平均值", max: 100 }, { name: "高专注指数", max: 100 }, { name: "专注唤醒效率", max: 100 }, { name: "整体和谐度", max: 100 }, { name: "专注力稳定度", max: 100 }, ], // 点击事件 triggerEvent: true, splitArea: { show: true, areaStyle: { color: ["#FFFFFF", "#E6E6E6", "#FFFFFF", "#E6E6E6", "#FFFFFF"], // 图表背景网格的颜色 } }, axisLine: { lineStyle: { color: "#E6E6E6", }, }, name: { rich: { a: { color: '#333333', fontSize: 10, fontWeight: "400", fontFamily: "Microsoft YaHei", }, b: { color: '#333333', align: 'center', padding: 5, fontSize: 10, } }, formatter: (a, b) => { i++; return `{a|${a}}\n{b|${$params[i]}}` } } }, series: [{ silent: true, name: "预算 vs 开销(Budget vs spending)", type: "radar", color: "#5470c6", symbolSize: 3, data: [{ value: $params, // name: '实际开销(Actual Spending)' name: "专注力要素分析数据", // areaStyle: { // color: "#FFB72D", // }, },], },], }; return $option; } //获取饼状图图属性 export function getPieChartsOption($pie_datas) { let option = { series: [{ silent: true, name: "访问来源", type: "pie", radius: ["45%", "70%"], avoidLabelOverlap: false, label: { show: false, position: "center", }, // right: "40%", emphasis: { label: { show: true, fontSize: "30", fontWeight: "bold", }, }, labelLine: { show: false, }, data: $pie_datas, },], }; return option; } // 受干扰次数 getInterfereChartsOption 小乌龟 export function getInterfereChartsOption(interfere_datas) { // console.log('干扰初始化', interfere_datas) if (interfere_datas) { let option = { color: '#23CC92', // 标题 title: { // left: 1220, }, // 提示 tooltip: { trigger: "axis", axisPointer: { type: "shadow", }, }, grid: { top: 20, bottom: 20 }, // x轴数据显示 xAxis: { type: 'category', boundaryGap: false, // data: ['0', '2', '4', '6', '8', '10', '12', '14', '16', '18', '20'], splitNumber: 11, }, // y轴坐标显示 yAxis: { color: '#23CC92', type: "value", splitNumber: 5, min: -100, max: 0, axisLabel: { formatter: '{value}', textStyle: { color: '#23CC92' } } }, //数据配置项 series: [{ data: interfere_datas, type: "line", large: true, areaStyle: {} },], } return option } } // 能力调整 getAdjustmentChartsOption export function getAdjustmentChartsOption(interfere_datas) { // console.log('调整初始化', interfere_datas) if (interfere_datas) { let option = { color: '#F3A100', // 标题 title: { // left: 1220, }, grid: { top: 20, bottom: 20 }, // 提示 tooltip: { trigger: "axis", axisPointer: { type: "shadow", }, }, // x轴数据显示 xAxis: { type: 'category', boundaryGap: false, }, // y轴坐标显示 yAxis: { // x: "center", type: "value", splitNumber: 5, min: 0, max: 100, axisLabel: { formatter: '{value}', textStyle: { color: '#F3A100' } } }, //数据配置项 series: [{ data: interfere_datas, type: "line", large: true, areaStyle: {} },], } return option } } // 时间戳转化成时间格式 export function timestampToTimeS(timestamp) { var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 var Y = date.getFullYear() + "-"; var M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-"; var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " "; var h = date.getHours() + ":"; var m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":"; var s = (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()); return Y + M + D + h + m + s; } // 成绩记录干扰图表数据处理 export function interfereAction($data) { if ($data) { let $interfereArr = [] let $objData = {}; // 自定义的对象 1200s 20分钟 for (var i = 0; i < 1200; i++) { $objData[i] = 0; } var $newObj = Object.assign($objData, $data); // 对象转数组 for (const key in $newObj) { $interfereArr.push($newObj[key]); } return $interfereArr } else { console.log("无数据", $data) } } export default { formatNumber, formatTime, getLineOption, getABOption, getDTOption, getBaseOption, // get_level_name, timestampToTimeS, interfereAction };