cc.Class({ extends: cc.Component, properties: { headDefaultSpriteFrame: cc.SpriteFrame, headSprite: cc.Sprite, background: cc.Sprite, rankSprite: cc.Sprite, // rankRichText: cc.RichText, rankLabel: cc.Label, nameLabel: cc.Label, // lvRichText: cc.RichText, lvLabel: cc.Label, rankSpriteFrame: [cc.SpriteFrame], backgroundSpriteFrame: [cc.SpriteFrame], isMe: { get: function() { if (!this._isMe) { this._isMe = false; } return this._isMe; }, set: function(value) { this._isMe = value; if (this._isMe) { this.background.spriteFrame = this.backgroundSpriteFrame[1]; } else { this.background.spriteFrame = this.backgroundSpriteFrame[0]; } } }, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, init (model, isMe = false) { this.configData(model); this.isMe = isMe; }, start () { }, configData(model) { this.headSprite.spriteFrame = this.headDefaultSpriteFrame; if (model.avatarUrl) { this.createImageFromUrl(model.avatarUrl, (spriteFrame) => { this.headSprite.spriteFrame = spriteFrame; }); } this.nameLabel.string = model.nickname == undefined ? model.nickName : model.nickname; // debugger; if (model.rank < 4) { this.rankSprite.node.active = true; this.rankLabel.node.active = false; this.rankSprite.spriteFrame = this.rankSpriteFrame[(model.rank - 1)]; } else { this.rankSprite.node.active = false; this.rankLabel.node.active = true; let rank = (model.rank > 100) ? "100+" : model.rank; this.rankLabel.string = `${rank}`; } if (model.score != undefined) { this.lvLabel.string = `LV.${model.score}`; } else { if (model.KVDataList && model.KVDataList.length > 0) { let value = JSON.parse(model.KVDataList[0].value); this.lvLabel.string = `LV.${value.wxgame.score}`; } } }, createImageFromUrl(avatarUrl, success, fail) { if (avatarUrl) { var index = avatarUrl.indexOf('https:'); var httpIndex = avatarUrl.indexOf('http:'); if (index === 0 || httpIndex === 0) { //以'https:'开头 } else { avatarUrl = 'https:' + avatarUrl; } if (window.wx != undefined) { try { let image = wx.createImage(); image.onload = () => { try { let texture = new cc.Texture2D(); texture.initWithElement(image); texture.handleLoadedTexture(); success(new cc.SpriteFrame(texture)) } catch (e) { cc.log(e); cc.loader.loadRes('./common/default_avatar', cc.SpriteFrame, (err, spriteFrame) => { success(spriteFrame); }) } }; image.src = avatarUrl; } catch (e) { cc.log(e); cc.loader.loadRes('./common/default_avatar', cc.SpriteFrame, (err, spriteFrame) => { success(spriteFrame); }) } } else { cc.loader.load({ url: avatarUrl, type: 'jpg' }, (err, texture) => { if (err === undefined || err === null) { success(new cc.SpriteFrame(texture)); } else { cc.loader.loadRes('./common/default_avatar', cc.SpriteFrame, (err, spriteFrame) => { success(spriteFrame); }) } }); } } else { cc.loader.loadRes('./common/default_avatar', cc.SpriteFrame, (err, spriteFrame) => { success(spriteFrame); }) } } // update (dt) {}, });