fix: 修复首页文章排序问题、修复文章详情广告问题

This commit is contained in:
小莫唐尼 2024-05-25 14:58:28 +08:00
parent 0d618e21ce
commit 85f166e7d0
6 changed files with 69 additions and 100 deletions

View File

@ -31,6 +31,7 @@ http.setConfig((config) => {
} }
return config return config
}) })
setInterceptors(http) setInterceptors(http)
export { export {

View File

@ -1,8 +1,6 @@
/** /**
* 封装各种请求方式 * 封装各种请求方式
*/ */
import { import {
http http
} from '@/common/http/index.js' } from '@/common/http/index.js'

View File

@ -73,12 +73,6 @@ export default {
waveImageUrl: '', // 关于页面波浪图片 waveImageUrl: '', // 关于页面波浪图片
banner: { // 轮播图配置
type: 'article', // 轮播图数据源 list=下方配置 article=热门文章封面
list: [],
},
// 微信分享信息 // 微信分享信息
wxShareConfig: { wxShareConfig: {
title: '', // 小程序分享标题[非必填] title: '', // 小程序分享标题[非必填]

View File

@ -6,7 +6,11 @@
"type": "git", "type": "git",
"url": "git+https://gitee.com/ialley-workshop-open/uni-halo.git" "url": "git+https://gitee.com/ialley-workshop-open/uni-halo.git"
}, },
"keywords": ["uni-halo", "小莫唐尼", "巷子工坊"], "keywords": [
"uni-halo",
"小莫唐尼",
"巷子工坊"
],
"author": "巷子工坊丨小莫唐尼", "author": "巷子工坊丨小莫唐尼",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"bugs": { "bugs": {
@ -17,6 +21,7 @@
"vue-i18n": "^9.1.10" "vue-i18n": "^9.1.10"
}, },
"dependencies": { "dependencies": {
"qs": "^6.12.1",
"uni-read-pages": "^1.0.5", "uni-read-pages": "^1.0.5",
"uni-simple-router": "^2.0.8-beta.4" "uni-simple-router": "^2.0.8-beta.4"
} }

View File

@ -64,7 +64,8 @@
<view :class="globalAppSettings.layout.home"> <view :class="globalAppSettings.layout.home">
<tm-translate v-for="(article, index) in articleList" :key="index" class="ani-item" <tm-translate v-for="(article, index) in articleList" :key="index" class="ani-item"
animation-name="fadeUp" :wait="calcAniWait(index)"> animation-name="fadeUp" :wait="calcAniWait(index)">
<article-card from="home" :article="article" :post="article" @on-click="fnToArticleDetail"></article-card> <article-card from="home" :article="article" :post="article"
@on-click="fnToArticleDetail"></article-card>
</tm-translate> </tm-translate>
</view> </view>
<view class="load-text mt-12">{{ loadMoreText }}</view> <view class="load-text mt-12">{{ loadMoreText }}</view>
@ -84,6 +85,7 @@
import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue'; import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
import eSwiper from '@/components/e-swiper/e-swiper.vue'; import eSwiper from '@/components/e-swiper/e-swiper.vue';
import qs from 'qs'
export default { export default {
components: { components: {
@ -100,7 +102,8 @@
loading: 'loading', loading: 'loading',
queryParams: { queryParams: {
size: 5, size: 5,
page: 1 page: 1,
sort: ['spec.pinned,desc', 'spec.publishTime,desc']
}, },
result: {}, result: {},
isLoadMore: false, isLoadMore: false,
@ -110,7 +113,6 @@
noticeList: [], noticeList: [],
articleList: [], articleList: [],
categoryList: [], categoryList: [],
}; };
}, },
@ -180,20 +182,8 @@
// //
fnGetBanner() { fnGetBanner() {
const _this = this; const _this = this;
const _format = function(list, type) { const _format = function(list) {
console.log("list", list)
return list.map((item, index) => { return list.map((item, index) => {
switch (type) {
case 'list':
return {
id: index,
nickname: _this.bloggerInfo.nickname,
avatar: _this.bloggerInfo.avatar,
address: item.href || '',
title: item.title,
image: _this.$utils.checkImageUrl(item.thumbnail)
};
case 'article':
return { return {
mp4: '', mp4: '',
id: item.metadata.name, id: item.metadata.name,
@ -205,33 +195,26 @@
src: _this.$utils.checkImageUrl(item.spec.cover), src: _this.$utils.checkImageUrl(item.spec.cover),
image: _this.$utils.checkImageUrl(item.spec.cover) image: _this.$utils.checkImageUrl(item.spec.cover)
}; };
case 'banner':
return {
id: '',
src: item
};
}
}); });
}; };
switch (this.$haloConfig.banner.type) {
case 'list': // banner const paramsStr = qs.stringify(this.queryParams, {
this.bannerList = _format(this.$haloConfig.banner.list, 'list'); allowDots: true,
break; encodeValuesOnly: true,
case 'article': // skipNulls: true,
this.$httpApi.getPostList({ encode: true,
page: 0, arrayFormat: 'repeat'
size: 6 })
}).then(res => { uni.request({
this.bannerList = _format(res.items, 'article'); url: '/apis/api.content.halo.run/v1alpha1/posts?' + paramsStr,
if (this.bannerList.length == 0) { method: 'GET',
this.bannerList = _format(this.$haloConfig.banner.list, 'list'); params: this.queryParams,
} success: (res) => {
}); this.bannerList = _format(res.data.items);
break; },
case 'banner': // banner fail: (err) => {}
this.bannerList = _format([], 'banner'); })
break;
}
}, },
fnOnBannerChange(e) { fnOnBannerChange(e) {
this.bannerCurrent = e.current; this.bannerCurrent = e.current;
@ -256,28 +239,37 @@
} }
this.loadMoreText = '加载中...'; this.loadMoreText = '加载中...';
this.$httpApi.v2 const paramsStr = qs.stringify(this.queryParams, {
.getPostList(this.queryParams) allowDots: true,
.then(res => { encodeValuesOnly: true,
console.log('加载成功', res); skipNulls: true,
this.result.hasNext = res.hasNext; encode: true,
arrayFormat: 'repeat'
})
uni.request({
url: '/apis/api.content.halo.run/v1alpha1/posts?' + paramsStr,
method: 'GET',
params: this.queryParams,
success: (res) => {
const data = res.data;
this.result.hasNext = data.hasNext;
if (this.isLoadMore) { if (this.isLoadMore) {
this.articleList = this.articleList.concat(res.items); this.articleList = this.articleList.concat(data.items);
} else { } else {
this.articleList = res.items; this.articleList = data.items;
} }
this.loading = 'success'; this.loading = 'success';
this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~'; this.loadMoreText = data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
}) uni.hideLoading();
.catch(err => { uni.stopPullDownRefresh();
},
fail: (err) => {
this.loading = 'error'; this.loading = 'error';
this.loadMoreText = '加载失败,请下拉刷新!'; this.loadMoreText = '加载失败,请下拉刷新!';
uni.$tm.toast(err.message || '数据加载失败!'); uni.$tm.toast(err.message || '数据加载失败!');
})
.finally(() => {
uni.hideLoading();
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
}); }
})
}, },
// //

