-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #467
- Loading branch information
Showing
10 changed files
with
289 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import api from './api' | ||
|
||
/** | ||
* 获取话题列表 | ||
* | ||
* @author mutoe <[email protected]> | ||
* @export | ||
* @param {Object} params | ||
* @param {string} [params.q] 搜索关键字 | ||
* @param {number} [params.limit=15] | ||
* @param {string} [params.direction=desc] | ||
* @param {number} [params.index=0] | ||
* @param {string} [params.only] 是否热门 'hot' | ||
* @returns | ||
*/ | ||
export function getTopicList (params) { | ||
const url = '/feed/topics' | ||
return api.get(url, { params, validateStatus: s => s === 200 }) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<template> | ||
<div class="p-topic-home"> | ||
<CommonHeader class="header"> | ||
<nav class="type-switch-bar"> | ||
<span :class="{active: currentType === 'hot'}" @click="currentType = 'hot'"> | ||
热门 | ||
</span> | ||
<span :class="{active: currentType === 'new'}" @click="currentType = 'new'"> | ||
最新 | ||
</span> | ||
</nav> | ||
<div slot="right" class="buttons"> | ||
<RouterLink | ||
tag="svg" | ||
append | ||
to="search" | ||
class="m-style-svg m-svg-def" | ||
> | ||
<use xlink:href="#icon-search" /> | ||
</RouterLink> | ||
<RouterLink | ||
tag="svg" | ||
append | ||
to="create" | ||
class="m-style-svg m-svg-def" | ||
> | ||
<use xlink:href="#icon-topic-create" /> | ||
</RouterLink> | ||
</div> | ||
</CommonHeader> | ||
|
||
<main> | ||
<JoLoadMore | ||
ref="loadmore" | ||
:show-bottom="currentType !== 'hot'" | ||
@onRefresh="onRefresh" | ||
@onLoadMore="onLoadMore" | ||
> | ||
<ul class="topic-list"> | ||
<TopicCard | ||
v-for="topic in list" | ||
:key="topic.id" | ||
class="topic-item" | ||
:topic="topic" | ||
/> | ||
</ul> | ||
</JoLoadMore> | ||
</main> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapActions, mapState } from 'vuex' | ||
import TopicCard from './components/TopicCard' | ||
export default { | ||
name: 'TopicHome', | ||
components: { | ||
TopicCard, | ||
}, | ||
computed: { | ||
...mapState('topic', { | ||
hot: 'hotList', | ||
new: 'newList', | ||
}), | ||
list () { | ||
let type = this.currentType | ||
return this[type] | ||
}, | ||
currentType: { | ||
get () { | ||
return this.$route.query.type || 'hot' | ||
}, | ||
set (type) { | ||
this.$router.replace({ | ||
path: this.$route.path, | ||
query: { type: type }, | ||
}) | ||
if (!this[type].length) this.onRefresh() | ||
}, | ||
}, | ||
}, | ||
created () { | ||
if (!this.$route.query.type) this.currentType = 'hot' | ||
}, | ||
methods: { | ||
...mapActions('topic', [ | ||
'fetchTopicList', | ||
]), | ||
onRefresh () { | ||
this.fetchTopicList({ type: this.currentType, reset: true }) | ||
.then(more => void this.$refs.loadmore.afterRefresh(more)) | ||
}, | ||
onLoadMore () { | ||
const lastTopic = [...this.list].pop() || {} | ||
this.fetchTopicList({ type: this.currentType, params: { index: lastTopic.id } }) | ||
.then(more => void this.$refs.loadmore.afterLoadMore(more)) | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="less" scoped> | ||
.p-topic-home { | ||
.header { | ||
overflow: initial; | ||
} | ||
.type-switch-bar { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 90px; | ||
> span { | ||
display: inline-block; | ||
height: 100%; | ||
margin: 0 20px; | ||
padding: 22px 12px; | ||
color: #999; | ||
transition: 0.3s; | ||
&.active { | ||
color: #333; | ||
border-bottom: 2px solid @primary; /* no */ | ||
} | ||
} | ||
} | ||
> main { | ||
padding: 30px; | ||
} | ||
.topic-list { | ||
display: flex; | ||
flex-direction: column; | ||
.topic-item { | ||
width: 100%; | ||
height: 300px; | ||
margin-bottom: 30px; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<template> | ||
<li class="c-topic-card" :style="{'background-image': `url(${logo})`}"> | ||
<h2 class="title">{{ topic.name }}</h2> | ||
</li> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'TopicCard', | ||
props: { | ||
topic: { type: Object, required: true }, | ||
}, | ||
computed: { | ||
logo () { | ||
const { logo = {} } = this.topic | ||
return logo.url || require('@/images/default_topic.jpg') | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="less" scoped> | ||
.c-topic-card { | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
background: no-repeat center; | ||
background-size: cover; | ||
border-radius: 10px; | ||
overflow: hidden; | ||
&::before { | ||
content: ''; | ||
position: absolute; | ||
display: block; | ||
left: 0; | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
background-color: rgba(0,0,0, .2); | ||
z-index: 0; | ||
} | ||
.title { | ||
position: relative; | ||
color: #fff; | ||
font-size: 42px; | ||
letter-spacing: 8px; | ||
z-index: 1; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import TopicHome from '@/page/topic/TopicHome.vue' | ||
|
||
export default [ | ||
{ | ||
path: '/topic', | ||
component: TopicHome, | ||
meta: { | ||
title: '话题', | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as api from '@/api/topic' | ||
import { limit } from '@/api' | ||
|
||
export const TYPES = { | ||
SAVE_TOPIC_LIST: 'SAVE_TOPIC_LIST', | ||
} | ||
|
||
const state = { | ||
hotList: [], | ||
newList: [], | ||
} | ||
|
||
const getters = {} | ||
|
||
const mutations = { | ||
[TYPES.SAVE_TOPIC_LIST] (state, payload) { | ||
let { list, type, reset = false } = payload | ||
type = type === 'hot' ? 'hotList' : 'newList' | ||
if (reset) { | ||
state[type] = list | ||
} else { | ||
state[type].push(...list) | ||
} | ||
}, | ||
} | ||
|
||
const actions = { | ||
/** | ||
* 获取动态列表 | ||
* | ||
* @author mutoe <[email protected]> | ||
* @returns {boolean} noMore? | ||
*/ | ||
async fetchTopicList ({ commit }, payload) { | ||
const { params = {}, reset, type } = payload | ||
if (type === 'hot') params.only = 'hot' | ||
const { data: list = [] } = await api.getTopicList(params) | ||
commit(TYPES.SAVE_TOPIC_LIST, { list, type, reset }) | ||
return list.length < limit | ||
}, | ||
} | ||
|
||
export default { | ||
namespaced: true, | ||
state, | ||
getters, | ||
mutations, | ||
actions, | ||
} |