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