码迷,mamicode.com
首页 > 微信 > 详细

微信简单的排行榜

时间:2018-07-13 22:15:20      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:port   color   public   程序   har   ==   mini   ali   image   

function IsMiniGame() {
return (Laya.Browser.window.wx != undefined)?true:false;
}

function SortAvatar(a, b)
{
return b["score"] - a["score"];
}

class VItem extends Laya.Box
{
public static WID: number = 500;
public static HEI: number = 200;

private Icon: Laya.Image;
private NickName: Laya.Label;
private Score: Laya.Label;

constructor()
{
super();
this.size(VItem.WID, VItem.HEI);
this.Icon = new Laya.Image();
this.Icon.size(100, 100);
this.Icon.pos(85, -5);
this.addChild(this.Icon);

this.NickName = new Laya.Label();
        this.NickName.text = "";
        this.NickName.fontSize = 35;
this.NickName.color = "#FFFFFF";
this.NickName.stroke = 4;
this.NickName.strokeColor = "#A27619";
this.NickName.pos(160, 5);
this.NickName.align = "center";
this.NickName.valign = "center";
        this.addChild(this.NickName);

this.Score = new Laya.Label();
        this.Score.text = "";
        this.Score.fontSize = 35;
this.Score.color = "#FFFFFF";
this.Score.stroke = 4;
this.Score.strokeColor = "#A27619";
        //this.Score.bold = true;
this.Score.pos(500, 10);
this.Score.align = "center";
this.Score.valign = "center";
        this.addChild(this.Score);
}

private SetIcon(src: string)
{
this.Icon.skin = src;
}

private SetNickName(nickname):void {
this.NickName.text = nickname;
}

private SetScore(score):void {
this.Score.text = "" + score;
}

public Update(data, index)
{
if (!data) {
return;
}
this.SetIcon(data["avatarUrl"]);
this.SetNickName(data["nickname"]);
this.SetScore(data["score"]);
}
}

// 程序入口
namespace Pioneer
{
export class Main
{
private VList:Laya.List;
private HList:Laya.List;
static nSize = 8;
private UserInfo = [];
private FriendList = [];
private nGetscore:number;
static sUserID = "";
constructor()
{
Laya.MiniAdpter.init(true, true);

Laya.init(720, 1280);
this.VList = new Laya.List();
this.VList.itemRender = VItem;
this.VList.repeatX = 1;
this.VList.repeatY = Main.nSize;

this.VList.x = 0;//(Laya.stage.width - VItem.WID * this.VList.repeatX) / 2;
this.VList.y = 10;//(Laya.stage.height - VItem.HEI * this.VList.repeatY) / 2;
this.VList.renderHandler = new Laya.Handler(this, this.UpdateVItem);
 
let self = this;
let sharedCanvas = wx.getSharedCanvas();

wx.onMessage(function(message)
{
if (message.type)
{
if (message.type == 1)
{
//通过接收主域的消息来设置开发数据域的画布大小跟矩阵信息
sharedCanvas.width = message.width;
sharedCanvas.height = message.height;
}
else if (message.type == 3)
{
self.GetData();
}
}
});
}

UpdateVItem(cell: VItem, index: number)
{
cell.Update(this.FriendList[index], index);
}

UpdateFriendList(res)
{
this.CullFriendList(res);
this.UpdateFriendListPage(0, Main.nSize);
}

UpdateFriendListPage(page, size)
{
Laya.stage.addChild(this.VList);
 
this.VList.array = this.FriendList;
}

CullFriendList(res)
{
let data = res.data;
 
this.FriendList = [];
for (let i = 0; i < data.length; ++i)
{
let avatar = {};
avatar["nickname"] = data[i].nickname;
avatar["avatarUrl"] = data[i].avatarUrl;
avatar["score"] = res.data[i].KVDataList[0].value;
this.FriendList.push(avatar);
}
}

GetData()
{
let self = this;
let score = wx.getFriendCloudStorage({
keyList:["score"],
success: function(res) {
self.UpdateFriendList(res);
},
fail: function (res) {
console.log("fail");
},
complete: function() {
console.log("complete");
}
});
}
}
}

微信简单的排行榜

标签:port   color   public   程序   har   ==   mini   ali   image   

原文地址:https://www.cnblogs.com/StevenChancxy/p/9307438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!