将一些跳转页面的方法提取到mixins中

This commit is contained in:
zhl 2019-03-26 16:32:45 +08:00
parent 22dd391d94
commit ce128c74ba
2 changed files with 24 additions and 13 deletions

19
src/mixins/nav.js Normal file
View File

@ -0,0 +1,19 @@
import wepy from 'wepy';
export default class navMixin extends wepy.mixin {
/**
* 跳转到游戏信息页面
* @param {string} gid 游戏短id
* */
$toGameInfo(gid) {
wepy.navigateTo({
url: '/pages/gameInfo?id=' + gid
})
}
// 登陆页面
$toLogin() {
wepy.navigateTo({
url: '/pages/login'
})
}
}

View File

@ -75,9 +75,10 @@
import base from '../mixins/base'; import base from '../mixins/base';
import tips from '../mixins/tips'; import tips from '../mixins/tips';
import cfg from '../mixins/cfg'; import cfg from '../mixins/cfg';
import nav from '../mixins/nav';
export default class Index extends wepy.page { export default class Index extends wepy.page {
mixins = [base, tips, cfg]; mixins = [base, tips, cfg, nav];
config = { config = {
navigationBarTitleText: '游戏大厅', navigationBarTitleText: '游戏大厅',
enablePullDownRefresh: true, enablePullDownRefresh: true,
@ -130,9 +131,7 @@
methods = { methods = {
gameTap(gid, e) { gameTap(gid, e) {
this.$parent.log('game_tap', {gid: gid}); this.$parent.log('game_tap', {gid: gid});
wepy.navigateTo({ this.$toGameInfo(gid);
url: '/pages/gameInfo?id=' + gid
})
}, },
async toSearch() { async toSearch() {
wepy.navigateTo({ wepy.navigateTo({
@ -296,17 +295,12 @@
} }
this.showAll = this.$showAll(); this.showAll = this.$showAll();
let userInfo = this.$parent.getUserInfo(); let userInfo = this.$parent.getUserInfo();
console.log(userInfo);
if (userInfo) { if (userInfo) {
this.nickname = userInfo.nickName; this.nickname = userInfo.nickName;
this.avatar = userInfo.avatarUrl; this.avatar = userInfo.avatarUrl;
this.$apply(); this.$apply();
} }
if (this.$parent.checkAuthorize()) { (this.$parent.checkAuthorize()) && this.$toLogin();
wepy.navigateTo({
url: '/pages/login'
})
}
} }
initPageParam() { initPageParam() {
this.all_count = 999; this.all_count = 999;
@ -368,9 +362,7 @@
cancelText: '继续' cancelText: '继续'
}); });
if (modal.confirm) { if (modal.confirm) {
wepy.navigateTo({ self.$toGameInfo(res.record.gid);
url: '/pages/gameInfo?id=' + res.record.gid
})
} }
} catch (err) { } catch (err) {
console.log('error get recent games'); console.log('error get recent games');