Commit 7949b7eb by lijiabin

【代码优化 11608】 refactor: 重构相关组件内容

parent a5a34e42
...@@ -6,66 +6,18 @@ ...@@ -6,66 +6,18 @@
<span class="text-lg font-semibold text-gray-800">评论 ({{ total }})</span> <span class="text-lg font-semibold text-gray-800">评论 ({{ total }})</span>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<button <button
v-for="sortOption in commentSortOptions"
:key="sortOption.value"
class="cursor-pointer px-3 py-1.5 text-sm transition-all relative" class="cursor-pointer px-3 py-1.5 text-sm transition-all relative"
@click="((searchParams.sortType = CommentSortTypeEnum.MOST_LIKE), refresh())" @click="handleChangeSort(sortOption.value)"
:class="{ :class="{
'text-indigo-600 font-medium': 'text-indigo-600 font-medium': searchParams.sortType === sortOption.value,
searchParams.sortType === CommentSortTypeEnum.MOST_LIKE, 'text-gray-600 hover:text-gray-900': searchParams.sortType !== sortOption.value,
'text-gray-600 hover:text-gray-900':
searchParams.sortType !== CommentSortTypeEnum.MOST_LIKE,
}" }"
> >
最高点赞 {{ sortOption.label }}
<span <span
v-if="searchParams.sortType === CommentSortTypeEnum.MOST_LIKE" v-if="searchParams.sortType === sortOption.value"
class="absolute bottom-0 left-0 right-0 h-0.5 bg-indigo-600"
></span>
</button>
<button
class="cursor-pointer px-3 py-1.5 text-sm transition-all relative"
@click="((searchParams.sortType = CommentSortTypeEnum.MOST_COMMENT), refresh())"
:class="{
'text-indigo-600 font-medium':
searchParams.sortType === CommentSortTypeEnum.MOST_COMMENT,
'text-gray-600 hover:text-gray-900':
searchParams.sortType !== CommentSortTypeEnum.MOST_COMMENT,
}"
>
最多评论
<span
v-if="searchParams.sortType === CommentSortTypeEnum.MOST_COMMENT"
class="absolute bottom-0 left-0 right-0 h-0.5 bg-indigo-600"
></span>
</button>
<button
class="cursor-pointer px-3 py-1.5 text-sm transition-all relative"
@click="((searchParams.sortType = CommentSortTypeEnum.EARLIEST_PUBLISH), refresh())"
:class="{
'text-indigo-600 font-medium':
searchParams.sortType === CommentSortTypeEnum.EARLIEST_PUBLISH,
'text-gray-600 hover:text-gray-900':
searchParams.sortType !== CommentSortTypeEnum.EARLIEST_PUBLISH,
}"
>
最早发布
<span
v-if="searchParams.sortType === CommentSortTypeEnum.EARLIEST_PUBLISH"
class="absolute bottom-0 left-0 right-0 h-0.5 bg-indigo-600"
></span>
</button>
<button
class="cursor-pointer px-3 py-1.5 text-sm transition-all relative"
@click="((searchParams.sortType = CommentSortTypeEnum.NEWEST_PUBLISH), refresh())"
:class="{
'text-indigo-600 font-medium':
searchParams.sortType === CommentSortTypeEnum.NEWEST_PUBLISH,
'text-gray-600 hover:text-gray-900':
searchParams.sortType !== CommentSortTypeEnum.NEWEST_PUBLISH,
}"
>
最新发布
<span
v-if="searchParams.sortType === CommentSortTypeEnum.NEWEST_PUBLISH"
class="absolute bottom-0 left-0 right-0 h-0.5 bg-indigo-600" class="absolute bottom-0 left-0 right-0 h-0.5 bg-indigo-600"
></span> ></span>
</button> </button>
...@@ -554,6 +506,19 @@ const { ...@@ -554,6 +506,19 @@ const {
}, },
immediate, immediate,
}) })
const commentSortOptions = [
{ label: '最高点赞', value: CommentSortTypeEnum.MOST_LIKE },
{ label: '最多评论', value: CommentSortTypeEnum.MOST_COMMENT },
{ label: '最早发布', value: CommentSortTypeEnum.EARLIEST_PUBLISH },
{ label: '最新发布', value: CommentSortTypeEnum.NEWEST_PUBLISH },
]
const handleChangeSort = async (sortType: CommentSortTypeEnum) => {
searchParams.value.sortType = sortType
refresh()
}
const handleCurrentChange = async (e: number) => { const handleCurrentChange = async (e: number) => {
await goToPage(e) await goToPage(e)
handleBackTop() handleBackTop()
......
...@@ -237,13 +237,15 @@ ...@@ -237,13 +237,15 @@
<el-radio-group <el-radio-group
size="small" size="small"
v-model="searchParams.sortType" v-model="searchParams.sortType"
@change="(val) => changeSortType(val as number)" @change="(val) => changeSortType(val as CommentSortTypeEnum)"
fill="#3b82f6" fill="#3b82f6"
> >
<el-radio-button label="最多点赞" :value="CommentSortTypeEnum.MOST_LIKE" /> <el-radio-button
<el-radio-button label="最多评论" :value="CommentSortTypeEnum.MOST_COMMENT" /> v-for="sortOption in answerSortOptions"
<el-radio-button label="最早发布" :value="CommentSortTypeEnum.EARLIEST_PUBLISH" /> :key="sortOption.value"
<el-radio-button label="最新发布" :value="CommentSortTypeEnum.NEWEST_PUBLISH" /> :label="sortOption.label"
:value="sortOption.value"
/>
</el-radio-group> </el-radio-group>
<!-- <span <!-- <span
@click="changeSortType(2)" @click="changeSortType(2)"
...@@ -525,7 +527,14 @@ const { ...@@ -525,7 +527,14 @@ const {
})), })),
}) })
const changeSortType = (type: number) => { const answerSortOptions = [
{ label: '最多点赞', value: CommentSortTypeEnum.MOST_LIKE },
{ label: '最多评论', value: CommentSortTypeEnum.MOST_COMMENT },
{ label: '最早发布', value: CommentSortTypeEnum.EARLIEST_PUBLISH },
{ label: '最新发布', value: CommentSortTypeEnum.NEWEST_PUBLISH },
]
const changeSortType = (type: CommentSortTypeEnum) => {
searchParams.value.sortType = type searchParams.value.sortType = type
refresh() refresh()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment