mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2025-05-19 01:50:15 +09:00
fix: 修复首页文章排序问题、修复文章详情广告问题
This commit is contained in:
parent
0d618e21ce
commit
85f166e7d0
@ -31,6 +31,7 @@ http.setConfig((config) => {
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
setInterceptors(http)
|
||||
|
||||
export {
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* 封装各种请求方式
|
||||
*/
|
||||
|
||||
|
||||
import {
|
||||
http
|
||||
} from '@/common/http/index.js'
|
||||
@ -11,7 +9,7 @@ export default {
|
||||
Get: (url, params, config = {}) => {
|
||||
return http.get(url, {
|
||||
params,
|
||||
...config
|
||||
...config
|
||||
})
|
||||
},
|
||||
Post: (url, data, config = {}) => {
|
||||
@ -26,4 +24,4 @@ export default {
|
||||
Delete: (url, data, config = {}) => {
|
||||
return http.delete(url, data, config)
|
||||
}
|
||||
}
|
||||
}
|
@ -72,13 +72,7 @@ export default {
|
||||
loadingEmptyUrl: '', // 加载图片为空地址
|
||||
|
||||
waveImageUrl: '', // 关于页面波浪图片
|
||||
|
||||
banner: { // 轮播图配置
|
||||
type: 'article', // 轮播图数据源 list=下方配置 article=热门文章封面
|
||||
list: [],
|
||||
},
|
||||
|
||||
|
||||
|
||||
// 微信分享信息
|
||||
wxShareConfig: {
|
||||
title: '', // 小程序分享标题[非必填]
|
||||
|
@ -6,7 +6,11 @@
|
||||
"type": "git",
|
||||
"url": "git+https://gitee.com/ialley-workshop-open/uni-halo.git"
|
||||
},
|
||||
"keywords": ["uni-halo", "小莫唐尼", "巷子工坊"],
|
||||
"keywords": [
|
||||
"uni-halo",
|
||||
"小莫唐尼",
|
||||
"巷子工坊"
|
||||
],
|
||||
"author": "巷子工坊丨小莫唐尼",
|
||||
"license": "AGPL-3.0",
|
||||
"bugs": {
|
||||
@ -17,6 +21,7 @@
|
||||
"vue-i18n": "^9.1.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"qs": "^6.12.1",
|
||||
"uni-read-pages": "^1.0.5",
|
||||
"uni-simple-router": "^2.0.8-beta.4"
|
||||
}
|
||||
|
@ -64,7 +64,8 @@
|
||||
<view :class="globalAppSettings.layout.home">
|
||||
<tm-translate v-for="(article, index) in articleList" :key="index" class="ani-item"
|
||||
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>
|
||||
</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 eSwiper from '@/components/e-swiper/e-swiper.vue';
|
||||
import qs from 'qs'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -100,7 +102,8 @@
|
||||
loading: 'loading',
|
||||
queryParams: {
|
||||
size: 5,
|
||||
page: 1
|
||||
page: 1,
|
||||
sort: ['spec.pinned,desc', 'spec.publishTime,desc']
|
||||
},
|
||||
result: {},
|
||||
isLoadMore: false,
|
||||
@ -110,7 +113,6 @@
|
||||
noticeList: [],
|
||||
articleList: [],
|
||||
categoryList: [],
|
||||
|
||||
};
|
||||
},
|
||||
|
||||
@ -180,58 +182,39 @@
|
||||
// 获取轮播图
|
||||
fnGetBanner() {
|
||||
const _this = this;
|
||||
const _format = function(list, type) {
|
||||
console.log("list", list)
|
||||
const _format = function(list) {
|
||||
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 {
|
||||
mp4: '',
|
||||
id: item.metadata.name,
|
||||
nickname: item.owner.displayName,
|
||||
avatar: _this.$utils.checkImageUrl(item.owner.avatar),
|
||||
address: '',
|
||||
createTime: uni.$tm.dayjs(item.spec.publishTime).fromNow(),
|
||||
title: item.spec.title,
|
||||
src: _this.$utils.checkImageUrl(item.spec.cover),
|
||||
image: _this.$utils.checkImageUrl(item.spec.cover)
|
||||
};
|
||||
case 'banner':
|
||||
return {
|
||||
id: '',
|
||||
src: item
|
||||
};
|
||||
}
|
||||
return {
|
||||
mp4: '',
|
||||
id: item.metadata.name,
|
||||
nickname: item.owner.displayName,
|
||||
avatar: _this.$utils.checkImageUrl(item.owner.avatar),
|
||||
address: '',
|
||||
createTime: uni.$tm.dayjs(item.spec.publishTime).fromNow(),
|
||||
title: item.spec.title,
|
||||
src: _this.$utils.checkImageUrl(item.spec.cover),
|
||||
image: _this.$utils.checkImageUrl(item.spec.cover)
|
||||
};
|
||||
});
|
||||
};
|
||||
switch (this.$haloConfig.banner.type) {
|
||||
case 'list': // 手动配置的banner
|
||||
this.bannerList = _format(this.$haloConfig.banner.list, 'list');
|
||||
break;
|
||||
case 'article': // 来自热门文章的封面
|
||||
this.$httpApi.getPostList({
|
||||
page: 0,
|
||||
size: 6
|
||||
}).then(res => {
|
||||
this.bannerList = _format(res.items, 'article');
|
||||
if (this.bannerList.length == 0) {
|
||||
this.bannerList = _format(this.$haloConfig.banner.list, 'list');
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'banner': // 来自后台配置的banner(暂未开放)
|
||||
this.bannerList = _format([], 'banner');
|
||||
break;
|
||||
}
|
||||
|
||||
const paramsStr = qs.stringify(this.queryParams, {
|
||||
allowDots: true,
|
||||
encodeValuesOnly: true,
|
||||
skipNulls: true,
|
||||
encode: true,
|
||||
arrayFormat: 'repeat'
|
||||
})
|
||||
uni.request({
|
||||
url: '/apis/api.content.halo.run/v1alpha1/posts?' + paramsStr,
|
||||
method: 'GET',
|
||||
params: this.queryParams,
|
||||
success: (res) => {
|
||||
this.bannerList = _format(res.data.items);
|
||||
},
|
||||
fail: (err) => {}
|
||||
})
|
||||
|
||||
},
|
||||
fnOnBannerChange(e) {
|
||||
this.bannerCurrent = e.current;
|
||||
@ -256,28 +239,37 @@
|
||||
}
|
||||
this.loadMoreText = '加载中...';
|
||||
|
||||
this.$httpApi.v2
|
||||
.getPostList(this.queryParams)
|
||||
.then(res => {
|
||||
console.log('加载成功', res);
|
||||
this.result.hasNext = res.hasNext;
|
||||
const paramsStr = qs.stringify(this.queryParams, {
|
||||
allowDots: true,
|
||||
encodeValuesOnly: true,
|
||||
skipNulls: true,
|
||||
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) {
|
||||
this.articleList = this.articleList.concat(res.items);
|
||||
this.articleList = this.articleList.concat(data.items);
|
||||
} else {
|
||||
this.articleList = res.items;
|
||||
this.articleList = data.items;
|
||||
}
|
||||
this.loading = 'success';
|
||||
this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
|
||||
})
|
||||
.catch(err => {
|
||||
this.loadMoreText = data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
|
||||
uni.hideLoading();
|
||||
uni.stopPullDownRefresh();
|
||||
},
|
||||
fail: (err) => {
|
||||
this.loading = 'error';
|
||||
this.loadMoreText = '加载失败,请下拉刷新!';
|
||||
uni.$tm.toast(err.message || '数据加载失败!');
|
||||
})
|
||||
.finally(() => {
|
||||
uni.hideLoading();
|
||||
uni.stopPullDownRefresh();
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
//跳转文章详情
|
||||
|
@ -72,16 +72,6 @@
|
||||
</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">
|
||||
<!-- markdown渲染 -->
|
||||
@ -101,19 +91,8 @@
|
||||
</template>
|
||||
</tm-more>
|
||||
</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>
|
||||
<image class="ad-card_cover" :src="haloAdConfig.articleDetail.custom.cover" mode="scaleToFill">
|
||||
</image>
|
||||
|
Loading…
Reference in New Issue
Block a user