Commit 57197efc authored by 李维's avatar 李维

添加了临时用户数据、Unit数据缓存

parent 62490ca1
...@@ -14175,7 +14175,7 @@ ...@@ -14175,7 +14175,7 @@
1, 1,
1, 1,
1, 1,
1 0
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
...@@ -14261,7 +14261,7 @@ ...@@ -14261,7 +14261,7 @@
"_normalMaterial": null, "_normalMaterial": null,
"_grayMaterial": null, "_grayMaterial": null,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.15,
"clickEvents": [ "clickEvents": [
{ {
"__id__": 314 "__id__": 314
...@@ -14269,8 +14269,8 @@ ...@@ -14269,8 +14269,8 @@
], ],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 0, "_N$transition": 3,
"transition": 0, "transition": 3,
"_N$normalColor": { "_N$normalColor": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 255,
...@@ -20550,7 +20550,7 @@ ...@@ -20550,7 +20550,7 @@
1, 1,
1, 1,
1, 1,
1 0
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
...@@ -20636,7 +20636,7 @@ ...@@ -20636,7 +20636,7 @@
"_normalMaterial": null, "_normalMaterial": null,
"_grayMaterial": null, "_grayMaterial": null,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.15,
"clickEvents": [ "clickEvents": [
{ {
"__id__": 468 "__id__": 468
...@@ -20644,8 +20644,8 @@ ...@@ -20644,8 +20644,8 @@
], ],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 0, "_N$transition": 3,
"transition": 0, "transition": 3,
"_N$normalColor": { "_N$normalColor": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 255,
...@@ -31674,7 +31674,7 @@ ...@@ -31674,7 +31674,7 @@
1, 1,
1, 1,
1, 1,
1 0
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
...@@ -31760,7 +31760,7 @@ ...@@ -31760,7 +31760,7 @@
"_normalMaterial": null, "_normalMaterial": null,
"_grayMaterial": null, "_grayMaterial": null,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.15,
"clickEvents": [ "clickEvents": [
{ {
"__id__": 703 "__id__": 703
...@@ -31768,8 +31768,8 @@ ...@@ -31768,8 +31768,8 @@
], ],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 0, "_N$transition": 3,
"transition": 0, "transition": 3,
"_N$normalColor": { "_N$normalColor": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 255,
...@@ -33796,7 +33796,7 @@ ...@@ -33796,7 +33796,7 @@
1, 1,
1, 1,
1, 1,
1 0
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
...@@ -33882,7 +33882,7 @@ ...@@ -33882,7 +33882,7 @@
"_normalMaterial": null, "_normalMaterial": null,
"_grayMaterial": null, "_grayMaterial": null,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.15,
"clickEvents": [ "clickEvents": [
{ {
"__id__": 752 "__id__": 752
...@@ -33890,8 +33890,8 @@ ...@@ -33890,8 +33890,8 @@
], ],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 0, "_N$transition": 3,
"transition": 0, "transition": 3,
"_N$normalColor": { "_N$normalColor": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 255,
...@@ -36377,7 +36377,7 @@ ...@@ -36377,7 +36377,7 @@
1, 1,
1, 1,
1, 1,
1 0
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
...@@ -36463,7 +36463,7 @@ ...@@ -36463,7 +36463,7 @@
"_normalMaterial": null, "_normalMaterial": null,
"_grayMaterial": null, "_grayMaterial": null,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.15,
"clickEvents": [ "clickEvents": [
{ {
"__id__": 810 "__id__": 810
...@@ -36471,8 +36471,8 @@ ...@@ -36471,8 +36471,8 @@
], ],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 0, "_N$transition": 3,
"transition": 0, "transition": 3,
"_N$normalColor": { "_N$normalColor": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 255,
...@@ -40604,7 +40604,7 @@ ...@@ -40604,7 +40604,7 @@
1, 1,
1, 1,
1, 1,
1 0
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
...@@ -40690,7 +40690,7 @@ ...@@ -40690,7 +40690,7 @@
"_normalMaterial": null, "_normalMaterial": null,
"_grayMaterial": null, "_grayMaterial": null,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.15,
"clickEvents": [ "clickEvents": [
{ {
"__id__": 906 "__id__": 906
...@@ -40698,8 +40698,8 @@ ...@@ -40698,8 +40698,8 @@
], ],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 0, "_N$transition": 3,
"transition": 0, "transition": 3,
"_N$normalColor": { "_N$normalColor": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 255,
...@@ -43151,7 +43151,7 @@ ...@@ -43151,7 +43151,7 @@
1, 1,
1, 1,
1, 1,
1 0
] ]
}, },
"_eulerAngles": { "_eulerAngles": {
...@@ -43237,7 +43237,7 @@ ...@@ -43237,7 +43237,7 @@
"_normalMaterial": null, "_normalMaterial": null,
"_grayMaterial": null, "_grayMaterial": null,
"duration": 0.1, "duration": 0.1,
"zoomScale": 1.2, "zoomScale": 1.15,
"clickEvents": [ "clickEvents": [
{ {
"__id__": 964 "__id__": 964
...@@ -43245,8 +43245,8 @@ ...@@ -43245,8 +43245,8 @@
], ],
"_N$interactable": true, "_N$interactable": true,
"_N$enableAutoGrayEffect": false, "_N$enableAutoGrayEffect": false,
"_N$transition": 0, "_N$transition": 3,
"transition": 0, "transition": 3,
"_N$normalColor": { "_N$normalColor": {
"__type__": "cc.Color", "__type__": "cc.Color",
"r": 255, "r": 255,
......
...@@ -26,9 +26,6 @@ export default class NewClass extends cc.Component { ...@@ -26,9 +26,6 @@ export default class NewClass extends cc.Component {
_inited = false; _inited = false;
// 点击用户中心 // 点击用户中心
handleClickUserCenter() { handleClickUserCenter() {
this.userPage.active = true; this.userPage.active = true;
...@@ -176,18 +173,11 @@ export default class NewClass extends cc.Component { ...@@ -176,18 +173,11 @@ export default class NewClass extends cc.Component {
userInfo; userInfo;
async getUserInfo() { async getUserInfo() {
this.userInfo = await global.middleLayer.getUserInfo(); const userInfo = await this.Viewer.getComponent("PageViewer").getUserInfo();
global.userInfo = { this.userInfo = userInfo.detail;
phone: this.userInfo.phone,
isIOSReview: this.userInfo.phone == "15500000001",
isAnonymous: this.userInfo.phone == "15500000002",
detail: this.userInfo
}
// 如果是匿名登录 隐藏右上角头像按钮 // 如果是匿名登录 隐藏右上角头像按钮
cc.find("/UserInfo", this.node).active = global.userInfo.isAnonymous ? false : true; cc.find("/UserInfo", this.node).active = this.userInfo.isAnonymous ? false : true;
cc.find("/UserLogin", this.node).active = global.userInfo.isAnonymous ? true : false; cc.find("/UserLogin", this.node).active = this.userInfo.isAnonymous ? true : false;
this.initTopUserPanel(); this.initTopUserPanel();
} }
......
...@@ -129,11 +129,11 @@ export default class NewClass extends cc.Component { ...@@ -129,11 +129,11 @@ export default class NewClass extends cc.Component {
this.showEnterFail(); this.showEnterFail();
return; return;
} }
global.userInfo = { this.Viewer.getComponent("PageViewer").setUserInfo({
phone: defaultPhone, phone: defaultPhone,
isAnonymous: true, isAnonymous: true,
isIOSReview: false, isIOSReview: false,
} });
global.middleLayer.isLogin = true; global.middleLayer.isLogin = true;
cc.sys.localStorage.setItem('token', res.data.token); cc.sys.localStorage.setItem('token', res.data.token);
cc.sys.localStorage.setItem('phone', defaultPhone); cc.sys.localStorage.setItem('phone', defaultPhone);
...@@ -188,11 +188,11 @@ export default class NewClass extends cc.Component { ...@@ -188,11 +188,11 @@ export default class NewClass extends cc.Component {
return; return;
} }
global.middleLayer.isLogin = true; global.middleLayer.isLogin = true;
global.userInfo = { this.Viewer.getComponent("PageViewer").setUserInfo({
phone: phone, phone: phone,
isAnonymous: false, isAnonymous: false,
isIOSReview: phone, isIOSReview: phone,
} });
cc.sys.localStorage.setItem('token', res.data.token); cc.sys.localStorage.setItem('token', res.data.token);
cc.sys.localStorage.setItem('phone', phone); cc.sys.localStorage.setItem('phone', phone);
this.showEnterSuccess(true); this.showEnterSuccess(true);
......
...@@ -42,6 +42,7 @@ export default class NewClass extends cc.Component { ...@@ -42,6 +42,7 @@ export default class NewClass extends cc.Component {
data=[]; data=[];
configData=[]; configData=[];
userInfo = null
handleClickBackBtn() { handleClickBackBtn() {
const vc = this.Viewer.getComponent("PageViewer"); const vc = this.Viewer.getComponent("PageViewer");
...@@ -53,13 +54,11 @@ export default class NewClass extends cc.Component { ...@@ -53,13 +54,11 @@ export default class NewClass extends cc.Component {
// onLoad () {} // onLoad () {}
async start() { async start() {
this.initBg(); this.initBg();
this.userInfo = await this.Viewer.getComponent("PageViewer").getUserInfo();
} }
async onEnable() { async onEnable() {
this.loading.active = true; this.loading.active = true;
this.scrollView.opacity = 0; this.scrollView.opacity = 0;
...@@ -73,6 +72,7 @@ export default class NewClass extends cc.Component { ...@@ -73,6 +72,7 @@ export default class NewClass extends cc.Component {
// 保存关卡数据用于解锁和跳下一关 // 保存关卡数据用于解锁和跳下一关
global.middleLayer.crossArray = this.data; global.middleLayer.crossArray = this.data;
this.userInfo = await this.Viewer.getComponent("PageViewer").getUserInfo();
} }
async onDisable() { async onDisable() {
...@@ -105,7 +105,6 @@ export default class NewClass extends cc.Component { ...@@ -105,7 +105,6 @@ export default class NewClass extends cc.Component {
// 数据汇报 // 数据汇报
if (this.node["pData"] && this.node["pData"].id!=null){ if (this.node["pData"] && this.node["pData"].id!=null){
console.log(cc.sys.localStorage.getItem('token'))
const {code, msg, results} = await asyncCallNetworkApiGet(`/api/kyxq/v1/user/course/report`, {syllabusid:this.node["pData"].id}) const {code, msg, results} = await asyncCallNetworkApiGet(`/api/kyxq/v1/user/course/report`, {syllabusid:this.node["pData"].id})
if (code != '200'){ if (code != '200'){
// 当前没有数据不显示按钮 // 当前没有数据不显示按钮
...@@ -151,7 +150,6 @@ export default class NewClass extends cc.Component { ...@@ -151,7 +150,6 @@ export default class NewClass extends cc.Component {
syllabusLockStatusStore = {}; // 课件是否解锁的存储对象 { 99343: 'locked', 19834: 'unlock' } syllabusLockStatusStore = {}; // 课件是否解锁的存储对象 { 99343: 'locked', 19834: 'unlock' }
async getAndStoreSyllabusStatus() { async getAndStoreSyllabusStatus() {
if (this.data.length == 0) { if (this.data.length == 0) {
return; return;
} }
...@@ -164,16 +162,13 @@ export default class NewClass extends cc.Component { ...@@ -164,16 +162,13 @@ export default class NewClass extends cc.Component {
} }
} }
} }
async initView() { async initView() {
this.initTitle(); this.initTitle();
this.initListView(); this.initListView();
} }
async initTitle() { async initTitle() {
const titleLabelNode = cc.find("bg/bg_title/label", this.node); const titleLabelNode = cc.find("bg/bg_title/label", this.node);
const titleLabel = titleLabelNode.getComponent(cc.Label); const titleLabel = titleLabelNode.getComponent(cc.Label);
titleLabel.string = this.node['pData'].name; titleLabel.string = this.node['pData'].name;
...@@ -234,14 +229,10 @@ export default class NewClass extends cc.Component { ...@@ -234,14 +229,10 @@ export default class NewClass extends cc.Component {
const itemArr = []; const itemArr = [];
for (let i = 0; i < dataArr.length; i++) { for (let i = 0; i < dataArr.length; i++) {
const data = dataArr[i]; const data = dataArr[i];
const itemNode = cc.instantiate(this.listItem); const itemNode = cc.instantiate(this.listItem);
// 前期测试,都放开成解锁状态 let unLock = this.userInfo.detail.cross_status == 1 ? true : this.syllabusLockStatusStore[data.id]==='unlock';
// const unLock = this.syllabusLockStatusStore[data.id]==='unlock';
const unLock = true;
if (i==0 && !unLock) { if (i==0 && !unLock) {
// 如果第一个是未解锁的状态,需要上报一个解锁并且渲染成解锁的状态 // 如果第一个是未解锁的状态,需要上报一个解锁并且渲染成解锁的状态
asyncCallNetworkApiPost(`/api/kyxq/v1/user/unlock`, {syllabus_id: data.id}).then((res) => { asyncCallNetworkApiPost(`/api/kyxq/v1/user/unlock`, {syllabus_id: data.id}).then((res) => {
...@@ -249,6 +240,7 @@ export default class NewClass extends cc.Component { ...@@ -249,6 +240,7 @@ export default class NewClass extends cc.Component {
global.middleLayer.showTips(`解锁失败`); global.middleLayer.showTips(`解锁失败`);
} }
}); });
unLock = true;
} }
data.unLock = unLock; data.unLock = unLock;
...@@ -258,20 +250,11 @@ export default class NewClass extends cc.Component { ...@@ -258,20 +250,11 @@ export default class NewClass extends cc.Component {
cc.find("English_label", itemNode).getComponent(cc.Label).string = data.tag; cc.find("English_label", itemNode).getComponent(cc.Label).string = data.tag;
const coverNode = cc.find("pic_layer", itemNode); const coverNode = cc.find("pic_layer", itemNode);
const maxW = coverNode.width;
const maxH = coverNode.height;
getSprNodeByUrl(data.cover, (spr) => { getSprNodeByUrl(data.cover, (spr) => {
coverNode.addChild(spr.node); coverNode.addChild(spr.node);
spr.srcBlendFactor = cc.macro.BlendFactor.ONE spr.srcBlendFactor = cc.macro.BlendFactor.ONE
setSprNodeMaxLen(spr.node, coverNode.width, coverNode.height); setSprNodeMaxLen(spr.node, coverNode.width, coverNode.height);
if (unLock) { if (unLock) {
cc.find(`icon_lock`, itemNode).active = false; cc.find(`icon_lock`, itemNode).active = false;
} else { } else {
...@@ -279,7 +262,6 @@ export default class NewClass extends cc.Component { ...@@ -279,7 +262,6 @@ export default class NewClass extends cc.Component {
} }
itemNode.active = true; itemNode.active = true;
}); });
itemArr.push(itemNode); itemArr.push(itemNode);
} }
return itemArr; return itemArr;
...@@ -303,7 +285,6 @@ export default class NewClass extends cc.Component { ...@@ -303,7 +285,6 @@ export default class NewClass extends cc.Component {
initScrollViewItem(sv, itemArr, row = 1) { initScrollViewItem(sv, itemArr, row = 1) {
sv.scrollToTop(); sv.scrollToTop();
const content = sv.content; const content = sv.content;
content.width = sv.node.width; content.width = sv.node.width;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
// Learn life-cycle callbacks: // Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { asyncCallNetworkApiGet } from "./util";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
...@@ -42,8 +44,64 @@ export default class NewClass extends cc.Component { ...@@ -42,8 +44,64 @@ export default class NewClass extends cc.Component {
// onLoad () {} // onLoad () {}
status = {
}
setStatus(key, value) {
this.status[key] = value;
}
getStatus(key) {
return this.status[key];
}
// 统一管理获取用户信息接口
async getUserInfo() {
const userInfo = this.getStatus("userInfo");
const nowDate = new Date().getTime();
const expTime = 30 * 1000; // 30秒超期
if(userInfo && (nowDate - userInfo.updateTime) < expTime) {
return this.getStatus("userInfo")
} else {
const userInfo = await global.middleLayer.getUserInfo();
this.setStatus("userInfo", {
phone: userInfo.phone,
isIOSReview: userInfo.phone == "15500000001",
isAnonymous: userInfo.phone == "15500000002",
detail: userInfo,
updateTime: new Date().getTime()
})
return this.getStatus("userInfo")
}
}
setUserInfo(userInfo) {
this.setStatus("userInfo", userInfo)
}
// 缓存课程数据
async getSyllabusTreeByPid(syllabus_pid) {
if(!syllabus_pid) {
return
}
const saveKey = `SyllabusTree_${syllabus_pid}`;
const treeData = this.getStatus(saveKey);
console.log(treeData)
const nowDate = new Date().getTime();
const expTime = 10 * 60 * 1000; // 10分钟超期
if(treeData && (nowDate - treeData.updateTime) < expTime) {
return this.getStatus(saveKey)
} else {
const treeData = await asyncCallNetworkApiGet(`/api/syllabus/v3/tree`, {pid: syllabus_pid, deep: 2});
treeData.updateTime = new Date();
this.setStatus(saveKey, treeData)
return this.getStatus(saveKey)
}
}
async start () { async start () {
const userInfo = await global.middleLayer.getUserInfo(); const userInfo = await this.getUserInfo();
if (!userInfo) { if (!userInfo) {
this._currentViewNode = this.loginPage; this._currentViewNode = this.loginPage;
this._currentViewName = "LoginPage" this._currentViewName = "LoginPage"
......
...@@ -46,6 +46,7 @@ export default class NewClass extends cc.Component { ...@@ -46,6 +46,7 @@ export default class NewClass extends cc.Component {
} }
async onEnable() { async onEnable() {
console.log("Unit page on Enabel")
await this.initView(); await this.initView();
} }
...@@ -119,9 +120,10 @@ export default class NewClass extends cc.Component { ...@@ -119,9 +120,10 @@ export default class NewClass extends cc.Component {
configData=[] configData=[]
async initUnitListView() { async initUnitListView() {
console.log("initUnitListView")
const svNode = this.unitScrollView; const svNode = this.unitScrollView;
svNode.opacity = 0; svNode.opacity = 0;
const resData = await asyncCallNetworkApiGet(`/api/syllabus/v3/tree`, {pid: this.node['syllabus_pid'], deep: 2}); const resData = await this.Viewer.getComponent("PageViewer").getSyllabusTreeByPid(this.node['syllabus_pid'])
let rows=[] let rows=[]
this.configData=[] this.configData=[]
......
...@@ -100,7 +100,7 @@ export abstract class middleLayerBase extends cc.Component { ...@@ -100,7 +100,7 @@ export abstract class middleLayerBase extends cc.Component {
} }
xhr.abort(); xhr.abort();
this.callNetworkApiGet(uri, data, callback); this.callNetworkApiGet(uri, data, callback);
}, 5); }, 10);
}); });
} }
......
...@@ -54,16 +54,17 @@ export default class NewClass extends cc.Component { ...@@ -54,16 +54,17 @@ export default class NewClass extends cc.Component {
initDeleteAccoutBtn() { initDeleteAccoutBtn() {
const delBtn = cc.find("btn_delAccount", this.node) const delBtn = cc.find("btn_delAccount", this.node)
delBtn.active = global.userInfo.isIOSReview ? true : false; const userInfo = this.Viewer.getComponent("PageViewer").getUserInfo();
delBtn.active = userInfo.isIOSReview ? true : false;
} }
logout() { logout() {
global.middleLayer.isLogin = false; global.middleLayer.isLogin = false;
global.userInfo = { this.Viewer.getComponent("PageViewer").setUserInfo({
phone: "", phone: "",
isAnonymous: false, isAnonymous: false,
isIOSReview: false, isIOSReview: false,
} });
// 清空信息 // 清空信息
cc.sys.localStorage.setItem('token', ""); cc.sys.localStorage.setItem('token', "");
......
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