Commit 0bb49d32 authored by liujiangnan's avatar liujiangnan

feat: 修改曲线

parent c424f54e
import { 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;
...@@ -10,203 +11,205 @@ const { ccclass, property } = cc._decorator; ...@@ -10,203 +11,205 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class SceneComponent extends MyCocosSceneComponent { export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.SpriteFrame) @property(cc.SpriteFrame)
picture: Array<cc.SpriteFrame> = []; picture: Array<cc.SpriteFrame> = [];
addPreloadImage() { addPreloadImage() {
} }
addPreloadAudio() { addPreloadAudio() {
} }
addPreloadAnima() { addPreloadAnima() {
} }
async onLoadEnd() { async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考 // TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData(); this.initData();
await this.initUserInfo(); await this.initUserInfo();
await this.initPartInfo(); await this.initPartInfo();
await this.initSpeakInfo(); await this.initSpeakInfo();
await this.initKnowledgeInfo(); await this.initKnowledgeInfo();
await this.drawChart(); await this.drawChart();
this.initBg(); this.initBg();
this.initListener(); this.initListener();
} }
token = null; token = null;
initData() { initData() {
const middleLayer = cc.find('middleLayer'); const middleLayer = cc.find('middleLayer');
if (!middleLayer) { if (!middleLayer) {
cc.sys.localStorage.setItem('token', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGhvbmUiOiIxNTUwMDAwMDAwMSIsInNpZ24iOiI3NWEwNmY0OC1jYTQ4LTQwZmQtYmFmMi02MzhjMzJkYjRmNzciLCJpYXQiOjE2NTI5NTA4MzksImV4cCI6MTY1NTU0MjgzOX0.OHh6__AUX4Z8pOM8IGUXvfIf4N1HMYdhjyhYV6Iwghc'); cc.sys.localStorage.setItem('token', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGhvbmUiOiIxNTUwMDAwMDAwMSIsInNpZ24iOiI3NWEwNmY0OC1jYTQ4LTQwZmQtYmFmMi02MzhjMzJkYjRmNzciLCJpYXQiOjE2NTI5NTA4MzksImV4cCI6MTY1NTU0MjgzOX0.OHh6__AUX4Z8pOM8IGUXvfIf4N1HMYdhjyhYV6Iwghc');
} }
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");
date.setDate(date.getDate() + 6); date.setDate(date.getDate() + 6);
const sunday = date["pattern"]("MM.dd"); const sunday = date["pattern"]("MM.dd");
return `${monday} - ${sunday}`; return `${monday} - ${sunday}`;
} }
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];
// 昵称 // 昵称
cc.find("nickname", usercenter).getComponent(cc.Label).string = userInfo.nick_name || ""; cc.find("nickname", usercenter).getComponent(cc.Label).string = userInfo.nick_name || "";
// 日历牌 // 日历牌
cc.find("learndate", usercenter).getComponent(cc.Label).string = this.getFomartDate(); cc.find("learndate", usercenter).getComponent(cc.Label).string = this.getFomartDate();
} }
// 学习小结 // 学习小结
partCount = 0; partCount = 0;
// 本周学习小结 // 本周学习小结
partWeekCount = 0; partWeekCount = 0;
async initPartInfo() { async initPartInfo() {
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;
this.partCount = partInfo.count; this.partCount = partInfo.count;
} }
const usercenter = cc.find("Canvas/usercenter/view/content/scollpage/user_center"); const usercenter = cc.find("Canvas/usercenter/view/content/scollpage/user_center");
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;
} }
// 开口次数 // 开口次数
speakCount = 0; speakCount = 0;
// 本周开口次数 // 本周开口次数
speakWeekCount = 0; speakWeekCount = 0;
async initSpeakInfo() { async initSpeakInfo() {
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;
this.speakCount = speakInfo.count; this.speakCount = speakInfo.count;
} }
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;
} }
lettercount = 0; lettercount = 0;
wordcount = 0; wordcount = 0;
sentencecount = 0; sentencecount = 0;
async initKnowledgeInfo() { async initKnowledgeInfo() {
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;
this.wordcount = knowledgeInfo.wordcount || 0; this.wordcount = knowledgeInfo.wordcount || 0;
this.sentencecount = knowledgeInfo.sentencecount || 0; this.sentencecount = knowledgeInfo.sentencecount || 0;
} }
const smallbg_2_left = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_2_left"); const smallbg_2_left = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_2_left");
const smallbg_2_middle = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_2_middle"); const smallbg_2_middle = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_2_middle");
const smallbg_2_right = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_2_right"); const smallbg_2_right = cc.find("Canvas/usercenter/view/content/scollpage/smallbg_2_right");
cc.find("lettercount", smallbg_2_left).getComponent(cc.RichText).string = `<color=#41954F>${this.lettercount}</c> <color=#726E6F><size=15>个</size></c>`; cc.find("lettercount", smallbg_2_left).getComponent(cc.RichText).string = `<color=#41954F>${this.lettercount}</c> <color=#726E6F><size=15>个</size></c>`;
cc.find("wordcount", smallbg_2_middle).getComponent(cc.RichText).string = `<color=#41954F>${this.wordcount}</c> <color=#726E6F><size=15>个</size></c>`; cc.find("wordcount", smallbg_2_middle).getComponent(cc.RichText).string = `<color=#41954F>${this.wordcount}</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>`; 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;
} }
const linebg = cc.find("Canvas/usercenter/view/content/scollpage/linebg"); const linebg = cc.find("Canvas/usercenter/view/content/scollpage/linebg");
cc.find("textbg/desc", linebg).getComponent(cc.RichText).string = `<color=#726E6F>累计学习时长</c><color=#41954F><size=30> ${this.learntotal} </size></c><color=#726E6F>分钟</c>,<color=#726E6F>平均每日学习</c><color=#41954F><size=30> ${this.average} </size></c><color=#726E6F>分钟</c>`; cc.find("textbg/desc", linebg).getComponent(cc.RichText).string = `<color=#726E6F>累计学习时长</c><color=#41954F><size=30> ${this.learntotal} </size></c><color=#726E6F>分钟</c>,<color=#726E6F>平均每日学习</c><color=#41954F><size=30> ${this.average} </size></c><color=#726E6F>分钟</c>`;
const dotHide = cc.find("dothide", linebg); const dotHide = cc.find("dothide", linebg);
const xAxis = cc.find("xline", linebg); const xAxis = cc.find("xline", linebg);
const line2 = cc.find("line2", linebg); const line2 = cc.find("line2", linebg);
const baseY = xAxis.y; const baseY = xAxis.y;
const maxY = line2.y; const maxY = line2.y;
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();
let monthNum; // 渲染刻度
for (let i = 1; i < 8; i++) { const date = new Date();
const index = i; let monthNum;
const value = this.learntimes[i-1]; for (let i = 1; i < 8; i++) {
date.setDate(date.getDate() - date.getDay() + index); const index = i;
const xNode = cc.find(`dp${index}/date${index}`, linebg); const value = this.learntimes[i - 1];
const dateStr = date["pattern"]("M月d日"); date.setDate(date.getDate() - date.getDay() + index);
if (dateStr.split("")[0] != monthNum){ const xNode = cc.find(`dp${index}/date${index}`, linebg);
monthNum = dateStr.split("")[0]; const dateStr = date["pattern"]("M月d日");
xNode.getComponent(cc.Label).string = dateStr; if (dateStr.split("")[0] != monthNum) {
} else { monthNum = dateStr.split("")[0];
xNode.getComponent(cc.Label).string = date["pattern"]("d"); xNode.getComponent(cc.Label).string = dateStr;
} } else {
const today = new Date(); xNode.getComponent(cc.Label).string = date["pattern"]("d");
if (today["pattern"]("d") == date["pattern"]("d")) { }
xNode.getComponent(cc.Label).string = "今天"; const today = new Date();
} if (today["pattern"]("d") == date["pattern"]("d")) {
if (i==1){ xNode.getComponent(cc.Label).string = "今天";
chart_line.moveTo(xNode.parent.x, itemLen*value+baseY); }
} else { if (i == 1) {
chart_line.lineTo(xNode.parent.x, itemLen*value+baseY); chart_line.moveTo(xNode.parent.x, itemLen * value + baseY);
} } else {
const dotClone = cc.instantiate(dotHide); chart_line.lineTo(xNode.parent.x, itemLen * value + baseY);
dotClone.parent = linebg; }
cc.find("pop/text", dotClone).getComponent(cc.Label).string = `${value}分钟`; const dotClone = cc.instantiate(dotHide);
dotClone.setPosition(xNode.parent.x, itemLen*value+baseY); dotClone.parent = linebg;
dotClone.active = true; cc.find("pop/text", dotClone).getComponent(cc.Label).string = `${value}分钟`;
} dotClone.setPosition(xNode.parent.x, itemLen * value + baseY);
chart_line.stroke(); dotClone.active = true;
} }
chart_line.stroke();
initBg() { }
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax; initBg() {
} const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
// update (dt) {} }
initListener() { // update (dt) {}
} initListener() {
}
} }
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