Skip to content

Commit

Permalink
fix(SPA): 修复未读消息小红点提示
Browse files Browse the repository at this point in the history
issue #529

(cherry picked from commit 74dd0c1)

# Conflicts:
#	resources/spa/src/page/feed/FeedList.vue
  • Loading branch information
mutoe committed Mar 1, 2019
1 parent 01733c9 commit 94a7606
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 281 deletions.
4 changes: 2 additions & 2 deletions resources/spa/src/components.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** common components */
import btnSwitch from './components/common/btnSwitch' /* btnSwitch 按钮 */
import badge from './components/common/badge' /* Badge 徽标 */
import Badge from './components/common/Badge' /* Badge 徽标 */
import CommonHeader from './components/common/CommonHeader.vue' /* 通用头部 */
import fullSpin from './components/FullSpin' /* 全屏加载动画 */
import loadMore from './components/loadMore'
Expand All @@ -18,7 +18,7 @@ import FormItems from '@/components/form/formItem.js'
export default [
Avatar,
btnSwitch,
badge,
Badge,
loadMore,
fullSpin,
HeadTop,
Expand Down
2 changes: 1 addition & 1 deletion resources/spa/src/components/DiySelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@click="setCurVal(option)"
>
<template v-if="option.hasMsg">
<VBadge :dot="option.hasMsg">{{ option.label }}</VBadge>
<Badge :dot="option.hasMsg">{{ option.label }}</Badge>
</template>
<span v-else>{{ option.label }}</span>
</div>
Expand Down
13 changes: 9 additions & 4 deletions resources/spa/src/components/FootGuide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@
class="guide-item"
@click="to({name: 'MessageHome'})"
>
<VBadge :dot="hasUnread">
<Badge :dot="hasUnread">
<svg class="m-style-svg m-svg-def">
<use xlink:href="#icon-foot-message" />
</svg>
</VBadge>
</Badge>
<span>消息</span>
</section>
<section
:class="{active: isCurPath('profile')}"
class="guide-item"
@click="to('/profile')"
>
<VBadge :dot="profile">
<Badge :dot="profile">
<svg class="m-style-svg m-svg-def">
<use xlink:href="#icon-foot-profile" />
</svg>
</VBadge>
</Badge>
<span>我</span>
</section>
</footer>
Expand Down Expand Up @@ -77,6 +77,7 @@ export default {
},
mounted () {
this.$el.parentNode.style.paddingBottom = '1rem'
this.fetchUnread()
},
methods: {
to (path) {
Expand All @@ -88,6 +89,10 @@ export default {
showPostMenu () {
this.$bus.$emit('post-menu')
},
fetchUnread () {
if (this.$route.path.match(/^\/message/)) return
this.$store.dispatch('GET_NEW_UNREAD_COUNT')
},
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<slot />
<sup :class="dotClasses" />
</span>

<span
v-else
ref="badge"
Expand All @@ -27,7 +28,7 @@
const prefixCls = 'v-badge'
export default {
name: 'VBadge',
name: 'Badge',
props: {
count: { type: [Number, String], default: 0 },
dot: { type: [Boolean, Number], default: false },
Expand Down Expand Up @@ -90,18 +91,16 @@ export default {
display: flex;
justify-content: center;
align-items: center;
transform: translateX(100%);
top: -10px;
right: 0;
height: 24px;
width: 24px;
border-radius: 24px;
height: 32px;
width: 32px;
border-radius: 32px;
background: @error;
border: 1px solid transparent; /*no*/
color: #fff;
font-size: 20px;
white-space: nowrap;
transform-origin: -10% center;
// transform-origin: -10% center;
z-index: 10;
box-shadow: 0 0 0 1px @error; /*no*/
Expand All @@ -112,9 +111,8 @@ export default {
&-alone {
top: auto;
display: block;
position: relative;
transform: translateX(0);
transform: scale(0.9);
}
}
Expand Down
7 changes: 2 additions & 5 deletions resources/spa/src/page/Discover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
<use :xlink:href="`#icon-discover-${icon}`" />
</svg>
<span class="m-flex-grow1">{{ title }}</span>
<VBadge
:dot="new_tips"
class="m-entry-extra"
>
<Badge :dot="new_tips" class="m-entry-extra">
{{ tips }}
</VBadge>
</Badge>
<svg class="m-style-svg m-svg-def entry__item--append">
<use xlink:href="#icon-arrow-right" />
</svg>
Expand Down
53 changes: 21 additions & 32 deletions resources/spa/src/page/UserFans.vue
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
<template>
<div class="p-user-fans">
<nav class="m-box m-head-top m-lim-width m-pos-f m-main m-bb1" style="padding: 0 10px;">
<div class="m-box m-aln-center m-flex-shrink0 ">
<svg class="m-style-svg m-svg-def" @click="goBack">
<use xlink:href="#icon-back" />
</svg>
</div>
<ul class="m-box m-flex-grow1 m-aln-center m-justify-center m-flex-base0 m-head-nav">
<RouterLink
:to="`/users/${userId}/followers`"
tag="li"
active-class="active"
exact
replace
>
<a>粉丝</a>
</RouterLink>
<RouterLink
:to="`/users/${userId}/followings`"
tag="li"
active-class="active"
exact
replace
>
<a>关注</a>
</RouterLink>
</ul>
<div class="m-box m-justify-end" />
</nav>
<CommonHeader :pinned="true" class="header">
<nav class="type-switch-bar">
<span :class="{active: type === 'followers'}" @click="type = 'followers'">
粉丝
</span>
<span :class="{active: type === 'followings'}" @click="type = 'followings'">
关注
</span>
</nav>
</CommonHeader>

<main style="padding-top: 0.9rem">
<main>
<JoLoadMore
ref="loadmore"
:auto-load="false"
@onRefresh="onRefresh"
@onLoadMore="onLoadMore"
>
Expand Down Expand Up @@ -67,10 +50,16 @@ export default {
},
computed: {
userId () {
return ~~this.$route.params.userId
return Number(this.$route.params.userId)
},
type () {
return this.$route.params.type
type: {
get () {
const { path } = this.$route
return path.match(/\/(\w+)$/)[1]
},
set (val) {
this.$router.replace({ path: `/users/${this.userId}/${val}` })
},
},
param () {
return {
Expand Down
103 changes: 46 additions & 57 deletions resources/spa/src/page/feed/FeedList.vue
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
<template>
<div class="p-feed">
<nav class="m-box m-head-top m-lim-width m-pos-f m-main m-bb1">
<ul class="m-box m-flex-grow1 m-aln-center m-justify-center m-flex-base0 m-head-nav">
<RouterLink
:to="{ name:'feeds', query: { type: 'new' } }"
tag="li"
active-class="active"
exact
replace
>
<a>最新</a>
</RouterLink>
<RouterLink
:to="{ name:'feeds', query: { type: 'hot' } }"
tag="li"
active-class="active"
exact
replace
>
<a>热门</a>
</RouterLink>
<RouterLink
:to="{ name:'feeds', query: { type: 'follow' } }"
tag="li"
active-class="active"
exact
replace
>
<a>关注</a>
</RouterLink>
</ul>
</nav>
<CommonHeader :pinned="true" class="header">
<span slot="left" />
<nav class="type-switch-bar">
<span :class="{active: feedType === 'new'}" @click="feedType = 'new'"> 最新 </span>
<span :class="{active: feedType === 'hot'}" @click="feedType = 'hot'"> 热门 </span>
<span :class="{active: feedType === 'follow'}" @click="feedType = 'follow'"> 关注 </span>
</nav>
</CommonHeader>

<main class="p-feed-main">
<JoLoadMore
ref="loadmore"
@onRefresh="onRefresh"
@onLoadMore="onLoadMore"
>
<ul class="feed-list">
<li
v-for="(feed, index) in pinned"
v-if="feed.id"
:key="`pinned-feed-${feedType}-${feed.id}-${index}`"
>
<FeedCard :feed="feed" :pinned="true" />
</li>
<li v-for="(card, index) in feeds" :key="`feed-${feedType}-${card.id}-${index}`">
<FeedCard v-if="card.user_id" :feed="card" />
<FeedAdCard v-if="card.space_id" :ad="card" />
</li>
</ul>
</JoLoadMore>
</main>

<JoLoadMore
ref="loadmore"
Expand Down Expand Up @@ -67,37 +66,34 @@
</li>
</ul>
</JoLoadMore>

<FootGuide />
</div>
</template>

<script>
/**
* 动态列表
* @typedef {{id: number, user, ...others}} FeedDetail
*/
import { mapGetters } from 'vuex'
import { limit } from '@/api'
import { noop } from '@/util'
import FeedCard from '@/components/FeedCard/FeedCard.vue'
const feedTypesMap = ['new', 'hot', 'follow']
export default {
name: 'FeedList',
components: { FeedCard },
data () {
return {}
},
computed: {
feedType () {
return this.$route.query.type || 'hot'
},
...mapGetters('feed', ['hot', 'new', 'follow', 'pinned']),
feeds () {
return this.$store.getters[`feed/${this.feedType}`]
return this[this.feedType]
},
pinned () {
return this.$store.getters['feed/pinned']
feedType: {
get () {
return this.$route.query.type || 'hot'
},
set (val) {
const { query } = this.$route
this.$router.replace({ query: { ...query, type: val } })
},
},
after () {
const len = this.feeds.length
Expand All @@ -107,15 +103,12 @@ export default {
},
},
watch: {
feedType (val, oldVal) {
feedTypesMap.includes(val) &&
oldVal &&
feedType (val) {
if (feedTypesMap.includes(val)) {
this.$refs.loadmore.beforeRefresh()
}
},
},
created () {
this.onRefresh(noop)
},
activated () {
if (this.$route.query.refresh) {
this.$refs.loadmore.beforeRefresh()
Expand All @@ -140,11 +133,7 @@ export default {

<style lang="less" scoped>
.p-feed {
.p-feed-main {
padding-top: 90px;
}
.p-feed-list > li + li {
.feed-list > li + li {
margin-top: 20px;
}
}
Expand Down
8 changes: 2 additions & 6 deletions resources/spa/src/page/message/MessageBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<span slot="left" />
<nav class="type-switch-bar">
<span :class="{active: currentType === 'list'}" @click="currentType = 'list'">
<VBadge :dot="hasUnreadMessage">消息</VBadge>
<Badge :dot="hasUnreadMessage">消息</Badge>
</span>
<span :class="{active: currentType === 'chats'}" @click="currentType = 'chats'">
<VBadge :dot="hasUnreadChat">聊天</VBadge>
<Badge :dot="hasUnreadChat">聊天</Badge>
</span>
</nav>
</CommonHeader>
Expand Down Expand Up @@ -37,10 +37,6 @@ export default {
},
},
},
created () {
this.$store.dispatch('GET_UNREAD_COUNT')
this.$store.dispatch('GET_NEW_UNREAD_COUNT')
},
}
</script>

Expand Down
Loading

0 comments on commit 94a7606

Please sign in to comment.