1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-06-11 04:39:35 +08:00

新增:文章详情原文链接、访问密码功能

This commit is contained in:
小莫唐尼
2023-06-08 20:48:15 +08:00
parent d701867b83
commit 21d723d260
5 changed files with 1273 additions and 1139 deletions
+19
View File
@@ -153,3 +153,22 @@
transform: scale(1);
}
}
/* 文本省略样式 开始 */
.text-sub-one {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 多行文本省略 */
@for $i from 2 through 30 {
.text-sub-more-#{$i} {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: $i;
overflow: hidden;
}
}
/* 文本省略样式 结束 */
+23 -14
View File
@@ -3,22 +3,14 @@
<view v-if="loadStatus == 'loading'" class="img-loading" :style="[imgStyle, loadStyle]">
<!-- <text class="img-load-icon iconfont icon-loading"></text>
<text class="img-load-text">{{ loadText }}</text> -->
<image :src="loadingImgSrc" :style="[imgStyle]" mode="aspectFit"></image>
<image :src="loadingImgSrc" :style="[loadingImgStyle]" mode="aspectFit"></image>
</view>
<view v-if="loadStatus == 'error'" class="img-error" :style="[imgStyle, loadErrStyle]">
<text class="img-err-icon iconfont icon-exclamation-circle"></text>
<text class="img-load-text">{{ loadErrText }}</text>
<!-- <text class="img-err-icon iconfont icon-exclamation-circle"></text>
<text class="img-load-text">{{ loadErrText }}</text> -->
<image class="img-error-img" :src="loadingErrorImageSrc" mode="scaleToFill"></image>
</view>
<image
v-show="loadStatus == 'success'"
:src="src"
@load="fnOnLoad"
@error="fnOnError"
:lazy-load="lazyLoad"
:style="[imgStyle]"
:mode="mode"
@click="$emit('on-click', url)"
></image>
<image v-show="loadStatus == 'success'" :src="src" @load="fnOnLoad" @error="fnOnError" :lazy-load="lazyLoad" :style="[imgStyle]" :mode="mode" @click="$emit('on-click', url)"></image>
</view>
</template>
@@ -91,6 +83,9 @@ export default {
data() {
return {
imgStyle: {},
loadingImgStyle: {
width: '120rpx',
},
src: '', // 图片地址
loadStatus: 'loading'
};
@@ -98,6 +93,9 @@ export default {
computed: {
loadingImgSrc() {
return getApp().globalData.loadingGifUrl;
},
loadingErrorImageSrc() {
return getApp().globalData.loadingErrUrl
}
},
watch: {
@@ -137,7 +135,7 @@ export default {
fnOnLoad() {
this.loadStatus = 'success';
},
fnOnError() {
fnOnError(e) {
this.loadStatus = 'error';
}
}
@@ -149,6 +147,7 @@ export default {
width: 100%;
height: 100%;
}
.img-loading,
.img-error {
display: flex;
@@ -158,21 +157,31 @@ export default {
box-sizing: border-box;
background-color: #f2f2f2;
}
.img-load-icon {
font-size: 36rpx;
animation: xhRote 0.8s infinite linear;
}
.img-load-text {
font-size: 28rpx;
margin-top: 8rpx;
color: inherit;
}
.img-error {
font-size: 28rpx;
&-img {
width: 100%;
border-radius: 12rpx;
}
}
.img-err-icon {
font-size: 36rpx;
}
@keyframes xhRote {
0% {
transform: rotate(0deg);
+1 -1
View File
@@ -550,7 +550,7 @@
},
"tabBar": {
"backgroundColor": "#fff",
"borderStyle": "#fff",
"borderStyle": "white",
"color": "#303133",
"selectedColor": "#03a9f4",
"list": [{
+211 -105
View File
@@ -46,12 +46,7 @@
<text class="text-weight-b">分类</text>
<text v-if="result.categories.length == 0" class="category-tag is-empty">未选择分类</text>
<block v-else>
<text
class="category-tag"
v-for="(item, index) in result.categories"
:key="index"
@click="fnToCate(item)"
>
<text class="category-tag" v-for="(item, index) in result.categories" :key="index" @click="fnToCate(item)">
{{ item.name }}
</text>
</block>
@@ -60,23 +55,21 @@
<text class="text-weight-b">标签</text>
<text v-if="result.tags.length == 0" class="category-tag is-empty">未选择标签</text>
<block v-else>
<text
class="category-tag"
:style="{ backgroundColor: item.color }"
v-for="(item, index) in result.tags"
:key="index"
@click="fnToTag(item)"
>
<text class="category-tag" :style="{ backgroundColor: item.color }" v-for="(item, index) in result.tags" :key="index" @click="fnToTag(item)">
{{ item.name }}
</text>
</block>
</view>
<view v-if="originalURL" class="mt-18 category-type original-url">
<view class="original-url_left text-weight-b">原文</view>
<view class="original-url_right text-grey">
<text class="original-url_right__link" @click.stop="fnToOriginal(originalURL)">{{ originalURL }}</text>
<text class="original-url_right__btn" @click.stop="fnToOriginal(originalURL)">阅读原文<text class="iconfont icon-angle-right ml-5 text-size-s"></text> </text>
</view>
</view>
</view>
<!-- 广告区域 -->
<view
v-if="haloAdConfig.articleDetail.use && (haloAdConfig.unitId || haloAdConfig.adpid)"
class="ad-wrap ma-24 mb-0"
>
<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 -->
@@ -87,27 +80,19 @@
<!-- 内容区域 -->
<view class="content ml-24 mr-24">
<!-- markdown渲染 -->
<mp-html
class="evan-markdown"
lazy-load
:domain="markdownConfig.domain"
:loading-img="markdownConfig.loadingGif"
:scroll-table="true"
:selectable="true"
:tag-style="markdownConfig.tagStyle"
:container-style="markdownConfig.containStyle"
:content="result.content || result.formatContent"
:markdown="true"
:showLineNumber="true"
:showLanguageName="true"
:copyByLongPress="true"
/>
<view class="markdown-wrap">
<tm-more :disabled="true" :maxHeight="1500" :isRemovBar="true" :open="showValidVisitMore" @click="fnOnShowValidVisitMore">
<mp-html class="evan-markdown" lazy-load :domain="markdownConfig.domain" :loading-img="markdownConfig.loadingGif" :scroll-table="true" :selectable="true" :tag-style="markdownConfig.tagStyle" :container-style="markdownConfig.containStyle" :content="result.content || result.formatContent" :markdown="true" :showLineNumber="true" :showLanguageName="true" :copyByLongPress="true" />
<template v-slot:more="{ data }">
<view class="">
<text class="text-blue text-size-m text-weight-b">文章部分内容已加密点击解锁</text>
<text class="text-blue iconfont icon-lock-fill text-size-s ml-5"></text>
</view>
</template>
</tm-more>
</view>
<!-- 广告区域微信/decloud申请 -->
<view
v-if="haloAdConfig.articleDetail.use && (haloAdConfig.unitId || haloAdConfig.adpid)"
class="ad-wrap mt-24 mb-24 "
>
<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 -->
@@ -117,21 +102,13 @@
</view>
<!-- 广告区域自定义广告位 -->
<view class="ad-card" v-if="haloAdConfig.articleDetail.custom.use">
<view class="ad-card mt-24" v-if="haloAdConfig.articleDetail.custom.use">
<text class="ad-card_tip">广告</text>
<image
class="ad-card_cover"
:src="haloAdConfig.articleDetail.custom.cover"
mode="scaleToFill"
></image>
<image class="ad-card_cover" :src="haloAdConfig.articleDetail.custom.cover" mode="scaleToFill"></image>
<view class="ad-card_info">
<view class="ad-card_info-title">{{ haloAdConfig.articleDetail.custom.title }}</view>
<view class="ad-card_info-desc">{{ haloAdConfig.articleDetail.custom.content }}</view>
<view
v-if="haloAdConfig.articleDetail.custom.url"
class="ad-card_info-link"
@click="fnToWebview(haloAdConfig.articleDetail.custom)"
>
<view v-if="haloAdConfig.articleDetail.custom.url" class="ad-card_info-link" @click="fnToWebview(haloAdConfig.articleDetail.custom)">
立即查看
</view>
</view>
@@ -140,9 +117,7 @@
<!-- 版权声明 -->
<view v-if="copyright.use" class="copyright-wrap bg-white mt-24 pa-24 round-4">
<view class="copyright-title text-weight-b">版权声明</view>
<view
class="copyright-content mt-12 grey-lighten-5 text-grey-darken-2 round-4 pt-12 pb-12 pl-24 pr-24 "
>
<view class="copyright-content mt-12 grey-lighten-5 text-grey-darken-2 round-4 pt-12 pb-12 pl-24 pr-24 ">
<view v-if="copyright.author" class="copyright-text text-size-s ">
版权归属{{ copyright.author }}
</view>
@@ -157,32 +132,15 @@
<!-- 评论展示区域 -->
<view class="comment-wrap bg-white mt-24 pa-24 round-4">
<commentList
:disallowComment="result.disallowComment"
:postId="result.id"
:post="result"
@on-comment-detail="fnOnShowCommentDetail"
@on-loaded="fnOnCommentLoaded"
></commentList>
<commentList :disallowComment="result.disallowComment" :postId="result.id" :post="result" @on-comment-detail="fnOnShowCommentDetail" @on-loaded="fnOnCommentLoaded"></commentList>
</view>
</view>
<!-- 弹幕效果 -->
<barrage ref="barrage" :maxTop="240" :type="globalAppSettings.barrage.type"></barrage>
<!-- 返回顶部 -->
<tm-flotbutton
:offset="[16, 80]"
icon="icon-angle-up"
color="bg-gradient-light-blue-accent"
@click="fnToTopPage()"
></tm-flotbutton>
<tm-flotbutton
:actions="btnOption.actions"
actions-pos="left"
:show-text="true"
color="bg-gradient-orange-accent"
@change="fnOnFlotButtonChange"
></tm-flotbutton>
<tm-flotbutton :offset="[16, 80]" icon="icon-angle-up" color="bg-gradient-light-blue-accent" @click="fnToTopPage()"></tm-flotbutton>
<tm-flotbutton :actions="btnOption.actions" actions-pos="left" :show-text="true" color="bg-gradient-orange-accent" @change="fnOnFlotButtonChange"></tm-flotbutton>
</block>
<!-- 评论详情 -->
@@ -190,13 +148,7 @@
<view class="pa-24">
<view class="poup-head pb-24">
<view class="poup-title text-align-center text-size-g text-weight-b mb-32">评论详情</view>
<comment-item
:useContentBg="false"
:useActions="false"
:isChild="false"
:comment="commentDetail.comment"
:postId="result.id"
></comment-item>
<comment-item :useContentBg="false" :useActions="false" :isChild="false" :comment="commentDetail.comment" :postId="result.id"></comment-item>
</view>
<scroll-view :scroll-y="true" class="poup-body">
@@ -207,12 +159,7 @@
</view>
<view v-else-if="commentDetail.loading == 'error'" class="error">
<tm-empty icon="icon-wind-cry" label="加载失败">
<tm-button
theme="bg-gradient-light-blue-accent"
size="m"
v-if="!disallowComment"
@click="fnGetChildComments()"
>
<tm-button theme="bg-gradient-light-blue-accent" size="m" v-if="!disallowComment" @click="fnGetChildComments()">
刷新试试
</tm-button>
</tm-empty>
@@ -224,16 +171,7 @@
</view>
<block v-else>
<comment-item
v-for="(comment, index) in commentDetail.list"
:useContentBg="false"
:useSolid="false"
:useActions="false"
:key="index"
:isChild="false"
:comment="comment"
:postId="result.id"
></comment-item>
<comment-item v-for="(comment, index) in commentDetail.list" :useContentBg="false" :useSolid="false" :useActions="false" :key="index" :isChild="false" :comment="comment" :postId="result.id"></comment-item>
</block>
</block>
</scroll-view>
@@ -263,6 +201,10 @@
</block>
</view>
</tm-poup>
<!-- 密码访问解密弹窗 -->
<tm-dialog :disabled="true" :input-val.sync="validVisitModal.value" title="验证提示" confirmText="立即验证" :showCancel="validVisitModal.useCancel" model="confirm" v-model="validVisitModal.show" content="博主设置了需要密码才能查看该文章内容,请输入文章密码进行验证" theme="split" confirmColor="blue shadow-blue-0" @cancel="fnOnValidVisitCancel" @confirm="fnOnValidVisitConfirm"></tm-dialog>
</view>
</template>
@@ -274,6 +216,8 @@ import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
import tmDialog from '@/tm-vuetify/components/tm-dialog/tm-dialog.vue';
import tmMore from '@/tm-vuetify/components/tm-more/tm-more.vue';
import mpHtml from '@/components/mp-html/components/mp-html/mp-html.vue';
import commentList from '@/components/comment-list/comment-list.vue';
@@ -290,6 +234,8 @@ export default {
tmFlotbutton,
tmButton,
tmEmpty,
tmDialog,
tmMore,
mpHtml,
commentList,
commentItem,
@@ -302,8 +248,7 @@ export default {
loading: 'loading',
markdownConfig: MarkdownConfig,
btnOption: {
actions: [
{
actions: [{
icon: 'icon-like',
color: 'bg-gradient-orange-accent'
},
@@ -334,7 +279,16 @@ export default {
showCanvas: false,
loading: true,
res: null
}
},
metas: [], // 自定义元数据
// 文章加密(弹窗输入密码解密)
validVisitModal: {
show: false,
useCancel: false,
value: undefined
},
showValidVisitMore: true,
};
},
computed: {
@@ -354,6 +308,48 @@ export default {
let blogger = this.$tm.vx.getters().getBlogger;
blogger.avatar = this.$utils.checkAvatarUrl(blogger.avatar, true);
return blogger;
},
// 原文链接:个人资质=可以打开公众号文章;非个人:任意链接地址(需在小程序后台配置)
originalURL() {
const target = this.metas.find(x => x.key == 'unihalo_originalURL');
if (!target) return '';
return target.value || '';
},
// 是否使用文章密码功能,如果值不为空,则优先于 useVisitMoreunihalo_useVisitPwd
useVisitPwd() {
const target = this.metas.find(x => x.key == 'unihalo_useVisitPwd');
if (!target) return false;
return target.value || false;
},
// 是否启用查看完整文章的功能的密码:unihalo_useVisitMorePwd
useVisitMorePwd() {
const target = this.metas.find(x => x.key == 'unihalo_useVisitMorePwd');
if (!target) return false;
return target.value || false;
},
// 当前是使用哪一种类型的密码验证 0=不使用任何 1=默认弹窗密码 2=查看部分内容
useVisitMode() {
if (this.useVisitPwd != false) {
return 1
}
if (this.useVisitMorePwd != false) {
return 2
}
return 0
}
},
watch: {
useVisitPwd(val) {
if (val) {
this.validVisitModal.show = true
}
},
useVisitMode(val) {
if (val != 2) {
this.showValidVisitMore = true
} else {
this.showValidVisitMore = false
}
}
},
onLoad(e) {
@@ -375,7 +371,9 @@ export default {
this.$httpApi
.getArticleDetail(this.queryParams.articleId)
.then(res => {
if (res.status == 200) {
this.result = res.data;
this.metas = res.data.metas;
this.fnSetPageTitle('文章详情');
this.loading = 'success';
this.fnSetWxShareConfig({
@@ -386,6 +384,9 @@ export default {
copyLink: this.$haloConfig.apiUrl,
query: {}
});
} else {
this.loading = 'error';
}
})
.catch(err => {
this.loading = 'error';
@@ -599,7 +600,6 @@ export default {
});
this.drawDashedLine(this.$refs.rCanvas.ctx, 14, 356, 332, 0.5, [8, 5, 5, 5], '#999');
// 小程序信息
await this.$refs.rCanvas
.drawImage({
@@ -748,7 +748,7 @@ export default {
});
}
const _handleRemove = () => {
this.$refs['barrage'].remove({
this.$refs['barrage'] && this.$refs['barrage'].remove({
duration: 5000, // 延迟关闭的时间
speed: 600 // 弹幕消失的速度
});
@@ -756,7 +756,7 @@ export default {
let index = 0;
const _handleAddBarrage = () => {
setTimeout(() => {
this.$refs['barrage'].add(_list[index]);
this.$refs['barrage'] && this.$refs['barrage'].add(_list[index]);
index += 1;
if (index < _list.length - 1) {
_handleAddBarrage();
@@ -768,13 +768,42 @@ export default {
},
fnToWebview(data) {
uni.navigateTo({
url:
'/pagesC/website/website?data=' +
url: '/pagesC/website/website?data=' +
JSON.stringify({
title: data.title,
url: data.url
})
});
},
fnToOriginal(originalURL) {
this.fnToWebview({ title: this.result.title, url: originalURL });
},
// 查看密码验证确认
fnOnValidVisitConfirm() {
if (this.useVisitMode == 1) {
if (this.validVisitModal.value === this.useVisitPwd) {
this.validVisitModal.show = false;
return;
}
} else if (this.useVisitMode == 2) {
if (this.validVisitModal.value === this.useVisitMorePwd) {
this.showValidVisitMore = true;
this.validVisitModal.show = false;
return;
}
}
uni.$tm.toast("验证密码不正确!")
},
fnOnValidVisitCancel() {
this.validVisitModal.show = false;
this.validVisitModal.useCancel = true;
this.validVisitModal.value = undefined;
},
// 点击解锁弹出密码输入框
fnOnShowValidVisitMore() {
this.validVisitModal.useCancel = true;
this.validVisitModal.value = undefined;
this.validVisitModal.show = true;
}
}
};
@@ -788,7 +817,20 @@ export default {
flex-direction: column;
box-sizing: border-box;
background-color: #fafafd;
padding-bottom: 24rpx;
}
.bg-image {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
width: 100vw;
height: 100vh;
z-index: 0;
}
.loading-wrap {
padding: 0 24rpx;
height: inherit;
@@ -804,24 +846,26 @@ export default {
background-color: #ffffff;
box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.03);
// box-shadow: 0rpx 6rpx 30rpx rgba(182, 223, 255, 0.3);
border-radius: 12rpx;
border-radius: 24rpx;
.title {
font-size: 36rpx;
font-weight: 600;
text-align: center;
}
.detail {
width: 100%;
margin-top: 24rpx;
font-size: 26rpx;
.author {
text-align: center;
font-size: 24rpx;
color: #666;
&-name {
}
&-name {}
&-time {
margin-left: 36rpx;
}
@@ -831,22 +875,27 @@ export default {
margin-top: 24rpx;
width: 100%;
height: 280rpx;
&-img {
width: 100%;
height: 100%;
border-radius: 12rpx;
}
}
.count {
margin-top: 24rpx;
display: flex;
justify-content: space-between;
&.no-thumbnail {
border-top: 2rpx solid #f2f2f2;
padding-top: 12rpx;
.count-item {
position: relative;
color: #666;
&::after {
content: '';
position: absolute;
@@ -855,6 +904,7 @@ export default {
width: 2rpx;
height: 32rpx;
}
&:last-child {
&::after {
display: none;
@@ -862,16 +912,19 @@ export default {
}
}
}
&-item {
flex: 1;
display: flex;
align-items: flex-end;
justify-content: center;
color: #666;
.label {
font-size: 24rpx;
padding-left: 8rpx;
}
.value {
font-size: 32rpx;
}
@@ -879,6 +932,7 @@ export default {
}
}
}
.category {
margin: 0 24rpx;
padding: 24rpx;
@@ -888,37 +942,51 @@ export default {
box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.03);
// border: 2rpx solid #f8f8f8;
font-size: 28rpx;
&-type {
line-height: 55rpx;
}
&-tag {
background-color: #5bb8fa;
color: #fff;
padding: 6rpx 12rpx;
border-radius: 6rpx;
font-size: 24rpx;
&.is-empty {
background-color: #607d8b;
}
}
}
.category-tag+.category-tag {
margin-left: 12rpx;
}
.content {
margin-top: 24rpx;
}
.markdown-wrap,
.evan-markdown,
.ad-wrap,
.copyright-wrap,
.comment-wrap {
box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.03);
}
.markdown-wrap {
overflow: hidden;
border-radius: 12rpx;
}
.copyright-title {
position: relative;
box-sizing: border-box;
padding-left: 24rpx;
font-size: 30rpx;
&:before {
content: '';
position: absolute;
@@ -930,16 +998,20 @@ export default {
border-radius: 6rpx;
}
}
.poup-head {
border-bottom: 2rpx solid #f5f5f5;
}
.poup-body {
height: 50vh;
}
.poup-empty {
width: 100%;
height: 40vh;
}
.poup-loading-wrap {
width: 100%;
height: 40vh;
@@ -948,14 +1020,17 @@ export default {
font-size: 80rpx;
}
}
.poster-content {
width: 100%;
min-height: 60vh;
overflow: hidden;
}
.copyright-text {
line-height: 1.7;
}
.poster-loading {
width: 100%;
position: absolute;
@@ -966,8 +1041,39 @@ export default {
// background-color: rgba(0, 0, 0, 0.1);
z-index: 666;
}
.poster-save {
box-sizing: border-box;
border-top: 2rpx dashed #eee;
}
.original-url {
display: flex;
&_left {
flex-shrink: 0;
width: 84rpx;
}
&_right {
flex-grow: 1;
display: inline-flex;
align-items: center;
&__link {
width: 410rpx;
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&__btn {
flex-grow: 1;
flex-shrink: 0;
display: block;
text-align: right;
}
}
}
</style>