| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754 |
- cc.Class({
- extends: cc.Component,
- properties: {
- content: cc.Node,
- prefab: cc.Prefab,
- prefabme: cc.Prefab,
- GoldMedal: cc.SpriteFrame,
- SilverMedal:cc.SpriteFrame,
- BronzeMedal:cc.SpriteFrame,
- },
- onLoad() {
- this.nodes = [];
- this.ranklist = cc.find("Canvas/ranklist");
- this.info = cc.find("Canvas/info");
- // this.Transcend = UtilsPrefabs.getNode("Transcend",cc.find("Canvas"));
- // this.animCtrl = this.Transcend.getComponent("cc.Animation");
- // console.log("动画组件紫玉到底有没有",this.Transcend);
- //
- //
- //
- // if (this.animCtrl!=null) {
- // this.animCtrl.on('finished', this.finished,this);
- // }
- // this.canvasAdopt();
- },
- finished : function(){
- // console.log("动画回调了吗",this.Transcendnode);
- if (this.Transcendnode != null) {
- this.Transcendnode.active = false;
- }
- },
- canvasAdopt() {
- // 适配解决方案
- let canvas = cc.director.getScene().getChildByName('Canvas').getComponent(cc.Canvas)
- // 设计分辨率比
- let rateR = canvas.designResolution.height/canvas.designResolution.width;
- // 显示分辨率比
- let rateV = cc.view.getVisibleSize().height / cc.view.getVisibleSize().width;
- console.log("winSize: rateR: " + rateR + " rateV: " + rateV);
- if (rateV > rateR) {
- canvas.fitHeight = false;
- canvas.fitWidth = true;
- console.log("winSize: fitWidth");
- } else {
- canvas.fitHeight = true;
- canvas.fitWidth = false;
- console.log("winSize: fitHeight");
- }
- },
- getFriend : function(){
- this.removeAll();
- if (cc.sys.platform === cc.sys.WECHAT_GAME){
- wx.getFriendCloudStorage({
- keyList: ['score'],
- success: function (res) {
- // console.log("朋友数据是",res.data);
- // console.log("我的数据是",userData.openId);
- // console.log(res.data[0].KVDataList[0].value);
- // for (let i = 0; i < res.data.length; i++) {
- // let friendInfo = res.data[i];
- // if (!friendInfo) {
- // _self.createPrefab();
- // continue;
- // }
- // _self.createUserBlock(friendInfo,i);
- // }
- //添加排行榜为 自己的条目在下面
- this.testListView(this.initData(res.data));
- this.addMyItem();
- }.bind(this),
- fail: function (res) {
- console.error(res);
- }.bind(this)
- });
- // console.log("自己的");
- // this.testListView();
- } else{
- this.testListView(this.initData(null));
- //添加排行榜为 自己的条目在下面
- this.addMyItem();
- }
- },
- removeAll : function(){
- for (var i = 0; i <this.nodes.length ; i++) {
- if (this.nodes[i] != null) {
- this.nodes[i].destroy();
- }
- }
- this.nodes = [];
- },
- //获取到当前名字
- getRanking : function(callback){
- if (cc.sys.platform === cc.sys.WECHAT_GAME){
- wx.getFriendCloudStorage({
- keyList: ['score'],
- success: function (res) {
- // console.log("朋友数据是",res.data);
- // console.log("我的数据是",userData.openId);
- // console.log(res.data[0].KVDataList[0].value);
- // for (let i = 0; i < res.data.length; i++) {
- // let friendInfo = res.data[i];
- // if (!friendInfo) {
- // _self.createPrefab();
- // continue;
- // }
- // _self.createUserBlock(friendInfo,i);
- // }
- this.initData(res.data,callback);
- }.bind(this),
- fail: function (res) {
- console.error(res);
- }.bind(this)
- });
- // console.log("自己的");
- // this.testListView();
- } else{
- this.initData(null,callback);
- }
- },
- initData : function(data,callback){
- var list = [
- {
- name : "汉堡店",
- id : 9527,
- Price : 100,
- Fluctuate : "15%",
- TotalPossession : 3500
- },
- {
- name : "汉堡店1",
- id : 9527,
- Price : 100,
- Fluctuate : "15%",
- TotalPossession : 3500
- },
- {
- name : "汉堡店3",
- id : 9527,
- Price : 100,
- Fluctuate : "15%",
- TotalPossession : 3500
- },
- ];
- var listdata = [
- {
- id: 2,
- name: "22",
- avatarUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=607947196,2238683854&fm=26&gp=0.jpg",
- listData: list,
- openId :"oGxOa5bd61v9jI_indIdQtI2T5P8",
- // num : 0
- },
- {
- id: 6,
- name: "22",
- avatarUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=607947196,2238683854&fm=26&gp=0.jpg",
- listData: list,
- openId :"oGxOa5bjKLaCSbkPev09yVze0WSA",
- // num : 1
- },
- {
- id: 3,
- name: "22",
- avatarUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=607947196,2238683854&fm=26&gp=0.jpg",
- listData: list,
- openId :"oGxOa5bjKLaCSbkPev09yVze0WSA",
- // num : 2
- },
- {
- id: 3,
- name: "22",
- avatarUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=607947196,2238683854&fm=26&gp=0.jpg",
- listData: list,
- openId :"oGxOa5bjKLaCSbkPev09yVze0WSA",
- // num : 3
- },
- {
- id: 7,
- name: "汪汪",
- avatarUrl: "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eohXLEIOV99ic2JosrQDgIgL4cU4ZlmmvkWzGpygkNV9aEJ6nCC2mVf4kYBDHogNOHgXo2wZhv85jA/132",
- listData: list,
- openId :"oGxOa5SQ1ltBWWsVRirUvXUBGRRY",
- // num : 4
- },
- ]
- if (data!=null) {
- listdata = [];
- for (let i = 0; i < data.length; i++) {
- let friendInfo = data[i];
- // console.log("每条外面的数据",friendInfo);
- // this.createUserBlock(friendInfo,i);
- let nickName = friendInfo.nickname;
- let avatarUrl = friendInfo.avatarUrl +"?aa=a.jpg";
- let ScoreValue = friendInfo.KVDataList[0].value;
- var d = {
- }
- d.id = parseInt(ScoreValue);
- d.name = nickName;
- d.openId = friendInfo.openid;
- d.avatarUrl = avatarUrl;
- d.listData = list;
- // d.num = i;
- // console.log("每条",d);
- listdata.push(d);
- if (friendInfo.openid == userData.openId) {
- userData.httpData.data.avatarUrl = avatarUrl + "?aa=a.jpg";
- userData.httpData.data.nickName = nickName;
- userData.httpData.data.id = d.id;
- // userData.httpData.data.num = d.num;
- }
-
- }
- }
- var lists = this.getSortArr(listdata);
- // console.log("現在的數據是什麼",lists);
- // console.log("家网络数据是什么",userData.httpData.data);
- if (callback!=null) {
- callback(lists);
- }
- return lists;
- },
- getSortArr : function(arr){
- return arr.sort(this.sortNumberfunction);
- },
- addMyItem : function(){
- let node = cc.instantiate(this.prefabme);
- node.parent = this.node;
- this.nodes.push(node);
- // // getUserInfo will return the nickName, getFriendCloudStorage will return the nickname.
- let nickName = userData.httpData.data.nickName;
- let avatarUrl = userData.httpData.data.avatarUrl + "?aa=a.jpg";
- let ScoreValue = userData.httpData.data.id;
- // // console.log("ScoreValue="+ScoreValue);
- let userName = node.getChildByName('userName').getComponent(cc.Label);
- let userIcon = node.getChildByName('mask').children[0].getComponent(cc.Sprite);
- let Scorelabel = node.getChildByName('Score').getComponent(cc.Label);
- // console.log("nickName="+nickName);
- userName.string = nickName;
- Scorelabel.string = ScoreValue;
- //
- cc.loader.load({
- url: avatarUrl, type: 'png'
- }, (err, texture) => {
- if (err) console.error(err);
- userIcon.spriteFrame = new cc.SpriteFrame(texture);
- });
- },
- sortNumberfunction: function(a,b)
- {
- return b.id-a.id;
- },
- callMessage : function(){
- },
- start () {
- // wx.postMessage
- // var button = this.node.getComponent(cc.Button);
- // this.node.on('click', this.callback, this);
- //
- // let _self = this;
- //
- // wx.onMessage( data => {
- // console.log(data.message);
- // });
- // https://developers.weixin.qq.com/minigame/dev/document/open-api/data/wx.getUserInfo.html
- // wx.getUserInfo({
- // openIdList: ['selfOpenId'],
- // lang: 'zh_CN',
- // success: (res) => {
- // console.log('success', res.data);
- // let userInfo = res.data[0];
- // _self.createUserBlock(userInfo);
- // },
- // fail: (res) => {
- // reject(res);
- // }
- // });
- // https://developers.weixin.qq.com/minigame/dev/document/open-api/data/wx.getFriendCloudStorage.html
- },
- testListView : function(listdata){
- for (let i = 0; i < listdata.length; i++) {
- let friendInfo = listdata[i];
- this.createtest(friendInfo,i);
- }
- this.setOnClickItem(function (index) {
- // console.log("条目点击",listdata[index],"点了索引了",index);
- UtilsPrefabs
- .init(this.node.parent)
- .addPrefabs(UtilsPrefabs.PrefabsName[5],null,function (node) {
- this.initcreateUserInfo(listdata[index],node);
- // UtilsWX.wxgameLogin(function (res) {
- // console.log('获取玩家信息 准备跳转到下个页面',res);
- // this.showLoadDialog();
- //
- // }.bind(this))
- var PCloseButton = UtilsPrefabs.getNode("PCloseButton",node);
- UtilsPrefabs.setOff(PCloseButton);
- UtilsPrefabs.setOn(PCloseButton,function () {
- UtilsPrefabs.removePrefabs(this.node.parent,node.name);
- }.bind(this))
- }.bind(this));
- }.bind(this));
- },
- createtest (user,index) {
- let node = this.createPrefab(index);
- // getUserInfo will return the nickName, getFriendCloudStorage will return the nickname.
- let nickName = user.name;
- let avatarUrl = user.avatarUrl +"?aa=a.jpg";
- let ScoreValue = user.id;
- // console.log("ScoreValue="+ScoreValue);
- let userName = node.getChildByName('userName').getComponent(cc.Label);
- let userIcon = node.getChildByName('mask').children[0].getComponent(cc.Sprite);
- let Scorelabel = node.getChildByName('Score').getComponent(cc.Label);
- node.__itemID = index;
- if (userName != null) {
- userName.string = nickName;
- }
- if (Scorelabel != null) {
- Scorelabel.string = ScoreValue;
- }
- // console.log(nickName + '\'s info has been getten.');
- cc.loader.load({
- url: avatarUrl, type: 'png'
- }, (err, texture) => {
- if (err) console.error(err);
- userIcon.spriteFrame = new cc.SpriteFrame(texture);
- });
- //点击效果
- node.on(cc.Node.EventType.TOUCH_END, function (event) {
- // cc.log("begin spin", event.currentTarget.__itemID);
- // if (this.onClickItem != null) {
- // this.onClickItem(event.currentTarget.__itemID);
- // }
- // this.Transcend.active = true;
- // this.animCtrl.play('Transcend');
- // this.Transcendfun();
- // this.getCurrs();
- }.bind(this));
- },
- Transcendfun : function(a,b){
- // UtilsPrefabs
- // .init(this.node.parent)
- // .addPrefabs("prefab/Transcend",null,function (node) {
- //
- // // var m
- // // = cc.moveTo(3,50,50);
- // // node.runAction(m)
- //
- // // var data = [];
- // // data["openid"] = userData.openId;
- // //
- // // httpUtils.Post(httpUtils.getUserData, data, function (resData) {
- // // console.log("子域访问网络成功", resData);
- // //
- // // if (resData.code == 0) {
- // // // this.getText.string = data.data.userdata;
- // // }
- // // }.bind(this), function (resData) {
- // // console.log("子域访问网络失败", resData);
- // // }.bind(this));
- //
- //
- //
- // }.bind(this));
- // console.log("超越者a",a,"被超者b",b);
- this.Transcendnode = UtilsPrefabs.getNode("Transcend",cc.find("Canvas"));
- this.Transcendnode.active = true;
- this.animCtrl = this.Transcendnode.getComponent("cc.Animation");
- if (a !=null && b!=null) {
- this.setItemDataA(a);
- this.setItemDataB(b);
- }
- if (this.animCtrl!=null) {
- this.animCtrl.play('Transcend');
- this.animCtrl.on('finished', this.finished,this);
- }
- },
- getCurrs : function(x,lists){
- // console.log("近来数据全不全",x,lists);
- this.ranklist.active = true;
- if (x == null && lists == null) {
- this.initData(null,function (list) {
- var listdata = [];
- for (var i = 0; i <list.length ; i++) {
- if (list[i].openId ==userData.openId) {
- // console.log("我 前面",list[i-1]);
- // console.log("我 ",list[i]);
- // console.log("我 后面",list[i+1]);
- if (list[i-1]!=null) {
- list[i-1].num = i;
- }
- if (list[i]!=null) {
- list[i].num = i+1;
- }
- if (list[i+1]!=null) {
- list[i+1].num = i+2;
- }
- listdata.push(list[i-1]);
- listdata.push(list[i]);
- listdata.push(list[i+1]);
- this.setleftmidrightRankListData(listdata);
- }
- }
- }.bind(this))
- }else{
- // console.log("我在统计数组4",lists);
- var listdata = [];
- for (var i = 0; i <lists.length ; i++) {
- if (lists[i].openId ==userData.openId) {
- // console.log("我 前面",lists[i-1]);
- // console.log("我 ",lists[i]);
- // console.log("我 后面",lists[i+1]);
- if (lists[i-1]!=null) {
- lists[i-1].num = i;
- }
- if (lists[i]!=null) {
- lists[i].num = i+1;
- }
- if (lists[i+1]!=null) {
- lists[i+1].num = i+2;
- }
- listdata.push(lists[i-1]);
- listdata.push(lists[i]);
- listdata.push(lists[i+1]);
- this.setleftmidrightRankListData(listdata);
- }
- }
- }
- },
- curr : function(data){
- this.info.active = true;
- let layou = UtilsPrefabs.getNode("layou",this.info);
- let ic = layou.children[1];
- let name = layou.children[2];
- let money = layou.children[3];
- name.getComponent(cc.Label).string = data.name;
- money.getComponent(cc.Label).string = data.id;
- cc.loader.load({
- url: data.avatarUrl, type: 'png'
- }, (err, texture) => {
- if (err) console.error(err);
- ic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
- });
- setTimeout(function () {
- this.info.active = false;
- }.bind(this),4000)
- },
- setleftmidrightRankListData : function(listdata){
- // console.log("进来的数据是",listdata);
- this.closeRanklist();
- // console.log("我在统计数组5",listdata);
- this.ranklist.active = true;
- for (var i = 0; i <listdata.length ; i++) {
- if (listdata[i] !=null) {
- var bg = this.ranklist.getChildByName("bg");
- bg.children[i].active = true;
- let num = UtilsPrefabs.getNode("num",bg.children[i]);
- let ic = UtilsPrefabs.getNode("ic",bg.children[i]);
- let name = UtilsPrefabs.getNode("name",bg.children[i]);
- let money = UtilsPrefabs.getNode("money",bg.children[i]);
- num.getComponent(cc.Label).string = listdata[i].num+"名";
- name.getComponent(cc.Label).string = listdata[i].name;
- money.getComponent(cc.Label).string = listdata[i].id;
- cc.loader.load({
- url: listdata[i].avatarUrl, type: 'png'
- }, (err, texture) => {
- if (err) console.error(err);
- ic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
- });
- }
- }
- this.ranklist.getChildByName("sub").on(cc.Node.EventType.TOUCH_END, function (event) {
- this.closeRanklist();
- }.bind(this));
- setTimeout(function () {
- this.closeRanklist();
- }.bind(this),5000)
- },
- closeRanklist : function(){
- for (var i = 0; i <this.ranklist.getChildByName("bg").children.length ; i++) {
- this.ranklist.getChildByName("bg").children[i].active = false;
- }
- this.ranklist.getChildByName("sub").off(cc.Node.EventType.TOUCH_END);
- this.ranklist.active = false;
- },
- setItemDataA : function(a){
- let nickName = a.name;
- let avatarUrl = a.avatarUrl;
- let ScoreValue = a.id;
- // console.log("ScoreValue="+ScoreValue);i
- this.Transcendnode = UtilsPrefabs.getNode("Transcend",cc.find("Canvas"));
- this.Other = UtilsPrefabs.getNode("i",this.Transcendnode);
- var block = UtilsPrefabs.getNode("block",this.Other);
- let userName = block.getChildByName('userName').getComponent(cc.Label);
- let userIcon = block.getChildByName('mask').children[0].getComponent(cc.Sprite);
- let Scorelabel = block.getChildByName('Score').getComponent(cc.Label);
- userName.string = nickName;
- Scorelabel.string = ScoreValue;
- // console.log(nickName + '\'s info has been getten.');
- cc.loader.load({
- url: avatarUrl, type: 'png'
- }, (err, texture) => {
- if (err) console.error(err);
- userIcon.spriteFrame = new cc.SpriteFrame(texture);
- });
- },
- setItemDataB : function(b){
- let nickName = b.name;
- let avatarUrl = b.avatarUrl;
- let ScoreValue = b.id;
- // console.log("ScoreValue="+ScoreValue);
- this.Transcendnode = UtilsPrefabs.getNode("Transcend",cc.find("Canvas"));
- var Other = UtilsPrefabs.getNode("Other",this.Transcendnode);
- var block = UtilsPrefabs.getNode("block",Other);
- let userName = block.getChildByName('userName').getComponent(cc.Label);
- let userIcon = block.getChildByName('mask').children[0].getComponent(cc.Sprite);
- let Scorelabel = block.getChildByName('Score').getComponent(cc.Label);
- userName.string = nickName;
- Scorelabel.string = ScoreValue;
- // console.log(nickName + '\'s info has been getten.');
- cc.loader.load({
- url: avatarUrl, type: 'png'
- }, (err, texture) => {
- if (err) console.error(err);
- userIcon.spriteFrame = new cc.SpriteFrame(texture);
- });
- },
- onClickItem: function () {
- },
- setOnClickItem: function (onClickItem) {
- this.onClickItem = onClickItem;
- },
- createUserBlock (user,index) {
- let node = this.createPrefab(index);
- // getUserInfo will return the nickName, getFriendCloudStorage will return the nickname.
- let nickName = user.nickName ? user.nickName : user.nickname;
- let avatarUrl = user.avatarUrl;
- let ScoreValue = (user.KVDataList)[0].value;
- // console.log("ScoreValue="+ScoreValue);
- let userName = node.getChildByName('userName').getComponent(cc.Label);
- let userIcon = node.getChildByName('mask').children[0].getComponent(cc.Sprite);
- let Scorelabel = node.getChildByName('Score').getComponent(cc.Label);
- userName.string = nickName;
- Scorelabel.string = ScoreValue;
- // console.log(nickName + '\'s info has been getten.');
- cc.loader.load({
- url: avatarUrl, type: 'png'
- }, (err, texture) => {
- if (err) console.error(err);
- userIcon.spriteFrame = new cc.SpriteFrame(texture);
- });
- },
- createPrefab (index) {
- let node = cc.instantiate(this.prefab);
- node.parent = this.content;
- this.nodes.push(node);
- switch (index) {
- case 0:
- node.spriteFrame=this.GoldMedal;
- break;
- case 1:
- node.spriteFrame=this.SilverMedal;
- break;
- case 2:
- node.spriteFrame=this.BronzeMedal;
- break;
- }
- return node;
- },
- initcreateUserInfo : function(listdata,node){
- cc.loader.loadRes(UtilsPrefabs.PrefabsName[6], function (err, texture) {
- this.itemprefab = cc.instantiate(texture);
- for (let i = 0; i < listdata.listData.length; i++) {
- let info = listdata.listData[i];
- var StockSort = UtilsPrefabs.getNode("StockSort",node);
- var ScrollView = UtilsPrefabs.getNode("ScrollView",StockSort);
- var view = UtilsPrefabs.getNode("view",ScrollView);
- var content = UtilsPrefabs.getNode("content",view);
- this.createUserInfo(info,i,content);
- }
- }.bind(this));
- },
- createUserInfo (user,index,nodes) {
- var itemnode = cc.instantiate(this.itemprefab);
- nodes.addChild(itemnode);
- var Layout = UtilsPrefabs.getNode("Layout",itemnode);
- var Name = UtilsPrefabs.getNode("Name",Layout);
- var Code = UtilsPrefabs.getNode("Code",Layout);
- var Price = UtilsPrefabs.getNode("Price",Layout);
- var Fluctuate = UtilsPrefabs.getNode("Fluctuate",Layout);
- var TotalPossession = UtilsPrefabs.getNode("TotalPossession",Layout);
- Name.getComponent(cc.Label).string = user.name;
- Code.getComponent(cc.Label).string = user.id;
- Price.getComponent(cc.Label).string = user.Price;
- Fluctuate.getComponent(cc.Label).string = user.Fluctuate;
- TotalPossession.getComponent(cc.Label).string = user.TotalPossession;
- // console.log("来了吗",user,index,nodes);
- },
- // callback: function (button) {
- // //do whatever you want with button
- // //另外,注意这种方式注册的事件,也无法传递 customEventData
- // console.log("111111111111111111111111111111111");
- // }
- // callback: function (event, customEventData) {
- // //这里 event 是一个 Touch Event 对象,你可以通过 event.target 取到事件的发送节点
- // var node = event.target;
- // var button = node.getComponent(cc.Button);
- // //这里的 customEventData 参数就等于你之前设置的 "foobar"
- // console.log("111111111111111111111111111111111");
- // }
- });
|