mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
refactor(articles): 分类筛选复用分类文章接口
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||||
import { getCategoryList, getPostList } from '@/api/halo'
|
import { getCategoryList, getCategoryPostList, getPostList } from '@/api/halo'
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
import { useSettingStore } from '@/store/setting'
|
import { useSettingStore } from '@/store/setting'
|
||||||
import { checkAvatarUrl } from '@/utils/url'
|
import { checkAvatarUrl } from '@/utils/url'
|
||||||
@@ -60,8 +60,7 @@ const filterValues = ref<Record<string, string>>({ category: '', sort: 'default'
|
|||||||
|
|
||||||
/** 切换分类/排序:重置分页并重新查询 */
|
/** 切换分类/排序:重置分页并重新查询 */
|
||||||
function handleSelectFilter(key: 'category' | 'sort', value: string) {
|
function handleSelectFilter(key: 'category' | 'sort', value: string) {
|
||||||
if (filterValues.value[key] === value)
|
if (filterValues.value[key] === value){ return }
|
||||||
return
|
|
||||||
filterValues.value[key] = value
|
filterValues.value[key] = value
|
||||||
resetLoadMoreStatus()
|
resetLoadMoreStatus()
|
||||||
articleList.value = []
|
articleList.value = []
|
||||||
@@ -83,7 +82,7 @@ async function handleGetCategoryList() {
|
|||||||
/* ---------------- 数据加载 ---------------- */
|
/* ---------------- 数据加载 ---------------- */
|
||||||
async function handleGetArticleList() {
|
async function handleGetArticleList() {
|
||||||
if (calcAuditModeEnabled.value) {
|
if (calcAuditModeEnabled.value) {
|
||||||
// 审核模式:真实文章按 audit-data posts 过滤(数组顺序即展示顺序),一次拉取不分页
|
// 审核模式
|
||||||
resetLoadMoreStatus()
|
resetLoadMoreStatus()
|
||||||
const auditPostNames = appConfigStore.auditData.spec?.posts || []
|
const auditPostNames = appConfigStore.auditData.spec?.posts || []
|
||||||
try {
|
try {
|
||||||
@@ -120,12 +119,15 @@ async function handleGetArticleList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const category = filterValues.value.category || ''
|
||||||
const params = {
|
const params = {
|
||||||
...queryParams.value,
|
...queryParams.value,
|
||||||
category: filterValues.value.category || undefined,
|
|
||||||
sort: sortMap[filterValues.value.sort] || sortMap.default,
|
sort: sortMap[filterValues.value.sort] || sortMap.default,
|
||||||
}
|
}
|
||||||
const res = await getPostList(params)
|
// 注意:/posts 公开接口不支持 category 过滤参数,分类筛选需走分类下文章接口
|
||||||
|
const res = category
|
||||||
|
? await getCategoryPostList(category, params)
|
||||||
|
: await getPostList(params)
|
||||||
articleList.value = (loadMoreStatus.value.active
|
articleList.value = (loadMoreStatus.value.active
|
||||||
? articleList.value.concat(res.data.items)
|
? articleList.value.concat(res.data.items)
|
||||||
: res.data.items).map((item) => {
|
: res.data.items).map((item) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user