123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691 |
- function formatNumber(n) {
- const str = n.toString();
- return str[1] ? str : `0${str}`;
- }
- 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 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 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) {
- const that = this;
- var option = {
- color: ["#FFB400", "#D4327A"],
- legend: {
- data: ["Att(专注度)", "Med(放松度)"],
- 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,
- },
- ],
- animation: false,
- };
- return option;
- }
- // 基本脑波图
- function getBaseOption(delta, theta, alpha, beta) {
- const that = this;
- var option = {
- color: ["#4b8cb4", "#ed4b59", "#fdb64b", "#F6CB90"],
- legend: {
- data: ["Delta", "Theta", "Alpha", "Beta"],
- 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: "Alpha",
- symbol: "none", //取消折点圆圈
- type: "line",
- smooth: true,
- data: alpha,
- },
- {
- name: "Beta",
- symbol: "none", //取消折点圆圈
- type: "line",
- smooth: true,
- data: beta,
- },
- ],
- 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: [{
- name: "访问来源",
- type: "pie",
- radius: "80%",
- labelLine: {
- show: false,
- },
- data: [
- // {value: $params, name: '高专注占比'},
- // {value: Math.abs(100-$params), name: '直接访问'},
- {
- value: $params,
- name: ''
- },
- {
- value: Math.abs($total - $params),
- name: ''
- },
- ]
- }]
- };
- return $option;
- }
- // 雷达图
- export function getRadarChartOption($params) {
- let $option = {
- tooltip: {
- },
- color: "#ffb72d",
- radar: {
- radius: "55%",
- name: {
- textStyle: {
- color: "#fff",
- backgroundColor: "#999",
- borderRadius: 3,
- padding: [3, 5],
- },
- },
- indicator: [{
- name: "专注力平均值指数",
- max: 100
- },
- {
- name: "专注力广度指数",
- max: 100
- },
- {
- name: "专注力爆发指数",
- max: 100
- },
- {
- name: "专注力抗性指数",
- max: 100
- },
- {
- name: "专注力启动指数",
- max: 100
- },
- {
- name: "高专注力占比指数",
- max: 100
- },
- ],
- splitArea: {
- show: true,
- areaStyle: {
- color: ['#423b97', '#5b55a6', '#7570b4', '#a6a3ce', '#dddcec'],
- // 图表背景网格的颜色
- }
- },
- },
- series: [{
- name: "预算 vs 开销(Budget vs spending)",
- type: "radar",
- lineStyle: {
- // color: "#D28885",
- color: "#ffda93",
- },
- data: [{
- value: $params,
- // name: '实际开销(Actual Spending)'
- name: "专注力要素分析数据",
- }, ],
- }, ],
- };
- return $option;
- }
- //获取饼状图图属性
- export function getPieChartsOption($pie_datas) {
- if ($pie_datas) {
- console.log($pie_datas);
- let option = {
- tooltip: {
- trigger: "item",
- formatter: "{a} \r\n {b}: {c} ({d}%)",
- },
- legend: {
- orient: "vertical",
- right: "10%",
- top: "20%",
- data: $pie_datas["legends"],
- },
- series: [{
- name: "访问来源",
- type: "pie",
- radius: ["40%", "70%"],
- avoidLabelOverlap: false,
- label: {
- show: false,
- position: "center",
- },
- right: "40%",
- emphasis: {
- label: {
- show: true,
- fontSize: "30",
- fontWeight: "bold",
- },
- },
- labelLine: {
- show: true,
- },
- data: $pie_datas["datas"],
- }, ],
- };
- return option;
- }
- }
- //过滤饼状数据
- export function filterPieData(datas) {
- let $this = this;
- let legends = [];
- let $att_region = [{
- min: 0,
- max: 20,
- },
- {
- min: 21,
- max: 40,
- },
- {
- min: 41,
- max: 60,
- },
- {
- min: 61,
- max: 80,
- },
- {
- min: 81,
- max: 100,
- },
- ];
- datas.forEach(($val, $index) => {
- legends.push(
- $att_region[$index]["min"] +
- "-" +
- $att_region[$index]["max"] +
- ":" +
- formatSeconds($val)
- );
- let _data = {
- name: $att_region[$index]["min"] +
- "-" +
- $att_region[$index]["max"] +
- ":" +
- formatSeconds($val),
- value: $val,
- };
- datas[$index] = _data;
- });
- return {
- datas,
- legends
- };
- }
- // 受干扰次数 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() + " ";
- var h = date.getHours() + ":";
- var m = date.getMinutes() + ":";
- var s = 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,
- getBaseOption,
- get_level_name,
- timestampToTimeS,
- interfereAction
- };
|