①,加入按钮(接口)
/**
* 按钮
*/
interface UserInfoButton {
destroy(): void;
hide(): void;
onTap(callback: (res) => void): void;
offTap(callback: () => void): void;
show(): void;
}
如下图所示:
②,加入createUserInfoButton方法 , 在 wx模块中:
/**
* 获取用户的当前设置。
*/
export function getSetting(object: _getSettingObject): void;
①,构建按钮攻玩家点击授权
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;
}
②,授权方法
private wxAuthorization : Function = ( $button? : UserInfoButton ) : void => {
wx.getSetting({
success:(result: _getSettingSuccessObject) : void =>{
if( result.authSetting['scope.userInfo'] ){//已经授权了
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;
//创建转发功能(!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(`微信获取玩家信息失败!(授权)`);
},
complete: () : void => {
}
});
}else{//授权失败
this.createUser();
}
},
fail: () : void => {
this.createUser();
},
complete: () : void =>{
}
});
}
①,转发功能
/**
* 创建转发功能
*/
private showShareMenu : Function = ( $title : string , $img : string ) : void => {
console.log(`分享参数 : ${$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 => {},
});
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。