Commit 9632f862 authored by 李维's avatar 李维

添加背景图配置功能

parent 5aa43e26
...@@ -54,7 +54,7 @@ export default class NewClass extends cc.Component { ...@@ -54,7 +54,7 @@ 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(); this.userInfo = await this.Viewer.getComponent("PageViewer").getUserInfo();
} }
...@@ -79,6 +79,15 @@ export default class NewClass extends cc.Component { ...@@ -79,6 +79,15 @@ export default class NewClass extends cc.Component {
global.middleLayer.crossArray = []; global.middleLayer.crossArray = [];
} }
initBg() {
const canvas = cc.find("Canvas");
const bg = cc.find("bg/bg_default", this.node);
const sx = canvas.width / bg.width;
const sy = canvas.height / bg.height;
bg.scale = Math.max(sx, sy);
}
async initData() { async initData() {
const { rows } = await asyncCallNetworkApiGet(`/api/syllabus/v1/list`, { pid: this.node['syllabus_pid'], deep: 2 }); const { rows } = await asyncCallNetworkApiGet(`/api/syllabus/v1/list`, { pid: this.node['syllabus_pid'], deep: 2 });
this.data = [] this.data = []
...@@ -98,6 +107,7 @@ export default class NewClass extends cc.Component { ...@@ -98,6 +107,7 @@ export default class NewClass extends cc.Component {
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);
} }
} }
this.refreshConfig() this.refreshConfig()
...@@ -183,13 +193,19 @@ export default class NewClass extends cc.Component { ...@@ -183,13 +193,19 @@ export default class NewClass extends cc.Component {
} }
} }
initBg() { initCustomBg(bg_image_url) {
if(!bg_image_url) {
return
}
const canvas = cc.find("Canvas"); const canvas = cc.find("Canvas");
const bg = cc.find("bg/bg", this.node); const bg = cc.find("bg/bg", this.node);
getSprNodeByUrl(bg_image_url, (sf)=>{
const sx = canvas.width / bg.width; const sx = canvas.width / sf.node.width;
const sy = canvas.height / bg.height; const sy = canvas.height / sf.node.height;
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).destroy();
})
} }
initListView() { initListView() {
...@@ -209,7 +225,6 @@ export default class NewClass extends cc.Component { ...@@ -209,7 +225,6 @@ export default class NewClass extends cc.Component {
const sv = svNode.getComponent(cc.ScrollView); const sv = svNode.getComponent(cc.ScrollView);
this.initScrollViewItem(sv, itemArr, 1); this.initScrollViewItem(sv, itemArr, 1);
const content = sv.content; const content = sv.content;
const canvas = cc.find("Canvas"); const canvas = cc.find("Canvas");
if (content.width > canvas.width) { if (content.width > canvas.width) {
...@@ -217,17 +232,13 @@ export default class NewClass extends cc.Component { ...@@ -217,17 +232,13 @@ export default class NewClass extends cc.Component {
} else { } else {
content.x = -content.width / 2; content.x = -content.width / 2;
} }
} }
getItemArr(dataArr) { getItemArr(dataArr) {
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'; let unLock = this.userInfo.detail.cross_status == 1 ? true : this.syllabusLockStatusStore[data.id] === 'unlock';
if (i == 0 && !unLock) { if (i == 0 && !unLock) {
// 如果第一个是未解锁的状态,需要上报一个解锁并且渲染成解锁的状态 // 如果第一个是未解锁的状态,需要上报一个解锁并且渲染成解锁的状态
......
...@@ -40,7 +40,6 @@ export default class NewClass extends cc.Component { ...@@ -40,7 +40,6 @@ export default class NewClass extends cc.Component {
// onLoad () {} // onLoad () {}
async start () { async start () {
this.initBg(); this.initBg();
this.listItem = cc.find("view/content/item", this.unitScrollView); this.listItem = cc.find("view/content/item", this.unitScrollView);
} }
...@@ -50,25 +49,36 @@ export default class NewClass extends cc.Component { ...@@ -50,25 +49,36 @@ export default class NewClass extends cc.Component {
} }
async initView() { async initView() {
this.loading.active = true; this.loading.active = true;
this.initTitle(); this.initTitle();
await this.initUnitListView(); await this.initUnitListView();
this.loading.active = false; this.loading.active = false;
} }
initBg() { initBg() {
const canvas = cc.find("Canvas"); const canvas = cc.find("Canvas");
const bg = cc.find("bg/bg", this.node); const bg = cc.find("bg/bg_default", this.node);
const sx = canvas.width / bg.width; const sx = canvas.width / bg.width;
const sy = canvas.height / bg.height; const sy = canvas.height / bg.height;
bg.scale = Math.max(sx, sy); bg.scale = Math.max(sx, sy);
} }
initCustomBg(bg_image_url) {
if(!bg_image_url) {
return
}
const canvas = cc.find("Canvas");
const bg = cc.find("bg/bg", this.node);
getSprNodeByUrl(bg_image_url, (sf)=>{
const sx = canvas.width / sf.node.width;
const sy = canvas.height / sf.node.height;
bg.getComponent(cc.Sprite).spriteFrame = sf.spriteFrame;
bg.scale = Math.max(sx, sy);
cc.find("bg/bg_default", this.node).destroy();
})
}
async initTitle() { async initTitle() {
const titleLabelNode = cc.find("bg/bg_title/label", this.node); const titleLabelNode = cc.find("bg/bg_title/label", this.node);
...@@ -130,6 +140,7 @@ export default class NewClass extends cc.Component { ...@@ -130,6 +140,7 @@ export default class NewClass extends cc.Component {
// 课程配置文件 // 课程配置文件
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);
} else { } else {
// 课程数据 // 课程数据
rows.push(v) rows.push(v)
......
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