123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- // 开放数据域 KVData 以key/value形式保存
- // 以下为本项目value格式,转为string之后才能提交
- // {
- //
- // "wxgame": {//wxgame 字段是微信要求保留的字段,这样才能在微信小游戏中心显示好友排行榜(其实目前看来这个功能不是十分重要)
- // "score":16, // 好友星星数量,即等级展示
- // "update_time": 1513080573 //数据提交的时间戳
- // },
- // "gender":0, //0代表女性,1代表男性
- // "jobLevelName":"国际巨星" //好友的艺人头衔
- // "jobLevel"
- // }
- cc.Class({
- extends: cc.Component,
- properties: {
- bgSprite: cc.Sprite,
- artistLevelSprite: cc.Sprite,
- headSprite: cc.Sprite,
- nickLabel: cc.Label,
- starCountLabel: cc.Label,
- genderIcon: cc.Sprite,
- _itemId: 0,
- titleLabel: cc.Label,
- artistLevelBgs: [cc.SpriteFrame],
- femaleFrame: cc.SpriteFrame,
- maleFrame: cc.SpriteFrame,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- // this.titleLabel.node.opacity = 0;
- },
- /**
- * gender [int]
- * head [string]
- * nick [string]
- * stars [int]
- * uid [int]
- * */
- updateItem(userInfo, itemId) {
- this._itemId = itemId;
- this.user = userInfo;
- //昵称
- this.nickLabel.string = userInfo.nickname;
- //头像
- this.createImageFromUrl(userInfo.avatarUrl, (spriteFrame) => {
- this.headSprite.spriteFrame = spriteFrame;
- }, () => {
- });
- if (userInfo.KVDataList && userInfo.KVDataList.length > 0) {
- let value = JSON.parse(userInfo.KVDataList[0].value);
- // 性别
- this.genderIcon.spriteFrame = value.gender == 1 ? this.maleFrame : this.femaleFrame;
- //艺人头衔
- if (value.jobLevelName) {
- this.titleLabel.node.active = true;
- this.titleLabel.string = value.jobLevelName;
- } else {
- this.titleLabel.node.active = false;
- }
- if (value.jobLevel) {
- this.artistLevelSprite.node.active = true;
- this.artistLevelSprite.spriteFrame = this.artistLevelBgs[value.jobLevel - 1];
- } else {
- this.artistLevelSprite.node.active = false;
- }
- //星星数量
- this.starCountLabel.string = value.wxgame.score;
- }
- },
- start() {
- },
- 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);
- fail();
- }
- };
- image.src = avatarUrl;
- } catch (e) {
- cc.log(e);
- fail();
- }
- } else {
- cc.loader.load({
- url: avatarUrl, type: 'jpg'
- }, (err, texture) => {
- if (err === undefined || err === null) {
- success(new cc.SpriteFrame(texture));
- } else {
- fail();
- }
- });
- }
- } else {
- cc.loader.loadRes('./default_avatar', cc.SpriteFrame, (err, spriteFrame) => {
- success(spriteFrame);
- })
- }
- }
- // update (dt) {},
- });
|