Commit 0bb49d32 authored by liujiangnan's avatar liujiangnan

feat: 修改曲线

parent c424f54e
import {
asyncDelay,
onHomeworkFinish,
asyncCallNetworkApiGet,
asyncCallNetworkApiPost } from "../script/util";
import {
asyncDelay,
onHomeworkFinish,
asyncCallNetworkApiGet,
asyncCallNetworkApiPost
} from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
const { ccclass, property } = cc._decorator;
......@@ -10,203 +11,205 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.SpriteFrame)
picture: Array<cc.SpriteFrame> = [];
addPreloadImage() {
}
addPreloadAudio() {
}
addPreloadAnima() {
}
async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
await this.initUserInfo();
await this.initPartInfo();
await this.initSpeakInfo();
await this.initKnowledgeInfo();
await this.drawChart();
this.initBg();
this.initListener();
}
token = null;
initData() {
const middleLayer = cc.find('middleLayer');
if (!middleLayer) {
cc.sys.localStorage.setItem('token', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGhvbmUiOiIxNTUwMDAwMDAwMSIsInNpZ24iOiI3NWEwNmY0OC1jYTQ4LTQwZmQtYmFmMi02MzhjMzJkYjRmNzciLCJpYXQiOjE2NTI5NTA4MzksImV4cCI6MTY1NTU0MjgzOX0.OHh6__AUX4Z8pOM8IGUXvfIf4N1HMYdhjyhYV6Iwghc');
}
this.token = cc.sys.localStorage.getItem("token");
}
getFomartDate () {
const date = new Date();
date.setDate(date.getDate() - date.getDay() + 1);
const monday = date["pattern"]("MM.dd");
date.setDate(date.getDate() + 6);
const sunday = date["pattern"]("MM.dd");
return `${monday} - ${sunday}`;
}
userInfo = null;
async initUserInfo() {
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/info", {token: this.token});
const userInfo = JSON.parse(res).data;
this.userInfo = userInfo;
const avatarIndex = userInfo.avatar_url ? parseInt(userInfo.avatar_url)-1 : 0;
const usercenter = cc.find("Canvas/usercenter/view/content/scollpage/user_center");
// 头像
cc.find("avatar", usercenter).getComponent(cc.Sprite).spriteFrame = this.picture[avatarIndex];
// 昵称
cc.find("nickname", usercenter).getComponent(cc.Label).string = userInfo.nick_name || "";
// 日历牌
cc.find("learndate", usercenter).getComponent(cc.Label).string = this.getFomartDate();
}
// 学习小结
partCount = 0;
// 本周学习小结
partWeekCount = 0;
async initPartInfo() {
if (!this.userInfo) {
return;
}
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/part/count", {kidid: this.userInfo.id,token: this.token});
const partInfo = JSON.parse(res).data;
if (partInfo) {
this.partWeekCount = partInfo.weekcount;
this.partCount = partInfo.count;
}
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>`;
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("numberbg/weekpartcount", smallbg_1_left).getComponent(cc.Label).string = "+" + this.partWeekCount;
}
// 开口次数
speakCount = 0;
// 本周开口次数
speakWeekCount = 0;
async initSpeakInfo() {
if (!this.userInfo) {
return;
}
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/record/count", {kidid: this.userInfo.id,token: this.token});
const speakInfo = JSON.parse(res).data;
if (speakInfo) {
this.speakWeekCount = speakInfo.weekcount;
this.speakCount = speakInfo.count;
}
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("numberbg/weekpartcount", smallbg_1_right).getComponent(cc.Label).string = "+" + this.speakWeekCount;
}
lettercount = 0;
wordcount = 0;
sentencecount = 0;
async initKnowledgeInfo() {
if (!this.userInfo) {
return;
}
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/knowledge/count", {kidid: this.userInfo.id,token: this.token});
const knowledgeInfo = JSON.parse(res).data;
if (knowledgeInfo) {
this.lettercount = knowledgeInfo.lettercount || 0;
this.wordcount = knowledgeInfo.wordcount || 0;
this.sentencecount = knowledgeInfo.sentencecount || 0;
}
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_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("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>`;
}
learntimes = [0,0,25,50,99,73,8];
learntotal = 0;
average = 0;
async drawChart() {
if (!this.userInfo) {
return;
}
const res:any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/learn/chart", {kidid: this.userInfo.id,token: this.token});
const chartInfo = JSON.parse(res).data;
if (chartInfo) {
// this.learntimes = chartInfo.learntimes;
this.learntotal = chartInfo.learntotal;
this.average = chartInfo.average;
}
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>`;
const dotHide = cc.find("dothide", linebg);
const xAxis = cc.find("xline", linebg);
const line2 = cc.find("line2", linebg);
const baseY = xAxis.y;
const maxY = line2.y;
const chart_line = cc.find(`chart_line`, linebg).getComponent(cc.Graphics);
const max = Math.max(...this.learntimes);
const itemLen = (maxY - baseY)/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 index = i;
const value = this.learntimes[i-1];
date.setDate(date.getDate() - date.getDay() + index);
const xNode = cc.find(`dp${index}/date${index}`, linebg);
const dateStr = date["pattern"]("M月d日");
if (dateStr.split("")[0] != monthNum){
monthNum = dateStr.split("")[0];
xNode.getComponent(cc.Label).string = dateStr;
} else {
xNode.getComponent(cc.Label).string = date["pattern"]("d");
}
const today = new Date();
if (today["pattern"]("d") == date["pattern"]("d")) {
xNode.getComponent(cc.Label).string = "今天";
}
if (i==1){
chart_line.moveTo(xNode.parent.x, itemLen*value+baseY);
} else {
chart_line.lineTo(xNode.parent.x, itemLen*value+baseY);
}
const dotClone = cc.instantiate(dotHide);
dotClone.parent = linebg;
cc.find("pop/text", dotClone).getComponent(cc.Label).string = `${value}分钟`;
dotClone.setPosition(xNode.parent.x, itemLen*value+baseY);
dotClone.active = true;
}
chart_line.stroke();
}
initBg() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
}
// update (dt) {}
initListener() {
}
@property(cc.SpriteFrame)
picture: Array<cc.SpriteFrame> = [];
addPreloadImage() {
}
addPreloadAudio() {
}
addPreloadAnima() {
}
async onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this.initData();
await this.initUserInfo();
await this.initPartInfo();
await this.initSpeakInfo();
await this.initKnowledgeInfo();
await this.drawChart();
this.initBg();
this.initListener();
}
token = null;
initData() {
const middleLayer = cc.find('middleLayer');
if (!middleLayer) {
cc.sys.localStorage.setItem('token', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwicGhvbmUiOiIxNTUwMDAwMDAwMSIsInNpZ24iOiI3NWEwNmY0OC1jYTQ4LTQwZmQtYmFmMi02MzhjMzJkYjRmNzciLCJpYXQiOjE2NTI5NTA4MzksImV4cCI6MTY1NTU0MjgzOX0.OHh6__AUX4Z8pOM8IGUXvfIf4N1HMYdhjyhYV6Iwghc');
}
this.token = cc.sys.localStorage.getItem("token");
}
getFomartDate() {
const date = new Date();
date.setDate(date.getDate() - date.getDay() + 1);
const monday = date["pattern"]("MM.dd");
date.setDate(date.getDate() + 6);
const sunday = date["pattern"]("MM.dd");
return `${monday} - ${sunday}`;
}
userInfo = null;
async initUserInfo() {
const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/info", { token: this.token });
const userInfo = JSON.parse(res).data;
this.userInfo = userInfo;
const avatarIndex = userInfo.avatar_url ? parseInt(userInfo.avatar_url) - 1 : 0;
const usercenter = cc.find("Canvas/usercenter/view/content/scollpage/user_center");
// 头像
cc.find("avatar", usercenter).getComponent(cc.Sprite).spriteFrame = this.picture[avatarIndex];
// 昵称
cc.find("nickname", usercenter).getComponent(cc.Label).string = userInfo.nick_name || "";
// 日历牌
cc.find("learndate", usercenter).getComponent(cc.Label).string = this.getFomartDate();
}
// 学习小结
partCount = 0;
// 本周学习小结
partWeekCount = 0;
async initPartInfo() {
if (!this.userInfo) {
return;
}
const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/part/count", { kidid: this.userInfo.id, token: this.token });
const partInfo = JSON.parse(res).data;
if (partInfo) {
this.partWeekCount = partInfo.weekcount;
this.partCount = partInfo.count;
}
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>`;
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("numberbg/weekpartcount", smallbg_1_left).getComponent(cc.Label).string = "+" + this.partWeekCount;
}
// 开口次数
speakCount = 0;
// 本周开口次数
speakWeekCount = 0;
async initSpeakInfo() {
if (!this.userInfo) {
return;
}
const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/record/count", { kidid: this.userInfo.id, token: this.token });
const speakInfo = JSON.parse(res).data;
if (speakInfo) {
this.speakWeekCount = speakInfo.weekcount;
this.speakCount = speakInfo.count;
}
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("numberbg/weekpartcount", smallbg_1_right).getComponent(cc.Label).string = "+" + this.speakWeekCount;
}
lettercount = 0;
wordcount = 0;
sentencecount = 0;
async initKnowledgeInfo() {
if (!this.userInfo) {
return;
}
const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/knowledge/count", { kidid: this.userInfo.id, token: this.token });
const knowledgeInfo = JSON.parse(res).data;
if (knowledgeInfo) {
this.lettercount = knowledgeInfo.lettercount || 0;
this.wordcount = knowledgeInfo.wordcount || 0;
this.sentencecount = knowledgeInfo.sentencecount || 0;
}
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_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("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>`;
}
learntimes = [0, 0, 25, 50, 99, 73, 8];
learntotal = 0;
average = 0;
async drawChart() {
if (!this.userInfo) {
return;
}
const res: any = await asyncCallNetworkApiGet("/api/oxford/v1/kid/learn/chart", { kidid: this.userInfo.id, token: this.token });
const chartInfo = JSON.parse(res).data;
if (chartInfo) {
this.learntimes = chartInfo.learntimes;
this.learntotal = chartInfo.learntotal;
this.average = chartInfo.average;
}
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>`;
const dotHide = cc.find("dothide", linebg);
const xAxis = cc.find("xline", linebg);
const line2 = cc.find("line2", linebg);
const baseY = xAxis.y;
const maxY = line2.y;
const chart_line = cc.find(`chart_line`, linebg).getComponent(cc.Graphics);
const max = Math.max(...this.learntimes);
const itemLen = max ? (maxY - baseY) / max : 0;
if (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 index = i;
const value = this.learntimes[i - 1];
date.setDate(date.getDate() - date.getDay() + index);
const xNode = cc.find(`dp${index}/date${index}`, linebg);
const dateStr = date["pattern"]("M月d日");
if (dateStr.split("")[0] != monthNum) {
monthNum = dateStr.split("")[0];
xNode.getComponent(cc.Label).string = dateStr;
} else {
xNode.getComponent(cc.Label).string = date["pattern"]("d");
}
const today = new Date();
if (today["pattern"]("d") == date["pattern"]("d")) {
xNode.getComponent(cc.Label).string = "今天";
}
if (i == 1) {
chart_line.moveTo(xNode.parent.x, itemLen * value + baseY);
} else {
chart_line.lineTo(xNode.parent.x, itemLen * value + baseY);
}
const dotClone = cc.instantiate(dotHide);
dotClone.parent = linebg;
cc.find("pop/text", dotClone).getComponent(cc.Label).string = `${value}分钟`;
dotClone.setPosition(xNode.parent.x, itemLen * value + baseY);
dotClone.active = true;
}
chart_line.stroke();
}
initBg() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
}
// 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