Commit 0bb49d32 authored by liujiangnan's avatar liujiangnan

feat: 修改曲线

parent c424f54e
...@@ -2,7 +2,8 @@ import { ...@@ -2,7 +2,8 @@ import {
asyncDelay, asyncDelay,
onHomeworkFinish, onHomeworkFinish,
asyncCallNetworkApiGet, asyncCallNetworkApiGet,
asyncCallNetworkApiPost } from "../script/util"; asyncCallNetworkApiPost
} from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -45,7 +46,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -45,7 +46,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.token = cc.sys.localStorage.getItem("token"); this.token = cc.sys.localStorage.getItem("token");
} }
getFomartDate () { getFomartDate() {
const date = new Date(); const date = new Date();
date.setDate(date.getDate() - date.getDay() + 1); date.setDate(date.getDate() - date.getDay() + 1);
const monday = date["pattern"]("MM.dd"); const monday = date["pattern"]("MM.dd");
...@@ -56,10 +57,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -56,10 +57,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
userInfo = null; userInfo = null;
async initUserInfo() { async initUserInfo() {
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/info", {token: this.token}); const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/info", { token: this.token });
const userInfo = JSON.parse(res).data; const userInfo = JSON.parse(res).data;
this.userInfo = userInfo; this.userInfo = userInfo;
const avatarIndex = userInfo.avatar_url ? parseInt(userInfo.avatar_url)-1 : 0; const avatarIndex = userInfo.avatar_url ? parseInt(userInfo.avatar_url) - 1 : 0;
const usercenter = cc.find("Canvas/usercenter/view/content/scollpage/user_center"); const usercenter = cc.find("Canvas/usercenter/view/content/scollpage/user_center");
// 头像 // 头像
cc.find("avatar", usercenter).getComponent(cc.Sprite).spriteFrame = this.picture[avatarIndex]; cc.find("avatar", usercenter).getComponent(cc.Sprite).spriteFrame = this.picture[avatarIndex];
...@@ -77,7 +78,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -77,7 +78,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (!this.userInfo) { if (!this.userInfo) {
return; return;
} }
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/part/count", {kidid: this.userInfo.id,token: this.token}); const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/part/count", { kidid: this.userInfo.id, token: this.token });
const partInfo = JSON.parse(res).data; const partInfo = JSON.parse(res).data;
if (partInfo) { if (partInfo) {
this.partWeekCount = partInfo.weekcount; this.partWeekCount = partInfo.weekcount;
...@@ -87,7 +88,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -87,7 +88,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.find("learndesc", usercenter).getComponent(cc.RichText).string = `<color=#ae441c>本周已经学习</c> <color=#41916e><size=60>${this.partWeekCount}</size></color> <color=#ae441c>个小节</color>`; cc.find("learndesc", usercenter).getComponent(cc.RichText).string = `<color=#ae441c>本周已经学习</c> <color=#41916e><size=60>${this.partWeekCount}</size></color> <color=#ae441c>个小节</color>`;
const smallbg_1_left = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_1_left"); const smallbg_1_left = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_1_left");
cc.find("smtextbg/partcount", smallbg_1_left).getComponent(cc.Label).string = this.partCount+""; cc.find("smtextbg/partcount", smallbg_1_left).getComponent(cc.Label).string = this.partCount + "";
cc.find("numberbg/weekpartcount", smallbg_1_left).getComponent(cc.Label).string = "+" + this.partWeekCount; cc.find("numberbg/weekpartcount", smallbg_1_left).getComponent(cc.Label).string = "+" + this.partWeekCount;
} }
...@@ -99,7 +100,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -99,7 +100,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (!this.userInfo) { if (!this.userInfo) {
return; return;
} }
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/record/count", {kidid: this.userInfo.id,token: this.token}); const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/record/count", { kidid: this.userInfo.id, token: this.token });
const speakInfo = JSON.parse(res).data; const speakInfo = JSON.parse(res).data;
if (speakInfo) { if (speakInfo) {
this.speakWeekCount = speakInfo.weekcount; this.speakWeekCount = speakInfo.weekcount;
...@@ -107,7 +108,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -107,7 +108,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
const smallbg_1_right = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_1_right"); const smallbg_1_right = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_1_right");
cc.find("smtextbg/partcount", smallbg_1_right).getComponent(cc.Label).string = this.speakCount+""; cc.find("smtextbg/partcount", smallbg_1_right).getComponent(cc.Label).string = this.speakCount + "";
cc.find("numberbg/weekpartcount", smallbg_1_right).getComponent(cc.Label).string = "+" + this.speakWeekCount; cc.find("numberbg/weekpartcount", smallbg_1_right).getComponent(cc.Label).string = "+" + this.speakWeekCount;
} }
...@@ -118,7 +119,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -118,7 +119,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (!this.userInfo) { if (!this.userInfo) {
return; return;
} }
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/knowledge/count", {kidid: this.userInfo.id,token: this.token}); const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/knowledge/count", { kidid: this.userInfo.id, token: this.token });
const knowledgeInfo = JSON.parse(res).data; const knowledgeInfo = JSON.parse(res).data;
if (knowledgeInfo) { if (knowledgeInfo) {
this.lettercount = knowledgeInfo.lettercount || 0; this.lettercount = knowledgeInfo.lettercount || 0;
...@@ -134,17 +135,17 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -134,17 +135,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
cc.find("sentencecount", smallbg_2_right).getComponent(cc.RichText).string = `<color=#41954F>${this.sentencecount}</c> <color=#726E6F><size=15>个</size></c>`; cc.find("sentencecount", smallbg_2_right).getComponent(cc.RichText).string = `<color=#41954F>${this.sentencecount}</c> <color=#726E6F><size=15>个</size></c>`;
} }
learntimes = [0,0,25,50,99,73,8]; learntimes = [0, 0, 25, 50, 99, 73, 8];
learntotal = 0; learntotal = 0;
average = 0; average = 0;
async drawChart() { async drawChart() {
if (!this.userInfo) { if (!this.userInfo) {
return; return;
} }
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/learn/chart", {kidid: this.userInfo.id,token: this.token}); const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/learn/chart", { kidid: this.userInfo.id, token: this.token });
const chartInfo = JSON.parse(res).data; const chartInfo = JSON.parse(res).data;
if (chartInfo) { if (chartInfo) {
// this.learntimes = chartInfo.learntimes; this.learntimes = chartInfo.learntimes;
this.learntotal = chartInfo.learntotal; this.learntotal = chartInfo.learntotal;
this.average = chartInfo.average; this.average = chartInfo.average;
} }
...@@ -161,20 +162,22 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -161,20 +162,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
const chart_line = cc.find(`chart_line`, linebg).getComponent(cc.Graphics); const chart_line = cc.find(`chart_line`, linebg).getComponent(cc.Graphics);
const max = Math.max(...this.learntimes); const max = Math.max(...this.learntimes);
const itemLen = (maxY - baseY)/max; const itemLen = max ? (maxY - baseY) / max : 0;
cc.find(`dp8/hafy`, linebg).getComponent(cc.Label).string = Math.floor(max/2)+""; if (max) {
cc.find(`dp9/max`, linebg).getComponent(cc.Label).string = max+""; cc.find(`dp8/hafy`, linebg).getComponent(cc.Label).string = Math.floor(max / 2) + "";
cc.find(`dp9/max`, linebg).getComponent(cc.Label).string = max + "";
}
// 渲染刻度 // 渲染刻度
const date = new Date(); const date = new Date();
let monthNum; let monthNum;
for (let i = 1; i < 8; i++) { for (let i = 1; i < 8; i++) {
const index = i; const index = i;
const value = this.learntimes[i-1]; const value = this.learntimes[i - 1];
date.setDate(date.getDate() - date.getDay() + index); date.setDate(date.getDate() - date.getDay() + index);
const xNode = cc.find(`dp${index}/date${index}`, linebg); const xNode = cc.find(`dp${index}/date${index}`, linebg);
const dateStr = date["pattern"]("M月d日"); const dateStr = date["pattern"]("M月d日");
if (dateStr.split("")[0] != monthNum){ if (dateStr.split("")[0] != monthNum) {
monthNum = dateStr.split("")[0]; monthNum = dateStr.split("")[0];
xNode.getComponent(cc.Label).string = dateStr; xNode.getComponent(cc.Label).string = dateStr;
} else { } else {
...@@ -184,15 +187,15 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -184,15 +187,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (today["pattern"]("d") == date["pattern"]("d")) { if (today["pattern"]("d") == date["pattern"]("d")) {
xNode.getComponent(cc.Label).string = "今天"; xNode.getComponent(cc.Label).string = "今天";
} }
if (i==1){ if (i == 1) {
chart_line.moveTo(xNode.parent.x, itemLen*value+baseY); chart_line.moveTo(xNode.parent.x, itemLen * value + baseY);
} else { } else {
chart_line.lineTo(xNode.parent.x, itemLen*value+baseY); chart_line.lineTo(xNode.parent.x, itemLen * value + baseY);
} }
const dotClone = cc.instantiate(dotHide); const dotClone = cc.instantiate(dotHide);
dotClone.parent = linebg; dotClone.parent = linebg;
cc.find("pop/text", dotClone).getComponent(cc.Label).string = `${value}分钟`; cc.find("pop/text", dotClone).getComponent(cc.Label).string = `${value}分钟`;
dotClone.setPosition(xNode.parent.x, itemLen*value+baseY); dotClone.setPosition(xNode.parent.x, itemLen * value + baseY);
dotClone.active = true; dotClone.active = true;
} }
chart_line.stroke(); chart_line.stroke();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment