Commit c5d5ac15 authored by 李维's avatar 李维

没有配置背景图时显示默认背景

parent 9a5019fa
...@@ -43,6 +43,8 @@ export default class NewClass extends cc.Component { ...@@ -43,6 +43,8 @@ export default class NewClass extends cc.Component {
data = []; data = [];
configData = []; configData = [];
userInfo = null userInfo = null
nameLblStr = "";
headSprStr = "";
handleClickBackBtn() { handleClickBackBtn() {
const vc = this.Viewer.getComponent("PageViewer"); const vc = this.Viewer.getComponent("PageViewer");
...@@ -100,16 +102,19 @@ export default class NewClass extends cc.Component { ...@@ -100,16 +102,19 @@ export default class NewClass extends cc.Component {
} }
} }
let bgImageUrl = null;
if (_configData) { if (_configData) {
const { rows } = await asyncCallNetworkApiGet(`/api/courseware/v2/${_configData.id}/list`, {}); const { rows } = await asyncCallNetworkApiGet(`/api/courseware/v2/${_configData.id}/list`, {});
if (rows && rows[0] && rows[0].data) { if (rows && rows[0] && rows[0].data) {
let _data = JSON.parse(rows[0].data) let _data = JSON.parse(rows[0].data)
this.configData = _data.pages this.configData = _data.pages;
this.nameLblStr = _data.title this.nameLblStr = _data.title;
this.headSprStr = _data.teacher_avatar this.headSprStr = _data.teacher_avatar;
this.initCustomBg(_data.bg_image_url); bgImageUrl = _data.bg_image_url;
} }
} }
this.initCustomBg(bgImageUrl);
this.refreshConfig() this.refreshConfig()
// 数据汇报 // 数据汇报
...@@ -127,8 +132,6 @@ export default class NewClass extends cc.Component { ...@@ -127,8 +132,6 @@ export default class NewClass extends cc.Component {
} }
} }
nameLblStr = "";
headSprStr = "";
refreshConfig() { refreshConfig() {
if (this.configData && this.configData.length > 0) { if (this.configData && this.configData.length > 0) {
this.btn_preview.active = true; this.btn_preview.active = true;
...@@ -194,7 +197,11 @@ export default class NewClass extends cc.Component { ...@@ -194,7 +197,11 @@ export default class NewClass extends cc.Component {
} }
initCustomBg(bg_image_url) { initCustomBg(bg_image_url) {
console.log("Iniit", bg_image_url)
if(!bg_image_url) { if(!bg_image_url) {
// 没有背景图 还原默认图
cc.find("bg/bg_default", this.node).active = true;
cc.find("bg/bg", this.node).active = false;
return return
} }
const canvas = cc.find("Canvas"); const canvas = cc.find("Canvas");
...@@ -204,7 +211,7 @@ export default class NewClass extends cc.Component { ...@@ -204,7 +211,7 @@ export default class NewClass extends cc.Component {
const sy = canvas.height / sf.node.height; const sy = canvas.height / sf.node.height;
bg.getComponent(cc.Sprite).spriteFrame = sf.spriteFrame; bg.getComponent(cc.Sprite).spriteFrame = sf.spriteFrame;
bg.scale = Math.max(sx, sy); bg.scale = Math.max(sx, sy);
cc.find("bg/bg_default", this.node).opacity = 0; cc.find("bg/bg_default", this.node).active = false;
}) })
} }
......
...@@ -66,6 +66,9 @@ export default class NewClass extends cc.Component { ...@@ -66,6 +66,9 @@ export default class NewClass extends cc.Component {
initCustomBg(bg_image_url) { initCustomBg(bg_image_url) {
if(!bg_image_url) { if(!bg_image_url) {
// 没有背景图 还原默认图
cc.find("bg/bg_default", this.node).active = true;
cc.find("bg/bg", this.node).active = false;
return return
} }
const canvas = cc.find("Canvas"); const canvas = cc.find("Canvas");
...@@ -75,7 +78,7 @@ export default class NewClass extends cc.Component { ...@@ -75,7 +78,7 @@ export default class NewClass extends cc.Component {
const sy = canvas.height / sf.node.height; const sy = canvas.height / sf.node.height;
bg.getComponent(cc.Sprite).spriteFrame = sf.spriteFrame; bg.getComponent(cc.Sprite).spriteFrame = sf.spriteFrame;
bg.scale = Math.max(sx, sy); bg.scale = Math.max(sx, sy);
cc.find("bg/bg_default", this.node).opacity = 0; cc.find("bg/bg_default", this.node).active = false;
}) })
} }
...@@ -135,12 +138,14 @@ export default class NewClass extends cc.Component { ...@@ -135,12 +138,14 @@ export default class NewClass extends cc.Component {
let rows = [] let rows = []
this.configData = null this.configData = null
let bgImageUrl = null;
for (let v of resData.rows) { for (let v of resData.rows) {
if (v.name == "config") { if (v.name == "config") {
// 课程配置文件 // 课程配置文件
const _strData = (v.children && v.children[0] && v.children[0].template_name == "sn_config" && v.children[0].data) ? v.children && v.children[0] && v.children[0].data : "{}" const _strData = (v.children && v.children[0] && v.children[0].template_name == "sn_config" && v.children[0].data) ? v.children && v.children[0] && v.children[0].data : "{}"
this.configData = JSON.parse(_strData) this.configData = JSON.parse(_strData)
this.initCustomBg( this.configData.bg_image_url); bgImageUrl = this.configData.bg_image_url
} else { } else {
// 课程数据 // 课程数据
rows.push(v) rows.push(v)
...@@ -155,6 +160,7 @@ export default class NewClass extends cc.Component { ...@@ -155,6 +160,7 @@ export default class NewClass extends cc.Component {
return; return;
} }
this.initCustomBg(bgImageUrl);
await this.getAndStoreSyllabusStatus(rows); await this.getAndStoreSyllabusStatus(rows);
// const svNode = this.unitScrollView; // const svNode = this.unitScrollView;
const view = cc.find("view", svNode); const view = cc.find("view", svNode);
......
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