void): voi..."/>
您好,登錄后才能下訂單哦!
①,加入按鈕(接口)
/**
* 按鈕
*/
interface UserInfoButton {
destroy(): void;
hide(): void;
onTap(callback: (res) => void): void;
offTap(callback: () => void): void;
show(): void;
}
如下圖所示:
②,加入createUserInfoButton方法 , 在 wx模塊中:
/**
* 獲取用戶的當(dāng)前設(shè)置。
*/
export function getSetting(object: _getSettingObject): void;
①,構(gòu)建按鈕攻玩家點擊授權(quán)
private createUser(): UserInfoButton{
let button:UserInfoButton=wx.createUserInfoButton({type:'text',text:'',style:{width:640,height:1136,backgroundColr:'#ff0000',color:'#ff0000',textAlign:'center',fontSize:16,borderRadius:4}});
button.onTap((res)=>{
this.wxAuthorization( button );
})
return button;
}
②,授權(quán)方法
private wxAuthorization : Function = ( $button? : UserInfoButton ) : void => {
wx.getSetting({
success:(result: _getSettingSuccessObject) : void =>{
if( result.authSetting['scope.userInfo'] ){//已經(jīng)授權(quán)了
if( $button ){
$button.hide();
$button.offTap;
}
//獲取微信玩家信息
wx.getUserInfo({
withCredentials: true,
lang: "zh_CN",
success: (result: _getUserInfoSuccessObject) : void => {
console.log(`玩家信息 : `);
console.log( result.userInfo );
model.WC_UserInfo_VO.Instance.UserInfo = result;
//創(chuàng)建轉(zhuǎn)發(fā)功能(!important)
const $general : small_lib.IAopConfigFile<config.Type_File_Config> = config.AOPConfigManager.Instance.getFile( config.Type_File_Config._General_);
const $shere_conf : NodeList|Node = $general.getInfoByFlag( "share" );
this.showShareMenu($general.getValue<string>( $shere_conf , "title" ) , $general.getValue<string>( $shere_conf , "png" ));
this._isWait_count ++;
this.enter2Game();
},
fail: () : void => {
console.warn(`微信獲取玩家信息失敗!(授權(quán))`);
},
complete: () : void => {
}
});
}else{//授權(quán)失敗
this.createUser();
}
},
fail: () : void => {
this.createUser();
},
complete: () : void =>{
}
});
}
①,轉(zhuǎn)發(fā)功能
/**
* 創(chuàng)建轉(zhuǎn)發(fā)功能
*/
private showShareMenu : Function = ( $title : string , $img : string ) : void => {
console.log(`分享參數(shù) : ${$title} / ${$img}`);
let $self = this;
wx.showShareMenu({
withShareTicket: true,
success: () => {
console.log(`顯示分享按鈕成功!`);
wx.onShareAppMessage(() : any => {
return {
title: $title,
imageUrl: $img
}
});
},
fail: () : void => {
console.warn(`顯示分享按鈕失敗!`);
},
complete: () : void => {},
});
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。