123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- // Learn cc.Class:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
- window.Global = {
- //Urls
- storeUrl:'https://api-touhu.duowan.com/product/getByType.do',
- skinBuyUrl:'https://api-touhu.duowan.com/product/buy.do',
- loginUrl:'https://api-touhu.duowan.com/auth/loginByGame.do',
- addReviveBoth:'https://api-touhu.duowan.com/user/addReviveBoth.do',
- userReport:'https://api-touhu.duowan.com/user/report.do',
- //SystemInfo
- ver:100,
- os:1,
- channel:"wexin",
- //皮肤ID
- bottleSkinId:-1,
- bottleSkinIndex:0,
- arrowSkinId:-1,
- arrowSkinIndex:0,
- //userInfo
- user:null,
- // user = {
- // token:data.token,
- // uid:user.id,
- // openId:user.openId,
- // nick:userInfo.nickName,
- // avatarUrl:userInfo.avatarUrl,
- // gender:userInfo.gender,
- // gold:user.coin,
- // score:user.score,
- // revivedCount:0
- // };
- //分享过来的用户Id
- shareUid:-1,
- //
- showLoginPage:true,
- showTotalRank:false,
- showFriendRank:false,
- //处理分享加复活卡的方法
- dealAddReviveBoth(){
- if(this.shareUid!=-1){
- if(this.shareUid!=this.user.uid){
- console.log('addReviveBoth');
- wx.request({
- url:Global.addReviveBoth,
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- method:"POST",
- data:{
- token:this.user.token,
- uid:this.user.uid,
- channel:this.channel,
- os:this.os,
- ver:this.ver,
- targetUid:this.shareUid
- },
- success:(response)=>{
- if(response.data.code!=undefined&&response.data.code==0){
- this.user.revivedCount = this.user.revivedCount+1;
- // wx.showToast({title:'复活卡:'+this.user.revivedCount,icon:null})
- }
- },
- complete:()=>{
- this.shareUid=-1;
- }
- })
- }
- }
- },
- useReviveCard(){
- wx.request({
- url:'https://api-touhu.duowan.com//user/useRevive.do',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- method:"POST",
- data:{
- token:this.user.token,
- uid:this.user.uid,
- channel:this.channel,
- os:this.os,
- ver:this.ver,
- },
- success:(response)=>{
- if(response.data.code!=undefined&&response.data.code==0){
- this.user.revivedCount = this.user.revivedCount-1;
- }
- },
- complete:()=>{
- this.shareUid=-1;
- }
- })
- },
- };
- wx.onShow(res => {
- // let shareTicket = res.shareTicket;
- // console.log(shareTicket);
- // if(shareTicket!=undefined){
- // wx.showToast({
- // title:shareTicket,
- // })
- // }else{
- // wx.showToast({
- // title:'undefind',
- // })
- // }
- if (typeof wx.getUpdateManager === 'function') {
- const updateManager = wx.getUpdateManager()
-
- updateManager.onCheckForUpdate(function (res) {
- // 请求完新版本信息的回调
- console.log(res.hasUpdate)
- })
-
- updateManager.onUpdateReady(function () {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate()
- })
-
- updateManager.onUpdateFailed(function () {
- // 新的版本下载失败
- })
- }
- wx.checkSession({
- success: function(){
- //session_key 未过期,并且在本生命周期一直有效
- },
- fail: function(){
- // session_key 已经失效,需要重新执行登录流程
- Global.showLoginPage = true;
- cc.director.loadScene("mainMenu");
- }
- })
- console.log('onShow res:');
- console.log(res);
- if(res!=null&&res.query!=null&&res.query.uid!=undefined){
- console.log('onShow query uid:'+res.query.uid);
- Global.shareUid = res.query.uid;
- if(Global.user!=null){
- Global.dealAddReviveBoth();
- }
- }
- });
|