Skip to content

Commit

Permalink
在各个页面加入加载超时提示
Browse files Browse the repository at this point in the history
  • Loading branch information
IwYvI authored and IwYvI committed Sep 4, 2018
1 parent 3d815f4 commit 4360a8b
Show file tree
Hide file tree
Showing 13 changed files with 1,211 additions and 1,163 deletions.
2,252 changes: 1,126 additions & 1,126 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "splatoon2-schedules-weapp",
"version": "0.5.6",
"version": "0.5.7",
"description": "乌贼日历",
"main": "dist/app.js",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions src/components/loader.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<view></view>
<view></view>
</view>
<view wx:if="{{timeout}}" class="loader-hint splatoon">请求超时,请下拉页面刷新</view>
</view>
</template>
<script>
Expand All @@ -14,16 +15,28 @@ export default class Loader extends wepy.component {
inline: {
type: Boolean,
default: false
},
timeout: {
type: Boolean,
default: false
}
}

onLoad() {}
}
</script>
<style>
.loader-hint {
font-size: 28rpx;
line-height: 1em;
margin-top: 20rpx;
color: #ffffff;
}
.block-loader {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 20rpx;
margin-bottom: 20rpx;
Expand All @@ -37,6 +50,7 @@ export default class Loader extends wepy.component {
}
.la-ball-spin-rotate {
display: block;
margin-bottom: 25rpx;
font-size: 0;
color: #fff;
}
Expand Down
22 changes: 20 additions & 2 deletions src/components/timer.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import wepy from 'wepy'

export default class Timer extends wepy.component {
data = {
timer: null
timer: null,
delay: 1000 * 60, // timer间隔
timeoutTimer: null, // 用于告诉页面是否到超时时间
timeoutDelay: 5000
}

events = {
Expand All @@ -18,11 +21,24 @@ export default class Timer extends wepy.component {
}
}

startTimeoutTimer() {
this.timeoutTimer = setTimeout(() => {
this.$emit('timer-timeout')
}, this.timeoutDelay)
}

stopTimeoutTimer() {
if (this.timeoutTimer) {
clearTimeout(this.timeoutTimer)
this.timeoutTimer = null
}
}

startTimer() {
if (!this.timer) {
this.timer = setInterval(() => {
this.$emit('timer-update')
}, 1000 * 60)
}, this.delay)
}
}

Expand All @@ -35,10 +51,12 @@ export default class Timer extends wepy.component {

onLoad() {
this.startTimer()
this.startTimeoutTimer()
}

onUnload() {
this.stopTimer()
this.stopTimeoutTimer()
}
}
</script>
22 changes: 11 additions & 11 deletions src/pages/index.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,10 @@
<text class="splatoon">海産招募中...</text>
</navigator>
</view>
<loader wx:if="{{!isSplatfestLoaded}}"></loader>
<loader wx:if="{{!isSplatfestLoaded}}" :timeout.sync="timeout"></loader>
<view wx:else class="index-wrap">
<view wx:if="{{isLatestSplatfestStart && !isLatestSplatfestEnd}}" class="container index-container">
<splatfest-schedule-card class="index-schedule-card" mode="splatfest" :list.sync="regularList" :splatfest.sync="latestSplatfest" />
<!-- <view class="index-schedule-hint">
<view class="index-region-picker">
<text>当前祭典区域:</text>
<region-picker readonly="true"></region-picker>
</view>
<view>可以在「更多」-「祭典」中修改</view>
</view> -->
</view>
<view wx:else class="container index-container">
<regular-card class="index-schedule-card" mode="regular" :list.sync="regularList" />
Expand All @@ -89,7 +82,7 @@
</view>
</view>
</view>
<timer @timer-update.user="timerUpdate"></timer>
<timer @timer-update.user="timerUpdate" @timer-timeout.user="timerTimeout"></timer>
</view>
</template>

