修改登录流程,使用公众号来获取相关资料
This commit is contained in:
parent
0f8ccea56b
commit
cceb187611
78
src/app.wpy
78
src/app.wpy
@ -30,9 +30,9 @@ export default class extends wepy.app {
|
||||
config = {
|
||||
pages: [
|
||||
'pages/index',
|
||||
'pages/login',
|
||||
'pages/game',
|
||||
'pages/gameInfo',
|
||||
'pages/login',
|
||||
'pages/search',
|
||||
'pages/jumppage',
|
||||
'pages/video',
|
||||
@ -52,7 +52,6 @@ export default class extends wepy.app {
|
||||
userInfo: null,
|
||||
gameToken: null,
|
||||
vip: false,
|
||||
jcfwLogined: false,
|
||||
}
|
||||
|
||||
constructor () {
|
||||
@ -63,7 +62,7 @@ export default class extends wepy.app {
|
||||
//全局拦截器
|
||||
this.intercept('request', {
|
||||
config(p) {
|
||||
let token = wepy.getStorageSync('game_token');
|
||||
let token = wepy.getStorageSync('mp_token');
|
||||
if (token) {
|
||||
p.header['Authorization'] = `JWT ${token}`;
|
||||
}
|
||||
@ -86,48 +85,12 @@ export default class extends wepy.app {
|
||||
}
|
||||
});
|
||||
}
|
||||
//登录流程
|
||||
login() {
|
||||
let self = this;
|
||||
return new Promise(async function(resolve, reject) {
|
||||
wepy.setStorageSync('game_token', null);
|
||||
//获取code
|
||||
try {
|
||||
let account = wepy.getStorageSync('account');
|
||||
let data = {
|
||||
account_id: account.account_id,
|
||||
session_id: account.session_id,
|
||||
open_id: account.openid,
|
||||
unionid: account.unionid
|
||||
};
|
||||
let res = await http.post('/api/emulated/user_login', data);
|
||||
wepy.setStorageSync('game_token', res.token);
|
||||
self.globalData.gameToken = res.token;
|
||||
jcEvent.emit(jcEvent.events.LOGIN_FINISHED, {});
|
||||
resolve();
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
})
|
||||
}
|
||||
onLaunch(options) {
|
||||
console.log('app.onLaunch');
|
||||
console.log(options);
|
||||
console.log('app.onLaunch', options);
|
||||
sdkManage.init(options);
|
||||
sdkManage.Login(() => {
|
||||
let account = wepy.getStorageSync('account');
|
||||
console.log('finish parse jcfw');
|
||||
console.log(account);
|
||||
this.globalData.jcfwLogined = true;
|
||||
jcEvent.emit(jcEvent.events.NEED_UPDATE_CFG, {});
|
||||
if (this.checkClientLogin()) {
|
||||
this.login();
|
||||
}
|
||||
});
|
||||
}
|
||||
onShow(options) {
|
||||
console.log('app.onShow');
|
||||
console.log(options);
|
||||
console.log('app.onShow', options);
|
||||
if (options.scene === 1038) { //从小程序返回
|
||||
jcEvent.emit(jcEvent.events.NEED_UPDATE_SCORE, {});
|
||||
let referrerInfo = options.referrerInfo;
|
||||
@ -162,23 +125,7 @@ export default class extends wepy.app {
|
||||
}
|
||||
return needAuthorize;
|
||||
}
|
||||
checkJcfwLogin() {
|
||||
return this.globalData.jcfwLogined;
|
||||
}
|
||||
checkClientLogin() {
|
||||
let self = this;
|
||||
let needLogin = true;
|
||||
if (!self.globalData.gameToken) {
|
||||
if (wepy.getStorageSync('game_token')) {
|
||||
self.globalData.gameToken = wepy.getStorageSync('game_token');
|
||||
needLogin = false;
|
||||
}
|
||||
} else {
|
||||
needLogin = false;
|
||||
}
|
||||
return needLogin;
|
||||
// return true;
|
||||
}
|
||||
|
||||
updateGlobalData(name, obj) {
|
||||
// 校验: globalData
|
||||
if (!this.globalData) return;
|
||||
@ -201,24 +148,15 @@ export default class extends wepy.app {
|
||||
getGlobalDate(name) {
|
||||
return this.globalData[name];
|
||||
}
|
||||
showAll() {
|
||||
return this.globalData.showAll;
|
||||
}
|
||||
// 判断当前用户是否是vip
|
||||
isVip() {
|
||||
return this.globalData.vip;
|
||||
}
|
||||
// 更新当前用户的vip状态
|
||||
updateVip(vip) {
|
||||
this.globalData.vip = vip;
|
||||
}
|
||||
getShareCount() {
|
||||
return sdkManage.getAchievInviteeNum();
|
||||
}
|
||||
getShareDetail() {
|
||||
return sdkManage.queryAchievementShareDetail();
|
||||
}
|
||||
updateUserInfo(allInfo) {
|
||||
return sdkManage.updateUser(allInfo);
|
||||
}
|
||||
// 日志上报
|
||||
log(eventName, param) {
|
||||
setTimeout(function() {
|
||||
sdkManage.uploadLog(eventName, param);
|
||||
|
@ -3,6 +3,7 @@ export default {
|
||||
env: env,
|
||||
// apiBase: env === 'test'? 'http://192.168.100.232' : 'https://ghost.kingsome.cn',
|
||||
apiBase: env === 'test'? 'https://ghost-test.kingsome.cn' : 'https://ghost.kingsome.cn',
|
||||
loginPage: env === 'test'? 'https://wechat-test.kingsome.cn/weapp/index.html?scope=snsapi_base' : 'https://wechat.kingsome.cn/weapp/index.html?scope=snsapi_base',
|
||||
cdnBase: 'https://h5games-al.kingsome.cn/emulator-static/',
|
||||
version: '1.0.0',
|
||||
gameTypes: ['射击','格斗', '角色扮演','动作角色扮演',
|
||||
|
@ -26,12 +26,13 @@ export default {
|
||||
},
|
||||
events: {
|
||||
BUY_GAME_SUCCESS: 'buy-game-success',
|
||||
LOGIN_FINISHED : 'login-finished',
|
||||
UPDATE_RECENT_GAMES: 'update-recent-games',
|
||||
UPDATE_GAME_STATUS: 'update-game-status',
|
||||
NEED_UPDATE_SCORE: 'need-update-score',
|
||||
NEED_UPDATE_CFG: 'need-update-cfg',
|
||||
NEED_UPDATE_UINFO: 'need-update-uinfo',
|
||||
BUY_ITEM_RESULT: 'buy-item-result',
|
||||
BUY_VIP_RESULT: 'buy-vip-result'
|
||||
BUY_VIP_RESULT: 'buy-vip-result',
|
||||
NEED_SHOW_LOGIN_PAGE: 'need_show_login_page',
|
||||
}
|
||||
}
|
||||
|
55
src/components/z-auth-view.wpy
Normal file
55
src/components/z-auth-view.wpy
Normal file
@ -0,0 +1,55 @@
|
||||
<!--授权界面-->
|
||||
<style lang="less">
|
||||
.z-auth-back {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #FFF;
|
||||
z-index: 101;
|
||||
}
|
||||
|
||||
</style>
|
||||
<template>
|
||||
<view class="z-auth-back {{ show ? '' : 'hidden'}}">
|
||||
<view class='zan-font-14 zan-c-gray-dark' style='text-align:center;margin-top:50rpx;margin-bottom:50rpx;'>
|
||||
允许微信授权后,才可以使用</view>
|
||||
<view class="zan-btns">
|
||||
<button open-type='getUserInfo' bindgetuserinfo="bindGetUserInfo" class="zan-btn zan-btn--primary">授权登录</button>
|
||||
<!--<button bindtap='navigateBack' class="zan-btn">返回首页</button>-->
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
import wepy from 'wepy'
|
||||
import jcEvent from '../common/jc-event';
|
||||
|
||||
export default class zAuthView extends wepy.component {
|
||||
props = {
|
||||
show: false
|
||||
}
|
||||
data = {
|
||||
}
|
||||
methods = {
|
||||
showView() {
|
||||
this.show = true;
|
||||
this.$apply();
|
||||
},
|
||||
bindGetUserInfo: async function(e) {
|
||||
if (e.detail.userInfo) {
|
||||
wepy.setStorageSync('userInfo', JSON.stringify(e.detail.userInfo));
|
||||
jcEvent.emit(jcEvent.events.NEED_UPDATE_UINFO, e.detail);
|
||||
this.show = false;
|
||||
this.$apply();
|
||||
} else {
|
||||
this.$invoke('zanToast', 'showZanToast', { title: '很遗憾,您拒绝了微信授权, 无法使用该小程序', timeout: 2000 })
|
||||
}
|
||||
},
|
||||
hideView() {
|
||||
this.show = false;
|
||||
this.$apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
@ -1,93 +1,100 @@
|
||||
var jcfw = require('./jcfw');
|
||||
var jcgamelog = jcfw.gamelog;
|
||||
var jcshare = jcfw.share;
|
||||
var g = require('../common/global').default;
|
||||
var ShareConfig = {
|
||||
'money':
|
||||
{
|
||||
urls: ['gift.jpg'],
|
||||
titles: ['领元宝'],
|
||||
logid: 1
|
||||
},
|
||||
'normal':
|
||||
{
|
||||
urls: ['gift.jpg'],
|
||||
titles: ['领元宝'],
|
||||
logid: 2
|
||||
}
|
||||
};
|
||||
var SDKManage = function() {
|
||||
let jcfw = require('./jcfw');
|
||||
let jcshare = jcfw.share;
|
||||
let g = require('../common/global').default;
|
||||
|
||||
let SDKManage = function() {
|
||||
this.isoffical = g.env === 'product';
|
||||
this.gameId = 8004;
|
||||
this.hasLogin = false;
|
||||
this.vision = '1.0.0';
|
||||
this.ChannelId = 6001;
|
||||
this.ChannelId = 7101;
|
||||
this.mpCode = '';
|
||||
this.init = function(launchObj) {
|
||||
this.launchObj = launchObj;
|
||||
jcfw.init(this.ChannelId, this.gameId, this.isoffical, launchObj);
|
||||
};
|
||||
this.doLogin = function(res) {
|
||||
if (this.loginStep < this.logincbarr.length) {
|
||||
this.logincbarr[this.loginStep](res);
|
||||
this.loginStep++;
|
||||
} else {
|
||||
this.loginOver();
|
||||
}
|
||||
this.updateMpCode = function(mpCode) {
|
||||
this.mpCode = mpCode;
|
||||
};
|
||||
this.checkSharedata = function() {
|
||||
var ldata;
|
||||
if (this.launchObj) {
|
||||
ldata = this.launchObj.query;
|
||||
} else {
|
||||
ldata = wx.getLaunchOptionsSync().query;
|
||||
}
|
||||
if (ldata.inviter_id) {
|
||||
jcshare.acceptAchievementInvite(ldata.inviter_id, '100', JSON.stringify([['100', 100]]));
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.doLogin();
|
||||
}, 10);
|
||||
this.login = async function(cb) {
|
||||
await this.gameLogin();
|
||||
await this.checkShareData();
|
||||
// redis 配置
|
||||
await this.getGameConfig();
|
||||
// 获取分享配置
|
||||
await this.getShareConfig();
|
||||
};
|
||||
this.gamelogin = function() {
|
||||
var token = wx.getStorageSync('token');
|
||||
var self = this;
|
||||
if (!token || token == '') {
|
||||
token = jcfw.makeUUID();
|
||||
try {
|
||||
wx.setStorageSync('token', token);
|
||||
} catch (e) {
|
||||
this.gameLogin = () => {
|
||||
let self = this;
|
||||
let loginCount = 0;
|
||||
return new Promise((resolve, reject) => {
|
||||
let login = () => {
|
||||
let token = wx.getStorageSync('token');
|
||||
if (!token) {
|
||||
token = jcfw.makeUUID();
|
||||
try {
|
||||
wx.setStorageSync('token', token);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
jcfw.loginUser((res) => {
|
||||
self.hasLogin = true;
|
||||
console.log('login success', res);
|
||||
wx.setStorageSync('account', res);
|
||||
self.account_id = res.account_id;
|
||||
resolve();
|
||||
},
|
||||
(neterr, logicerr, errmsg) => {
|
||||
if (loginCount++ < 10) {
|
||||
login();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
},
|
||||
self.mpCode
|
||||
);
|
||||
};
|
||||
login();
|
||||
});
|
||||
};
|
||||
this.checkShareData = function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let ldata;
|
||||
if (this.launchObj) {
|
||||
ldata = this.launchObj.query;
|
||||
} else {
|
||||
ldata = wx.getLaunchOptionsSync().query;
|
||||
}
|
||||
}
|
||||
jcfw.loginUser((res) => {
|
||||
self.hasLogin = true;
|
||||
console.log('login success');
|
||||
console.log(res);
|
||||
wx.setStorageSync('account', res);
|
||||
self.account_id = res.account_id;
|
||||
self.doLogin();
|
||||
},
|
||||
(neterr, logicerr, errmsg) => {
|
||||
self.gamelogin();
|
||||
if (ldata.inviter_id) {
|
||||
jcshare.acceptAchievementInvite(ldata.inviter_id, '100', JSON.stringify([['100', 100]]));
|
||||
}
|
||||
);
|
||||
};
|
||||
this.getGameConfig = function() {
|
||||
var self = this;
|
||||
var cb = function(res) {
|
||||
resolve();
|
||||
});
|
||||
|
||||
console.log('getGameConfig');
|
||||
console.log(res);
|
||||
wx.setStorageSync('cfg', res);
|
||||
setTimeout(() => {
|
||||
self.doLogin();
|
||||
}, 10);
|
||||
};
|
||||
var cbf = function(res) {
|
||||
console.log('getGameConfig fail');
|
||||
self.getGameConfig();
|
||||
};
|
||||
jcfw.cloud.initConfig(cb, cbf);
|
||||
// jcfw.getConfig('',cb,cbf);
|
||||
|
||||
};
|
||||
|
||||
this.getGameConfig = function() {
|
||||
let tryCount = 0;
|
||||
return new Promise((resolve, reject) => {
|
||||
let cb = function(res) {
|
||||
console.log('getGameConfig', res);
|
||||
wx.setStorageSync('cfg', res);
|
||||
resolve();
|
||||
};
|
||||
let cbf = function(res) {
|
||||
console.log('getGameConfig fail');
|
||||
if (tryCount++ < 10) {
|
||||
request();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
};
|
||||
let request = () => {
|
||||
jcfw.cloud.initConfig(cb, cbf);
|
||||
};
|
||||
request();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -103,56 +110,35 @@ var SDKManage = function() {
|
||||
};
|
||||
|
||||
this.getShareConfig = function() {
|
||||
var self = this;
|
||||
var cbs = function(res) {
|
||||
self.doLogin();
|
||||
console.log(res);
|
||||
if (res.length > 0) {
|
||||
let shareArr = [];
|
||||
for(let obj of res) {
|
||||
shareArr.push({
|
||||
image: obj.image,
|
||||
str: obj.str
|
||||
});
|
||||
let tryCount = 0;
|
||||
return new Promise((resolve, reject) => {
|
||||
let cbs = function(res) {
|
||||
if (res.length > 0) {
|
||||
let shareArr = [];
|
||||
for (let obj of res) {
|
||||
shareArr.push({
|
||||
image: obj.image,
|
||||
str: obj.str
|
||||
});
|
||||
}
|
||||
wx.setStorageSync('share_cfg', shareArr);
|
||||
}
|
||||
wx.setStorageSync('share_cfg', shareArr);
|
||||
}
|
||||
// for (var i = 0; i < res.length; i++) {
|
||||
// var sdt = res[i];
|
||||
// if (ShareConfig[sdt.type]) {
|
||||
// ShareConfig[sdt.type].urls = sdt.images;
|
||||
// ShareConfig[sdt.type].titles = sdt.strs;
|
||||
// }
|
||||
// }
|
||||
// if(cc.sys.platform == cc.sys.WECHAT_GAME){
|
||||
// wx.showShareMenu({
|
||||
// withShareTicket: false
|
||||
// });
|
||||
// wx.onShareAppMessage(function () {
|
||||
// return {
|
||||
// title: Main.config.shareConfig["normal"].title,
|
||||
// imageUrl: Main.config.shareConfig["normal"].url2[0]
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
console.log('getShareConfig ssssssssssssss');
|
||||
console.log(res);
|
||||
};
|
||||
var cbf = function() {
|
||||
console.log('getShareConfig fffffffffff');
|
||||
self.getShareConfig();
|
||||
};
|
||||
jcfw.cloud.getShareData(this.sex, this.province, this.city, cbs, cbf);
|
||||
};
|
||||
|
||||
this.loadData = function() {
|
||||
var self = this;
|
||||
var cb = function(v) {
|
||||
// self.playerData.load(v);
|
||||
|
||||
self.doLogin();
|
||||
};
|
||||
this.getStorage(['aaa', 'bbb'], cb);
|
||||
console.log('getShareConfig success', res);
|
||||
resolve();
|
||||
};
|
||||
let cbf = function() {
|
||||
console.log('getShareConfig fail');
|
||||
if (tryCount++ < 10) {
|
||||
request();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
};
|
||||
let request = () => {
|
||||
jcfw.cloud.getShareData(this.sex, this.province, this.city, cbs, cbf);
|
||||
};
|
||||
request();
|
||||
});
|
||||
};
|
||||
|
||||
this.getAchievInviteeNum = function() {
|
||||
@ -162,7 +148,7 @@ var SDKManage = function() {
|
||||
console.log(res);
|
||||
let invitee_nums = 0;
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
if (res[i].achievement_id == 100) {
|
||||
if (res[i].achievement_id === 100) {
|
||||
invitee_nums = res[i].invitee_num;//邀请玩家数
|
||||
break;
|
||||
}
|
||||
@ -172,29 +158,10 @@ var SDKManage = function() {
|
||||
jcshare.getAchievInviteeNum(callback, (err) => {
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
this.Login = function(cb) {
|
||||
this.loginStep = 0;
|
||||
if (cb) {
|
||||
this.loginOver = cb;
|
||||
}
|
||||
|
||||
this.logincbarr = [
|
||||
this.gamelogin.bind(this),
|
||||
// this.wxGetUseInfo.bind(this),
|
||||
this.checkSharedata.bind(this),
|
||||
// redis 配置
|
||||
this.getGameConfig.bind(this),
|
||||
// 获取分享配置
|
||||
this.getShareConfig.bind(this),
|
||||
// 获取云存档
|
||||
// this.loadData.bind(this),
|
||||
];
|
||||
this.doLogin();
|
||||
};
|
||||
this.queryAchievementShareDetail = function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const callback = function(res) {
|
||||
@ -210,16 +177,16 @@ var SDKManage = function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
jcfw.updateUser(allInfo, (obj) => {
|
||||
resolve(obj);
|
||||
},(err) => {
|
||||
}, (err) => {
|
||||
reject(err);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
};
|
||||
this.uploadLog = function(eventName, param) {
|
||||
jcfw.gamelog.logButtonClick(eventName, param);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var instance = new SDKManage();
|
||||
let instance = new SDKManage();
|
||||
module.exports = instance;
|
||||
|
@ -188,7 +188,7 @@ module.exports = {
|
||||
if(this.env){
|
||||
this.urlbd.addKV('env', this.env);
|
||||
}
|
||||
|
||||
|
||||
httpclient.httpGet(this.urlbd.baseurl, function(restext){
|
||||
var obj = httpclient.JSON_parse(restext);
|
||||
if(obj.errcode == 0){
|
||||
@ -201,7 +201,7 @@ module.exports = {
|
||||
}, function(errcode, errmsg){
|
||||
//console.log('[__getServerList]failed!'+errcode+":"+errmsg);
|
||||
failcb && failcb(errcode, 0, errmsg);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
__loginYoume(accountid, sessionid, nickname, successcb, failcb){
|
||||
@ -249,7 +249,7 @@ module.exports = {
|
||||
}, function(errcode, errmsg){
|
||||
//console.log('[__registerAccount]failed!'+errcode+":"+errmsg);
|
||||
failcb && failcb(errcode, 0, errmsg);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
__loginJCByID(account, pwd, successcb, failcb){
|
||||
@ -272,7 +272,7 @@ module.exports = {
|
||||
}, function(errcode, errmsg){
|
||||
//console.log('[__loginJC]failed!'+errcode+":"+errmsg);
|
||||
failcb && failcb(errcode, 0, errmsg);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
__loginJCBySMS(phone, smscode, successcb, failcb){
|
||||
@ -295,7 +295,7 @@ module.exports = {
|
||||
}, function(errcode, errmsg){
|
||||
//console.log('[__loginSMS]failed!'+errcode+":"+errmsg);
|
||||
failcb && failcb(errcode, 0, errmsg);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
__sendSMSCode(phone, code_type, successcb, failcb){
|
||||
@ -318,7 +318,7 @@ module.exports = {
|
||||
}, function(errcode, errmsg){
|
||||
//console.log('[__sendSMSCode]failed!'+errcode+":"+errmsg);
|
||||
failcb && failcb(errcode, 0, errmsg);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
_checkUserInfo(){
|
||||
@ -331,7 +331,7 @@ module.exports = {
|
||||
this.updateinfo(this.svuserinfo, this._activesuccess, this._activefail);
|
||||
}else{
|
||||
this._activesuccess && this._activesuccess(this.userinfo);
|
||||
}
|
||||
}
|
||||
// this._activefail && this._activefail(0, -1, 'is not weixin platform!');
|
||||
}
|
||||
}else{
|
||||
@ -339,7 +339,7 @@ module.exports = {
|
||||
this.updateinfo(this.svuserinfo, this._activesuccess, this._activefail);
|
||||
}else{
|
||||
this._activesuccess && this._activesuccess(this.userinfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -355,7 +355,9 @@ module.exports = {
|
||||
this.userinfo = {};
|
||||
}
|
||||
switch(this.channelid){
|
||||
case 6001:{
|
||||
case 6001:
|
||||
case 7101:
|
||||
{
|
||||
this.userinfo.nickname = info.nickName;
|
||||
this.userinfo.country= info.country;
|
||||
this.userinfo.province= info.province;
|
||||
@ -379,7 +381,7 @@ module.exports = {
|
||||
this.userinfo.nickname = info.nickname;
|
||||
this.userinfo.avatar_url = info.avatar;
|
||||
this.userinfo.unionid = info.unionid;
|
||||
|
||||
|
||||
//todo:
|
||||
}break;
|
||||
case 6501:{
|
||||
@ -446,7 +448,7 @@ module.exports = {
|
||||
//console.log('[country]'+svinfo.country+"|"+lcinfo.country);
|
||||
svinfo.country = lcinfo.country;
|
||||
bupdated = true;
|
||||
}
|
||||
}
|
||||
if(lcinfo.avatar_url && (svinfo.avatar_url != lcinfo.avatar_url)){
|
||||
//console.log('[avatar_url]'+svinfo.avatar_url+"|"+lcinfo.avatar_url);
|
||||
svinfo.avatar_url = lcinfo.avatar_url;
|
||||
@ -497,7 +499,7 @@ module.exports = {
|
||||
self.sessionid = obj.session_id;
|
||||
self.accountid = obj.account_id;
|
||||
self.openid = obj.openid;
|
||||
self.actived = obj.activated == true;
|
||||
self.actived = !!obj.activated;
|
||||
self.logined = true;
|
||||
self.login_costtime = nowtime - self._loginstarttime;
|
||||
self._loadServerInfo(obj);
|
||||
@ -592,13 +594,12 @@ module.exports = {
|
||||
this.updateuserinfo(userinfo);
|
||||
}break;
|
||||
|
||||
case 7001:{
|
||||
case 7001:
|
||||
case 7002:
|
||||
case 7101:{
|
||||
this.login(exparam, successcb, failcb);
|
||||
}break;
|
||||
|
||||
case 7002:{
|
||||
this.login(exparam, successcb, failcb);
|
||||
}break;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -192,4 +192,19 @@ export default class baseMixin extends wepy.mixin {
|
||||
}).exec();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取本地存储
|
||||
* @param {string} key
|
||||
* */
|
||||
$getStorage(key) {
|
||||
return wepy.getStorageSync(key);
|
||||
}
|
||||
/**
|
||||
* 保存数据至本地存储
|
||||
* @param {string} key
|
||||
* @param {object} value
|
||||
* */
|
||||
$setStorage(key, value) {
|
||||
wepy.setStorageSync(key, value);
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,5 @@ export default class cfgMixin extends wepy.mixin {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ export default class navMixin extends wepy.mixin {
|
||||
url: '/pages/gameInfo?id=' + gid
|
||||
})
|
||||
}
|
||||
// 登陆页面
|
||||
$toLogin() {
|
||||
wepy.navigateTo({
|
||||
// 跳转到登录公众号页面
|
||||
$toMpLogin() {
|
||||
wepy.redirectTo({
|
||||
url: '/pages/login'
|
||||
})
|
||||
}
|
||||
@ -45,4 +45,5 @@ export default class navMixin extends wepy.mixin {
|
||||
url: '/pages/webview?link=' + encodeURIComponent(url) + '&title='
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
22
src/mixins/webApi.js
Normal file
22
src/mixins/webApi.js
Normal file
@ -0,0 +1,22 @@
|
||||
import wepy from 'wepy'
|
||||
import http from '../utils/http';
|
||||
|
||||
export default class apiMixin extends wepy.mixin {
|
||||
async $clienLogin() {
|
||||
let wxData = await wepy.login();
|
||||
console.log('wx.login: ', wxData);
|
||||
let account = wepy.getStorageSync('account');
|
||||
let data = {
|
||||
account_id: account.account_id,
|
||||
session_id: account.session_id,
|
||||
open_id: account.openid,
|
||||
unionid: account.unionid,
|
||||
code: wxData.code,
|
||||
};
|
||||
let res = await http.post('/api/emulated/user_login', data);
|
||||
wepy.setStorageSync('mp_token', res.token);
|
||||
}
|
||||
$isClientLogin() {
|
||||
return !!wepy.getStorageSync('mp_token');
|
||||
}
|
||||
}
|
@ -173,7 +173,7 @@
|
||||
this.zActionSheetCfg.payVer = g.env === 'product' ? 'release' : 'develop';
|
||||
this.vip = this.$parent.isVip();
|
||||
this.id = decodeURIComponent(params.id);
|
||||
this.showAll = this.$parent.showAll();
|
||||
this.showAll = this.$showAll();
|
||||
console.log(this.id);
|
||||
let self = this;
|
||||
jcEvent.on(jcEvent.events.NEED_UPDATE_SCORE, this, data => {
|
||||
|
@ -50,14 +50,15 @@
|
||||
</view>
|
||||
<view class="record-list">
|
||||
<repeat for="{{records}}" item="item" >
|
||||
<recordCell :item="item" @gameCellTap.user="gameTap" :showAll.sync = 'showAll'/>
|
||||
<recordCell :item="item" @gameCellTap.user="gameTap" :showAll.sync = 'showAll'></recordCell>
|
||||
</repeat>
|
||||
<zanLoadmore :loading.sync="loading" :nodata.sync="noData" :nomore.sync="noMore" nodata_str="暂无数据"></zanLoadmore>
|
||||
</view>
|
||||
<toast/>
|
||||
<toast></toast>
|
||||
<inviteView :config.sync="inviteViewCfg" :btnList.sync="inviteBtns" @inviteBtnClick.user="inviteBtnClick" @needHideMe.user="hideInviteView"></inviteView>
|
||||
<zanToptips/>
|
||||
<zScrollText/>
|
||||
<zanToptips></zanToptips>
|
||||
<zScrollText></zScrollText>
|
||||
<zAuthView></zAuthView>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -70,6 +71,8 @@
|
||||
import zanLoadmore from '../components/zan-loadmore';
|
||||
import inviteView from '../components/invite-view';
|
||||
import zanToptips from '../components/zan-toptips'
|
||||
import zAuthView from '../components/z-auth-view';
|
||||
import zScrollText from '../components/z-scroll-text';
|
||||
import jcEvent from '../common/jc-event';
|
||||
import image from '../common/images';
|
||||
import global from '../common/global';
|
||||
@ -77,10 +80,13 @@
|
||||
import tips from '../mixins/tips';
|
||||
import cfg from '../mixins/cfg';
|
||||
import nav from '../mixins/nav';
|
||||
import zScrollText from '../components/z-scroll-text';
|
||||
import webApi from '../mixins/webApi';
|
||||
|
||||
|
||||
let sdkManage = require('../jcfw/SDKManage');
|
||||
|
||||
export default class Index extends wepy.page {
|
||||
mixins = [base, tips, cfg, nav];
|
||||
mixins = [base, tips, cfg, nav, webApi];
|
||||
config = {
|
||||
navigationBarTitleText: '游戏大厅',
|
||||
enablePullDownRefresh: true,
|
||||
@ -94,7 +100,8 @@
|
||||
zanLoadmore: zanLoadmore,
|
||||
inviteView: inviteView,
|
||||
zanToptips: zanToptips,
|
||||
zScrollText: zScrollText
|
||||
zScrollText: zScrollText,
|
||||
zAuthView: zAuthView
|
||||
};
|
||||
|
||||
data = {
|
||||
@ -137,12 +144,12 @@
|
||||
this.$toGameInfo(gid);
|
||||
},
|
||||
async toSearch() {
|
||||
this.showScollText('1. 你已成功领取100元代金券,点击查看详情,想看就看; 2. 你已成功领取100元代金券,点击查看详情,想看就看; 3. 你已成功领取100元代金券,点击查看详情,想看就看;');
|
||||
// wepy.navigateTo({
|
||||
// url: '/pages/search'
|
||||
// })
|
||||
// this.showScollText('1. 你已成功领取100元代金券,点击查看详情,想看就看; 2. 你已成功领取100元代金券,点击查看详情,想看就看; 3. 你已成功领取100元代金券,点击查看详情,想看就看;');
|
||||
wepy.navigateTo({
|
||||
url: '/pages/search'
|
||||
})
|
||||
// let movie = 'http://iqiyi.kuyun-bofang.com/20190208/eebojrT3/index.m3u8'
|
||||
// this.$toMovie(movie, '流浪地球');
|
||||
// this.$toWebView('https://wechat-test.kingsome.cn/weapp/index.html?scope=snsapi_base');
|
||||
},
|
||||
async showInviteView() {
|
||||
await this.updateInviteViewData();
|
||||
@ -198,8 +205,31 @@
|
||||
}
|
||||
|
||||
async onLoad(options) {
|
||||
console.log('index.onload, is logined: ' + this.$parent.checkJcfwLogin());
|
||||
console.log(options);
|
||||
console.log('index.onload', options);
|
||||
// begin of 登录流程
|
||||
if (options.loadtype && options.loadtype === 'login') {
|
||||
console.log('get mp code success:' + options.code);
|
||||
this.$setStorage('mp_code', options.code);
|
||||
}
|
||||
const mpCode = this.$getStorage('mp_code');
|
||||
if (!mpCode) {
|
||||
return this.$toMpLogin();
|
||||
}
|
||||
sdkManage.updateMpCode(mpCode);
|
||||
try {
|
||||
await sdkManage.login();
|
||||
console.log('finish parse jcfw');
|
||||
} catch (err) {
|
||||
console.log('sdkManage login error');
|
||||
}
|
||||
let account = this.$getStorage('account');
|
||||
console.log('account:', account);
|
||||
let mpToken = this.$getStorage('mp_token');
|
||||
if (!mpToken) {
|
||||
await this.$clienLogin();
|
||||
}
|
||||
// end of 登录流程
|
||||
|
||||
this.myGameTitles = [];
|
||||
this.recommendTitles = ['推荐'];
|
||||
this.$apply();
|
||||
@ -209,18 +239,10 @@
|
||||
withShareTicket: true
|
||||
});
|
||||
this.payVer = global.env === 'product' ? 'release' : 'develop';
|
||||
if (this.$parent.checkJcfwLogin()) {
|
||||
this.joinRoomPlay(options);
|
||||
}
|
||||
if (!this.$parent.checkClientLogin()) {
|
||||
this.getAllData();
|
||||
this.vip_params = `token=${this.$parent.getGlobalDate('gameToken')}`;
|
||||
} else {
|
||||
jcEvent.on(jcEvent.events.LOGIN_FINISHED, this, data => {
|
||||
this.getAllData()
|
||||
this.vip_params = `token=${this.$parent.getGlobalDate('gameToken')}`;
|
||||
});
|
||||
}
|
||||
this.joinRoomPlay(options);
|
||||
this.getAllData();
|
||||
this.vip_params = `token=${this.$parent.getGlobalDate('gameToken')}`;
|
||||
|
||||
jcEvent.on(jcEvent.events.UPDATE_RECENT_GAMES, this, data => {
|
||||
this.getRecentGames()
|
||||
});
|
||||
@ -240,8 +262,28 @@
|
||||
jcEvent.on(jcEvent.events.NEED_UPDATE_CFG, this, data => {
|
||||
this.showAll = this.$showAll();
|
||||
this.showBuy = !!this.vip_btn_title && this.$showBuy();
|
||||
let cfg = wepy.getStorageSync('cfg');
|
||||
if (!cfg._getrewardtype) {
|
||||
wepy.hideShareMenu();
|
||||
} else {
|
||||
wepy.showShareMenu({
|
||||
withShareTicket: true
|
||||
});
|
||||
}
|
||||
this.$apply();
|
||||
this.joinRoomPlay(options);
|
||||
})
|
||||
jcEvent.on(jcEvent.events.NEED_UPDATE_UINFO, this, async (data) => {
|
||||
let userInfo = data.userInfo;
|
||||
if (userInfo) {
|
||||
this.nickname = userInfo.nickName;
|
||||
this.avatar = userInfo.avatarUrl;
|
||||
this.$apply();
|
||||
}
|
||||
try {
|
||||
await sdkManage.updateUser(data);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
})
|
||||
jcEvent.on(jcEvent.events.BUY_VIP_RESULT, this, data => {
|
||||
if (data.success) {
|
||||
@ -256,7 +298,8 @@
|
||||
this.$parent.log('buy_vip_fail', data);
|
||||
}
|
||||
})
|
||||
|
||||
jcEvent.emit(jcEvent.events.NEED_UPDATE_CFG);
|
||||
console.log('page on load finished');
|
||||
}
|
||||
getAllData() {
|
||||
this.getRecords();
|
||||
@ -266,33 +309,25 @@
|
||||
this.getRecommendGames();
|
||||
}
|
||||
onUnload() {
|
||||
jcEvent.remove(jcEvent.events.LOGIN_FINISHED, this);
|
||||
jcEvent.remove(jcEvent.events.UPDATE_RECENT_GAMES, this);
|
||||
jcEvent.remove(jcEvent.events.UPDATE_GAME_STATUS, this);
|
||||
jcEvent.remove(jcEvent.events.NEED_UPDATE_SCORE, this);
|
||||
jcEvent.remove(jcEvent.events.NEED_UPDATE_CFG, this);
|
||||
jcEvent.remove(jcEvent.events.BUY_VIP_RESULT, this);
|
||||
jcEvent.remove(jcEvent.events.NEED_UPDATE_UINFO, this);
|
||||
}
|
||||
onShow(options) {
|
||||
console.log('onshow');
|
||||
console.log(options);
|
||||
console.log('onshow', options);
|
||||
this.$parent.log('index_onshow', {});
|
||||
let cfg = wepy.getStorageSync('cfg');
|
||||
if (!cfg._getrewardtype) {
|
||||
wepy.hideShareMenu();
|
||||
} else {
|
||||
wepy.showShareMenu({
|
||||
withShareTicket: true
|
||||
});
|
||||
if (this.$parent.checkAuthorize()) {
|
||||
this.$invoke('zAuthView', 'showView', {})
|
||||
}
|
||||
this.showAll = this.$showAll();
|
||||
let userInfo = this.$parent.getUserInfo();
|
||||
if (userInfo) {
|
||||
this.nickname = userInfo.nickName;
|
||||
this.avatar = userInfo.avatarUrl;
|
||||
this.$apply();
|
||||
}
|
||||
(this.$parent.checkAuthorize()) && this.$toLogin();
|
||||
}
|
||||
initPageParam() {
|
||||
this.all_count = 999;
|
||||
@ -476,7 +511,7 @@
|
||||
let gameList = [];
|
||||
this.inviteBtns = [];
|
||||
try {
|
||||
userList = await this.$parent.getShareDetail();
|
||||
userList = await sdkManage.queryAchievementShareDetail();
|
||||
gameList = await this.myAchieveGames();
|
||||
} catch (err) {
|
||||
console.log('error get invite user list');
|
||||
|
@ -90,6 +90,7 @@
|
||||
import cfg from '../mixins/cfg';
|
||||
import g from '../common/global';
|
||||
|
||||
let sdkManage = require('../jcfw/SDKManage');
|
||||
export default class JumpPage extends wepy.page {
|
||||
components = {};
|
||||
mixins = [base, tips, cfg];
|
||||
@ -120,7 +121,7 @@
|
||||
console.log(`aid : ${this.aid}`);
|
||||
let self = this;
|
||||
try {
|
||||
this.shareCount = await this.$parent.getShareCount();
|
||||
this.shareCount = await sdkManage.getAchievInviteeNum();
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
@ -1,65 +1,44 @@
|
||||
<style lang="less">
|
||||
.zan-btns {
|
||||
width: 95%;
|
||||
.container{
|
||||
background-color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class='zan-font-14 zan-c-gray-dark' style='text-align:center;margin-top:50rpx;margin-bottom:50rpx;'>
|
||||
允许微信授权后,才可以使用</view>
|
||||
<view class="zan-btns">
|
||||
<button open-type='getUserInfo' bindgetuserinfo="bindGetUserInfo" class="zan-btn zan-btn--primary">授权登录</button>
|
||||
<!--<button bindtap='navigateBack' class="zan-btn">返回首页</button>-->
|
||||
</view>
|
||||
<web-view src="{{link}}"></web-view>
|
||||
</view>
|
||||
<zanToast />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import wepy from 'wepy'
|
||||
import zanToast from '../components/zan-toast'
|
||||
import base from '../mixins/base';
|
||||
import tips from '../mixins/tips';
|
||||
import cfg from '../mixins/cfg';
|
||||
import global from '../common/global';
|
||||
|
||||
export default class Login extends wepy.page {
|
||||
config = {
|
||||
navigationBarTitleText: '授权'
|
||||
}
|
||||
export default class LoginPage extends wepy.page {
|
||||
components = {};
|
||||
mixins = [base, tips, cfg];
|
||||
components = {
|
||||
zanToast: zanToast
|
||||
}
|
||||
|
||||
config = {
|
||||
navigationBarBackgroundColor: '#FFF',
|
||||
navigationBarTextStyle: 'white',
|
||||
backgroundColor: '#FFF',
|
||||
backgroundColorTop: '#FFF',
|
||||
disableSwipeBack: true,
|
||||
};
|
||||
data = {
|
||||
backType: 'index'
|
||||
}
|
||||
|
||||
computed = {
|
||||
now () {
|
||||
return +new Date()
|
||||
}
|
||||
}
|
||||
|
||||
link: '',
|
||||
};
|
||||
methods = {
|
||||
bindGetUserInfo: async function(e) {
|
||||
let self = this
|
||||
if (e.detail.userInfo) {
|
||||
wepy.setStorageSync('userInfo', JSON.stringify(e.detail.userInfo));
|
||||
self.$parent.updateGlobalData('userInfo', e.detail.userInfo);
|
||||
await self.$parent.updateUserInfo(e.detail);
|
||||
wepy.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
} else {
|
||||
this.$invoke('zanToast', 'showZanToast', { title: '很遗憾,您拒绝了微信授权, 无法使用该小程序', timeout: 2000 })
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onLoad() {
|
||||
console.log('login onLoad');
|
||||
this.$parent.log('login_page_onload', {});
|
||||
onLoad(params) {
|
||||
//TODO: 根据登录状态直接跳转首页或者加载登录页
|
||||
// this.$parent.log('main_page_onload', params);
|
||||
this.link = global.loginPage;
|
||||
this.$apply();
|
||||
console.log('load page: ' + this.link);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user