Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
refactor: question card 抽出
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Jul 4, 2018
1 parent b3eb5de commit 863d632
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 108 deletions.
2 changes: 1 addition & 1 deletion src/page/question/QuestionBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import SwitchBar from "./components/SwitchBar.vue";
export default {
name: "PageQuestions",
name: "Questions",
components: {
SwitchBar
}
Expand Down
6 changes: 3 additions & 3 deletions src/page/question/QuestionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:class="classNamebuilder('main-loading')">
<icon-loading :class="classNamebuilder('main-loading_icon')" />
</div>
<question-list-item
<question-card
v-for="question in questions"
:key="question.id"
:question="question" />
Expand All @@ -64,13 +64,13 @@
<script>
import message from "plus-message-bundle";
import Loading from "@/icons/Loading.vue";
import QuestionListItem from "./QuestionListItem.vue";
import QuestionCard from "./components/QuestionCard.vue";
import { list } from "@/api/question/questions";
export default {
name: "QuestionList",
components: {
QuestionListItem,
QuestionCard,
IconLoading: Loading
},
Expand Down
6 changes: 3 additions & 3 deletions src/page/question/TopicDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
:class="[classNameBuilder('questions')]"
:on-refresh="handleRefresh"
:on-load-more="handleLoadQuestions" >
<question-list-item
<question-card
v-for="question in questions"
:key="question.id"
:question="question" />
Expand All @@ -117,14 +117,14 @@

<script>
import UserAvatar from "./components/UserAvatar.vue";
import QuestionListItem from "./QuestionListItem.vue";
import QuestionCard from "./components/QuestionCard.vue";
import { show, questions, follow, unfollow } from "@/api/question/topics";
export default {
name: "TopicDetail",
components: {
UserAvatar,
QuestionListItem
QuestionCard
},
data: () => ({
topic: {},
Expand Down
108 changes: 9 additions & 99 deletions src/page/question/TopicList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,26 @@
ref="LoadQuestionTopicsContainer"
:on-refresh="handleRefresh"
:on-load-more="handleLoadMore" >
<div
<topic-card
v-for="topic in topics"
:key="topic.id"
class="module-questions-topics-item">
<router-link
:src="topic.avatar"
:to="`/question-topics/${topic.id}`"
tag="img"
class="topic-image" />
<router-link
:to="`/question-topics/${topic.id}`"
tag="a"
class="title">
<span class="topic">{{ topic.name }}</span>
<span class="label">
<span>{{ topic.follows_count }}</span>&nbsp;关注
·
<span>{{ topic.questions_count }}</span>&nbsp;问题
</span>
</router-link>
<button
v-if="topic.has_follow || type === 'follow'"
class="follow active"
@click="handleUnfollow(topic)"><span>✓</span>已关注</button>
<button
v-else
class="follow"
@click="handleFollow(topic)"><span>+</span>关注</button>
</div>
:topic="topic"
:type="type"
@follow="handleFollow"
@unfollow="handleUnfollow"/>
</load-more>
</div>
</template>

<script>
import TopicCard from "./components/TopicCard.vue";
import { all, followTopics, follow, unfollow } from "@/api/question/topics";
export default {
name: "TopicList",
components: {
TopicCard
},
data: () => ({
topics: []
}),
Expand Down Expand Up @@ -220,77 +202,5 @@ export default {
color: #333;
}
}
&-item {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 175px;
padding: 28px;
background-color: #fff;
border-bottom: solid 1px #d7d8d8;
.topic-image {
width: 120px;
height: 120px;
margin-right: 28px;
border: none;
background-color: #d7d8d8;
}
.title {
flex-grow: 1;
display: inline-flex;
align-items: flex-start;
flex-direction: column;
height: 120px;
justify-content: center;
.topic {
margin-top: 17px;
font-size: 32px;
font-weight: normal;
font-stretch: normal;
line-height: 0px;
height: 30px;
letter-spacing: 0px;
color: #333;
}
.label {
margin-top: 19px;
height: 26px;
font-size: 28px;
font-weight: normal;
font-stretch: normal;
line-height: 0px;
letter-spacing: 0px;
color: #666;
> span {
color: #59b6d7;
}
}
}
.follow {
// width: 126px;
height: 50px;
background-color: #fff;
border-radius: 8px;
border: solid 2px #59b6d7;
color: #59b6d7;
font-size: 26px;
font-weight: normal;
font-stretch: normal;
line-height: 5px;
letter-spacing: 0px;
outline: none;
> span {
width: 20px;
height: 20px;
font-size: 36px;
margin-right: 2px;
}
&.active {
color: #ccc;
border: solid 2px #ccc;
}
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
</template>

<script>
import QuestionListAnswerCard from "./QuestionListAnswerCard";
import QuestionListAnswerCard from "../QuestionListAnswerCard";
import { syntaxTextAndImage } from "@/util/markdown";
export default {
name: "QuestionListItem",
name: "QuestionCard",
components: {
QuestionListAnswerCard
},
Expand Down
126 changes: 126 additions & 0 deletions src/page/question/components/TopicCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<template>
<div class="topic-card">
<router-link
:src="topic.avatar"
:to="`/question-topics/${topic.id}`"
tag="img"
class="topic-image" />
<router-link
:to="`/question-topics/${topic.id}`"
tag="a"
class="title">
<span class="topic">{{ topic.name }}</span>
<span class="label">
<span>{{ topic.follows_count }}</span>&nbsp;关注
·
<span>{{ topic.questions_count }}</span>&nbsp;问题
</span>
</router-link>
<button
v-if="topic.has_follow || type === 'follow'"
class="follow active"
@click="handleUnfollow(topic)"><span>✓</span>已关注</button>
<button
v-else
class="follow"
@click="handleFollow(topic)"><span>+</span>关注</button>
</div>
</template>

<script>
export default {
props: {
topic: { type: Object, require: true, default() {} },
type: { type: String, default: "hot" }
},
methods: {
handleUnfollow(topic) {
this.$emit("unfollow", { topic });
},
handleFollow(topic) {
this.$emit("follow", { topic });
}
}
};
</script>

<style lang="less" scoped>
.topic-card {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 175px;
padding: 28px;
background-color: #fff;
border-bottom: solid 1px #d7d8d8;
.topic-image {
width: 120px;
height: 120px;
margin-right: 28px;
border: none;
background-color: #d7d8d8;
}
.title {
flex-grow: 1;
display: inline-flex;
align-items: flex-start;
flex-direction: column;
height: 120px;
justify-content: center;
.topic {
margin-top: 17px;
font-size: 32px;
font-weight: normal;
font-stretch: normal;
line-height: 0px;
height: 30px;
letter-spacing: 0px;
color: #333;
}
.label {
margin-top: 19px;
height: 26px;
font-size: 28px;
font-weight: normal;
font-stretch: normal;
line-height: 0px;
letter-spacing: 0px;
color: #666;
> span {
color: #59b6d7;
}
}
}
.follow {
// width: 126px;
height: 50px;
background-color: #fff;
border-radius: 8px;
border: solid 2px #59b6d7;
color: #59b6d7;
font-size: 26px;
font-weight: normal;
font-stretch: normal;
line-height: 5px;
letter-spacing: 0px;
outline: none;
> span {
width: 20px;
height: 20px;
font-size: 36px;
margin-right: 2px;
}
&.active {
color: #ccc;
border: solid 2px #ccc;
}
}
}
</style>

0 comments on commit 863d632

Please sign in to comment.