Expand Down Expand Up @@ -151,7 +144,8 @@ export default class Index extends wepy.page {
isSplatfestLoaded: false,
latestSplatfest: {},
isLatestSplatfestEnd: true, // 最近的祭典是否已经结束
isLatestSplatfestStart: false // 最近的祭典是否开始
isLatestSplatfestStart: false, // 最近的祭典是否开始
timeout: false
}

watch = {
Expand All @@ -171,6 +165,10 @@ export default class Index extends wepy.page {
methods = {
timerUpdate() {
this.startUpdate()
},
timerTimeout() {
this.timeout = true
this.$apply()
}
}

Expand Down Expand Up @@ -207,7 +205,9 @@ export default class Index extends wepy.page {
this.isLatestSplatfestStart = false
}
}
this.isSplatfestLoaded = true
if (this.splatfest.updatedAt) {
this.isSplatfestLoaded = true // 确保祭奠成功加载
}
this.$apply()
this.updateLogo()
}
Expand Down
11 changes: 8 additions & 3 deletions src/pages/salmonrun.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<image class="salmonrun-logo" mode="widthFix" src="../assets/img/salmon-run.png"></image>
<text class="splatoon">Salmon Run</text>
</view>
<loader wx:if="{{listWithDetail.length===0}}"></loader>
<loader wx:if="{{listWithDetail.length===0}}" :timeout.sync="timeout"></loader>
<view wx:else>
<view class="salmonrun-block">
<view class="salmonrun-block-status splatoon">{{firstStatus}}</view>
Expand Down Expand Up @@ -65,7 +65,7 @@
</view>
</view>
</view>
<timer @timer-update.user="timerUpdate"></timer>
<timer @timer-update.user="timerUpdate" @timer-timeout.user="timerTimeout"></timer>
</view>
</template>
<script>
Expand Down Expand Up @@ -117,7 +117,8 @@ export default class Salmonrun extends wepy.page {

data = {
listWithDetail: [],
restList: []
restList: [],
timeout: true
}

watch = {
Expand All @@ -129,6 +130,10 @@ export default class Salmonrun extends wepy.page {
methods = {
timerUpdate() {
this.startUpdateSalmonrun()
},
timerTimeout() {
this.timeout = true
this.$apply()
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/pages/schedule.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</view>
<icon class="schedule-close-icon" @tap="backToIndex" type="clear" size="24" color="#ffffff" />
</view>
<loader wx:if="{{list.length===0 || !isSplatfestLoaded}}"></loader>
<loader wx:if="{{list.length===0 || !isSplatfestLoaded}}" :timeout.sync="timeout"></loader>
<view wx:else>
<view wx:if="{{computedMode==='splatfest' && latestSplatfest}}" class="schedule-card-block schedule-card-splatfest-block">
<view class="schedule-card-block-images schedule-card-splatfest-block-images">
Expand Down Expand Up @@ -47,7 +47,7 @@
</view>
</view>
</view>
<timer @timer-update.user="timerUpdate"></timer>
<timer @timer-update.user="timerUpdate" @timer-timeout.user="timerTimeout"></timer>
</view>
</template>
<style lang="less">
Expand Down Expand Up @@ -249,7 +249,8 @@ export default class Schedule extends wepy.page {
isSplatfestLoaded: false,
latestSplatfest: {},
isLatestSplatfestEnd: true, // 最近的祭典是否已经结束
isLatestSplatfestStart: false // 最近的祭典是否开始
isLatestSplatfestStart: false, // 最近的祭典是否开始
timeout: false
}

watch = {
Expand Down Expand Up @@ -306,11 +307,16 @@ export default class Schedule extends wepy.page {
},
timerUpdate() {
this.startUpdate()
},
timerTimeout() {
this.timeout = true
this.$apply()
}
}

loadSchedule() {
const mode = this.computedMode === 'splatfest' ? 'regular' : this.computedMode
const mode =
this.computedMode === 'splatfest' ? 'regular' : this.computedMode
this.list = this.schedule[mode].list
this.$apply()
wx.stopPullDownRefresh()
Expand Down
12 changes: 8 additions & 4 deletions src/pages/shop.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<text>小程序只展示当前SplatNet中的装备</text>
<text>购买需要在APP里进行操作</text>
</view>
<loader wx:if="{{list.length===0}}"></loader>
<loader wx:if="{{list.length===0}}" :timeout.sync="timeout"></loader>
<view wx:else>
<view class="shop-item" wx:for="{{listWithComputedTime}}" wx:key="end_time">
<view class="item-title">
Expand Down Expand Up @@ -68,7 +68,7 @@
</view>
</view>
</view>
<timer @timer-update.user="timerUpdate"></timer>
<timer @timer-update.user="timerUpdate" @timer-timeout.user="timerTimeout"></timer>
</view>
</template>
<script>
Expand Down Expand Up @@ -111,7 +111,8 @@ export default class Shop extends wepy.page {

data = {
list: [],
listWithComputedTime: []
listWithComputedTime: [],
timeout: false
}

watch = {
Expand All @@ -123,6 +124,10 @@ export default class Shop extends wepy.page {
methods = {
timerUpdate() {
this.startUpdateShop()
},
timerTimeout() {
this.timeout = true
this.$apply()
}
}

Expand Down Expand Up @@ -280,7 +285,6 @@ export default class Shop extends wepy.page {
align-items: center;
justify-content: center;
-webkit-mask-size: 1000rpx 1600rpx;
mask-size: 1000rpx 1600rpx;
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/pages/splatfest.wpy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<region-picker></region-picker>
</view>
</view>
<loader wx:if="{{list.length===0}}"></loader>
<loader wx:if="{{list.length===0}}" :timeout.sync="timeout"></loader>
<view wx:else class="splatfest-lists">
<repeat for="{{list}}" key="index">
<view class="splatfest-card-wrap" @tap="showModal" data-item="{{item}}">
Expand All @@ -26,7 +26,7 @@
<view wx:if="{{isModalShow}}" class="splatfest-modal" @touchmove.stop="disablePageScroll" @tap.stop="closeModal">
<splatfest-result-card :detail.sync="modalItem"></splatfest-result-card>
</view>
<timer @timer-update.user="timerUpdate"></timer>
<timer @timer-update.user="timerUpdate" @timer-timeout.user="timerTimeout"></timer>
</view>
</template>
<script>
Expand Down Expand Up @@ -82,7 +82,8 @@ export default class Splatfest extends wepy.page {
data = {
list: [],
isModalShow: false,
modalItem: {}
modalItem: {},
timeout: false
}

methods = {
Expand All @@ -94,7 +95,11 @@ export default class Splatfest extends wepy.page {
timerUpdate() {
this.startUpdate()
},
disablePageScroll() {},
timerTimeout() {
this.timeout = true
this.$apply()
},
disablePageScroll() {}, // 使用空方法来阻止滚动
showModal($event) {
if (!this.isModalShow) {
const targetItem = $event.currentTarget.dataset.item
Expand Down
3 changes: 1 addition & 2 deletions src/store/reducers/salmonrun.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const defaultState = {
},
updatedAt: 0, // 记录上次加载时间
activedAt: 0,
isError: false,
reloadCount: 0
isError: false
}

export default handleActions({
Expand Down
3 changes: 1 addition & 2 deletions src/store/reducers/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const defaultState = {
},
updatedAt: 0, // 记录上次加载时间
activedAt: 0, // 记录上次调用时间
isError: false,
reloadCount: 0
isError: false
}

export default handleActions({
Expand Down
3 changes: 1 addition & 2 deletions src/store/reducers/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const defaultState = {
},
updatedAt: 0, // 记录上次加载时间
activedAt: 0,
isError: false,
reloadCount: 0
isError: false
}

export default handleActions({
Expand Down
3 changes: 1 addition & 2 deletions src/store/reducers/splatfest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const defaultState = {
},
updatedAt: 0,
activedAt: 0,
isError: false,
reloadCount: 0
isError: false
}

export default handleActions({
Expand Down

0 comments on commit 4360a8b

Please sign in to comment.