352 lines
11 KiB
Plaintext
352 lines
11 KiB
Plaintext
<style lang="less">
|
||
@import "../style/index.wxss";
|
||
</style>
|
||
<template>
|
||
<view class="container">
|
||
<view class="top-view">
|
||
<view class="userinfo">
|
||
<view class="userinfo-user">
|
||
<image class="userinfo-avatar" src="{{avatar}}"/>
|
||
<view class="userinfo-nickname">{{ nickname }}</view>
|
||
<view class="vip-view {{showAll? '' : 'hidden'}}">
|
||
<image src="{{vipImg}}"></image>
|
||
<text class="vip-expire-txt">{{expire_str}}</text>
|
||
<navigator class="vip-btn zan-btn zan-btn--mini zan-btn--primary zan-btn--plain button-hover {{showBuy ? '' : 'hidden'}}"
|
||
target="miniProgram"
|
||
open-type="navigate"
|
||
app-id="wx815bf59d472c0a63"
|
||
path="/pages/buyvip?{{vip_params}}"
|
||
extra-data=""
|
||
version="{{payVer}}"
|
||
>
|
||
{{vip_btn_title}}</navigator>
|
||
</view>
|
||
</view>
|
||
<view class="userinfo-score {{showAll? '' : 'hidden'}}">金币: {{score}}</view>
|
||
</view>
|
||
</view>
|
||
<myGame class="{{(showAll && showMyGame && !vip)? '' : 'hidden'}}" :gameList.sync="my_game_list" title="我的游戏" @gameCellTap.user="gameTap"></myGame>
|
||
<recentGame class="{{(showAll && showRecent)? '' : 'hidden'}}" :gameList.sync="recent_game_list" title="最近在玩" @gameCellTap.user="gameTap"></recentGame>
|
||
<view class="list-title">
|
||
<view class="left"><i class="icon-bookmark"></i> 热门游戏</view>
|
||
<view class="right" @tap="toSearch"><i class="icon-search"></i> 搜索</view>
|
||
</view>
|
||
<repeat for="{{records}}" item="item" >
|
||
<recordCell :item="item" @gameCellTap.user="gameTap" :showAll.sync = 'showAll'/>
|
||
</repeat>
|
||
<zanLoadmore :loading.sync="loading" :nodata.sync="noData" :nomore.sync="noMore" nodata_str="暂无数据"></zanLoadmore>
|
||
<toast/>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import wepy from 'wepy';
|
||
import Toast from 'wepy-com-toast';
|
||
import http from '../utils/http';
|
||
import recordCell from '../components/game-cell';
|
||
import recentGame from '../components/recent-game';
|
||
import zanLoadmore from '../components/zan-loadmore';
|
||
import jcEvent from '../common/jc-event';
|
||
import image from '../common/images';
|
||
import global from '../common/global';
|
||
import base from '../mixins/base';
|
||
import tips from '../mixins/tips';
|
||
import cfg from '../mixins/cfg';
|
||
|
||
export default class Index extends wepy.page {
|
||
mixins = [base, tips, cfg];
|
||
config = {
|
||
navigationBarTitleText: '游戏大厅',
|
||
enablePullDownRefresh: true,
|
||
backgroundTextStyle: 'dark'
|
||
};
|
||
components = {
|
||
toast: Toast,
|
||
recordCell: recordCell,
|
||
recentGame: recentGame,
|
||
myGame: recentGame,
|
||
zanLoadmore: zanLoadmore
|
||
};
|
||
|
||
data = {
|
||
nickname: '加载中',
|
||
avatar: '',
|
||
score: 0,
|
||
records: [],
|
||
recent_game_list: [],
|
||
my_game_list: [],
|
||
all_count: 0,
|
||
current: 0,
|
||
loading: false,
|
||
noData: true,
|
||
noMore: false,
|
||
showAll: false,
|
||
showRecent: false,
|
||
showMyGame: false,
|
||
vip: false,
|
||
expire_str: '',
|
||
vipImg: image.vip_s,
|
||
vip_btn_title: '激活',
|
||
vip_params: '',
|
||
showBuy: false,
|
||
payVer: 'develop',
|
||
achivement: false,
|
||
};
|
||
|
||
methods = {
|
||
gameTap(gid, e) {
|
||
wepy.navigateTo({
|
||
url: '/pages/gameInfo?id=' + gid
|
||
})
|
||
},
|
||
async toSearch() {
|
||
// wepy.navigateTo({
|
||
// url: '/pages/search'
|
||
// })
|
||
let res = await this.$parent.getShareDetail();
|
||
console.log(res);
|
||
}
|
||
};
|
||
onPullDownRefresh() {
|
||
this.initPageParam();
|
||
this.getAllData();
|
||
}
|
||
|
||
onReachBottom() {
|
||
if (this.current < this.all_count) {
|
||
this.loading = true;
|
||
this.$apply();
|
||
let self = this;
|
||
setTimeout(() => {
|
||
self.getRecords();
|
||
}, 200);
|
||
}
|
||
}
|
||
|
||
async onLoad(options) {
|
||
let self = this;
|
||
wepy.showShareMenu({
|
||
withShareTicket: true
|
||
});
|
||
this.payVer = global.env === 'product' ? 'release' : 'develop';
|
||
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')}`;
|
||
});
|
||
}
|
||
jcEvent.on(jcEvent.events.UPDATE_RECENT_GAMES, this, data => {
|
||
this.getRecendGames()
|
||
});
|
||
jcEvent.on(jcEvent.events.UPDATE_GAME_STATUS, this, data => {
|
||
for(let g of self.records) {
|
||
if (g.gid == data.gid) {
|
||
g.owned = true;
|
||
break;
|
||
}
|
||
}
|
||
this.getMyGames();
|
||
self.$apply();
|
||
});
|
||
jcEvent.on(jcEvent.events.NEED_UPDATE_SCORE, this, data => {
|
||
this.getUserInfo();
|
||
})
|
||
jcEvent.on(jcEvent.events.NEED_UPDATE_CFG, this, data => {
|
||
this.showAll = this.$showAll();
|
||
this.showBuy = !!this.vip_btn_title && this.$showBuy();
|
||
this.$apply();
|
||
})
|
||
jcEvent.on(jcEvent.events.BUY_VIP_RESULT, this, data => {
|
||
if (data.success) {
|
||
this.showToast('购买成功', 2000, 'success');
|
||
this.getUserInfo();
|
||
} else {
|
||
this.showToast('购买失败', 2000);
|
||
}
|
||
})
|
||
/**
|
||
* 处理加入多人游戏的逻辑
|
||
* 如果超时5分钟,则直接提示超时
|
||
* 否则加入房间
|
||
* */
|
||
if (options.togame) {
|
||
let timestamp = options.t;
|
||
let now = Date.now();
|
||
if (now - timestamp > 60*1000*5) {
|
||
this.showToast('加入房间失败', 2000);
|
||
} else {
|
||
let cfg = wepy.getStorageSync('cfg');
|
||
let fcUrl = cfg.fcurl;
|
||
let roomId = options.roomId;
|
||
let gid = options.gid;
|
||
let link = `${fcUrl}?id=${gid}&roomId=${roomId}`;
|
||
wepy.navigateTo({
|
||
url: '/pages/game?link=' + encodeURIComponent(link) + '&gid=' + gid +'&name=multiplayer'
|
||
});
|
||
}
|
||
}
|
||
}
|
||
getAllData() {
|
||
this.getRecords();
|
||
this.getRecendGames();
|
||
this.getUserInfo();
|
||
this.getMyGames();
|
||
}
|
||
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);
|
||
}
|
||
onShow() {
|
||
let cfg = wepy.getStorageSync('cfg');
|
||
if (!cfg._getrewardtype) {
|
||
wepy.hideShareMenu();
|
||
} else {
|
||
wepy.showShareMenu({
|
||
withShareTicket: true
|
||
});
|
||
}
|
||
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'
|
||
})
|
||
}
|
||
}
|
||
initPageParam() {
|
||
this.all_count = 999;
|
||
this.current = 0;
|
||
this.records = [];
|
||
}
|
||
async getRecendGames() {
|
||
try {
|
||
let res = await http.post('/api/emulated/recent_games');
|
||
this.recent_game_list = res.records;
|
||
this.showRecent = this.recent_game_list.length > 0;
|
||
this.$apply();
|
||
} catch (err) {
|
||
console.log('error get recent games');
|
||
}
|
||
}
|
||
async getMyGames() {
|
||
try {
|
||
let res = await http.post('/api/emulated/my_games');
|
||
this.my_game_list = res.records;
|
||
this.showMyGame = this.my_game_list.length > 0;
|
||
this.$apply();
|
||
wepy.setStorageSync('game_count', this.my_game_list.length);
|
||
} catch (err) {
|
||
console.log('error get recent games');
|
||
}
|
||
}
|
||
async getUserInfo() {
|
||
try {
|
||
let res = await http.post('/api/emulated/user_info', {type: 'all'});
|
||
this.debugLog(res);
|
||
if (res.userInfo) {
|
||
let user = res.userInfo;
|
||
this.score = user.score;
|
||
this.vip = user.vip;
|
||
this.$parent.updateVip(user.vip);
|
||
if (user.vip) {
|
||
this.vipImg = image.vip;
|
||
if (user.vip_expire_day === 99999) {
|
||
this.expire_str = '(永久)';
|
||
this.vip_btn_title = '';
|
||
} else if (user.vip_expire_day === 0){
|
||
this.expire_str = '(不到1天)';
|
||
this.vip_btn_title = '续费';
|
||
} else {
|
||
this.expire_str = `(${user.vip_expire_day}天)`;
|
||
this.vip_btn_title = '续费';
|
||
}
|
||
|
||
} else {
|
||
this.vip_btn_title = '激活';
|
||
this.vipImg = image.vip_s;
|
||
}
|
||
this.showBuy = !!this.vip_btn_title && this.$showBuy();
|
||
}
|
||
|
||
this.$apply();
|
||
} catch (err) {
|
||
console.log('error get user info');
|
||
}
|
||
}
|
||
async getRecords() {
|
||
let self = this;
|
||
try {
|
||
let res = await http.post(`/api/emulated/games`, {start: self.current});
|
||
wepy.stopPullDownRefresh();
|
||
if (res.errcode === 0) {
|
||
if (res.count > 0) {
|
||
self.all_count = res.count;
|
||
}
|
||
self.current += 10;
|
||
for (let obj of res.records) {
|
||
(obj.open) && (obj.owned = true);
|
||
if (obj.images && obj.images.length > 0) {
|
||
obj.icon = obj.images[0];
|
||
}
|
||
self.records.push(obj);
|
||
}
|
||
self.loading = false;
|
||
self.noMore = (self.records.length >= self.all_count);
|
||
self.noData = (self.records.length === 0);
|
||
self.$apply();
|
||
} else {
|
||
this.debugLog('get game data error');
|
||
self.loading = false
|
||
}
|
||
} catch (error) {
|
||
console.log(error);
|
||
self.loading = false
|
||
}
|
||
this.$apply();
|
||
this.noData = false;
|
||
this.noMore = true;
|
||
}
|
||
onShareAppMessage() {
|
||
let account = wepy.getStorageSync('account');
|
||
let shareObj = this.$getShareCfg();
|
||
let shareUrl = `/pages/index?isShare=1&inviter_id=${account.account_id}`;
|
||
if (this.achivement) {
|
||
shareUrl += '&shareType=achivement'
|
||
}
|
||
return {
|
||
title: shareObj.str,
|
||
path: shareUrl,
|
||
imageUrl: shareObj.image,
|
||
success: function (res) {
|
||
wepy.getShareInfo({
|
||
shareTicket: res.shareTickets[0]
|
||
})
|
||
.then(res => {
|
||
this.debugLog(res);
|
||
})
|
||
.catch(err => {
|
||
console.log(err)
|
||
})
|
||
},
|
||
fail: function (res) {
|
||
// 分享失败
|
||
console.log(res)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</script>
|