View File

@ -72,16 +72,6 @@
</view> </view>
</view> </view>
</view> </view>
<!-- 广告区域 -->
<view v-if="haloAdConfig.articleDetail.use && (haloAdConfig.unitId || haloAdConfig.adpid)"
class="ad-wrap ma-24 mb-0">
<!-- #ifdef MP-WEIXIN -->
<ad v-if="haloAdConfig.unitId" :unit-id="haloAdConfig.unitId"></ad>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<ad v-if="haloAdConfig.adpid" :adpid="haloAdConfig.adpid"></ad>
<!-- #endif -->
</view>
<!-- 内容区域 --> <!-- 内容区域 -->
<view class="content ml-24 mr-24"> <view class="content ml-24 mr-24">
<!-- markdown渲染 --> <!-- markdown渲染 -->
@ -101,19 +91,8 @@
</template> </template>
</tm-more> </tm-more>
</view> </view>
<!-- 广告区域微信/decloud申请 -->
<view v-if="haloAdConfig.articleDetail.use && (haloAdConfig.unitId || haloAdConfig.adpid)"
class="ad-wrap mt-24 mb-24 ">
<!-- #ifdef MP-WEIXIN -->
<ad v-if="haloAdConfig.unitId" :unit-id="haloAdConfig.unitId"></ad>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<ad v-if="haloAdConfig.adpid" :adpid="haloAdConfig.adpid"></ad>
<!-- #endif -->
</view>
<!-- 广告区域自定义广告位 --> <!-- 广告区域自定义广告位 -->
<view class="ad-card mt-24" v-if="haloAdConfig.articleDetail.custom.use"> <view class="ad-card mt-24" v-if="haloAdConfig.articleDetail.custom">
<text class="ad-card_tip">广告</text> <text class="ad-card_tip">广告</text>
<image class="ad-card_cover" :src="haloAdConfig.articleDetail.custom.cover" mode="scaleToFill"> <image class="ad-card_cover" :src="haloAdConfig.articleDetail.custom.cover" mode="scaleToFill">
</image> </image>