article-detail.vue 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. <template>
  2. <view class="app-page">
  3. <view v-if="loading != 'success'" class="loading-wrap">
  4. <tm-skeleton model="card"></tm-skeleton>
  5. <tm-skeleton model="card"></tm-skeleton>
  6. <tm-skeleton model="card"></tm-skeleton>
  7. </view>
  8. <block v-else>
  9. <!-- 顶部信息 -->
  10. <view class="head ma-24">
  11. <view class="title">{{ result.title }}</view>
  12. <view class="detail">
  13. <view class="author">
  14. <text class="author-name">博主:{{ author.nickname }}</text>
  15. <text class="author-time">
  16. 时间:{{ { d: result.createTime, f: 'yyyy年MM月dd日 星期w' } | formatTime }}
  17. </text>
  18. </view>
  19. <view class="cover" v-if="result.thumbnail">
  20. <image class="cover-img" mode="aspectFill" :src="calcUrl(result.thumbnail)"></image>
  21. </view>
  22. <view class="count" :class="{ 'no-thumbnail': !result.thumbnail }">
  23. <view class="count-item">
  24. <text class="value">{{ result.visits }}</text>
  25. <text class="label">阅读</text>
  26. </view>
  27. <view class="count-item">
  28. <text class="value">{{ result.likes }}</text>
  29. <text class="label">喜欢</text>
  30. </view>
  31. <view class="count-item">
  32. <text class="value">{{ result.commentCount }}</text>
  33. <text class="label">评论</text>
  34. </view>
  35. <view class="count-item">
  36. <text class="value">{{ result.wordCount }}</text>
  37. <text class="label">字数</text>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 分类 -->
  43. <view class="category">
  44. <view class="category-type">
  45. <text class="text-weight-b">分类:</text>
  46. <text v-if="result.categories.length == 0" class="category-tag is-empty">未选择分类</text>
  47. <block v-else>
  48. <text class="category-tag" v-for="(item, index) in result.categories" :key="index" @click="fnToCate(item)">
  49. {{ item.name }}
  50. </text>
  51. </block>
  52. </view>
  53. <view class="mt-18 category-type">
  54. <text class="text-weight-b">标签:</text>
  55. <text v-if="result.tags.length == 0" class="category-tag is-empty">未选择标签</text>
  56. <block v-else>
  57. <text class="category-tag" :style="{ backgroundColor: item.color }" v-for="(item, index) in result.tags" :key="index" @click="fnToTag(item)">
  58. {{ item.name }}
  59. </text>
  60. </block>
  61. </view>
  62. <view v-if="originalURL" class="mt-18 category-type original-url">
  63. <view class="original-url_left text-weight-b">原文:</view>
  64. <view class="original-url_right text-grey">
  65. <text class="original-url_right__link" @click.stop="fnToOriginal(originalURL)">{{ originalURL }}</text>
  66. <text class="original-url_right__btn" @click.stop="fnToOriginal(originalURL)">阅读原文<text class="iconfont icon-angle-right ml-5 text-size-s"></text> </text>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 广告区域 -->
  71. <view v-if="haloAdConfig.articleDetail.use && (haloAdConfig.unitId || haloAdConfig.adpid)" class="ad-wrap ma-24 mb-0">
  72. <!-- #ifdef MP-WEIXIN -->
  73. <ad v-if="haloAdConfig.unitId" :unit-id="haloAdConfig.unitId"></ad>
  74. <!-- #endif -->
  75. <!-- #ifndef MP-WEIXIN -->
  76. <ad v-if="haloAdConfig.adpid" :adpid="haloAdConfig.adpid"></ad>
  77. <!-- #endif -->
  78. </view>
  79. <!-- 内容区域 -->
  80. <view class="content ml-24 mr-24">
  81. <!-- markdown渲染 -->
  82. <view class="markdown-wrap">
  83. <tm-more :disabled="true" :maxHeight="1500" :isRemovBar="true" :open="showValidVisitMore" @click="fnOnShowValidVisitMore">
  84. <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" />
  85. <template v-slot:more="{ data }">
  86. <view class="">
  87. <text class="text-blue text-size-m text-weight-b">文章部分内容已加密点击解锁</text>
  88. <text class="text-blue iconfont icon-lock-fill text-size-s ml-5"></text>
  89. </view>
  90. </template>
  91. </tm-more>
  92. </view>
  93. <!-- 广告区域:微信/decloud申请 -->
  94. <view v-if="haloAdConfig.articleDetail.use && (haloAdConfig.unitId || haloAdConfig.adpid)" class="ad-wrap mt-24 mb-24 ">
  95. <!-- #ifdef MP-WEIXIN -->
  96. <ad v-if="haloAdConfig.unitId" :unit-id="haloAdConfig.unitId"></ad>
  97. <!-- #endif -->
  98. <!-- #ifndef MP-WEIXIN -->
  99. <ad v-if="haloAdConfig.adpid" :adpid="haloAdConfig.adpid"></ad>
  100. <!-- #endif -->
  101. </view>
  102. <!-- 广告区域:自定义广告位 -->
  103. <view class="ad-card mt-24" v-if="haloAdConfig.articleDetail.custom.use">
  104. <text class="ad-card_tip">广告</text>
  105. <image class="ad-card_cover" :src="haloAdConfig.articleDetail.custom.cover" mode="scaleToFill"></image>
  106. <view class="ad-card_info">
  107. <view class="ad-card_info-title">{{ haloAdConfig.articleDetail.custom.title }}</view>
  108. <view class="ad-card_info-desc">{{ haloAdConfig.articleDetail.custom.content }}</view>
  109. <view v-if="haloAdConfig.articleDetail.custom.url" class="ad-card_info-link" @click="fnToWebview(haloAdConfig.articleDetail.custom)">
  110. 立即查看
  111. </view>
  112. </view>
  113. </view>
  114. <!-- 版权声明 -->
  115. <view v-if="copyright.use" class="copyright-wrap bg-white mt-24 pa-24 round-4">
  116. <view class="copyright-title text-weight-b">版权声明</view>
  117. <view class="copyright-content mt-12 grey-lighten-5 text-grey-darken-2 round-4 pt-12 pb-12 pl-24 pr-24 ">
  118. <view v-if="copyright.author" class="copyright-text text-size-s ">
  119. 版权归属:{{ copyright.author }}
  120. </view>
  121. <view v-if="copyright.description" class="copyright-text text-size-s mt-12">
  122. 版权说明:{{ copyright.description }}
  123. </view>
  124. <view v-if="copyright.violation" class="copyright-text text-size-s mt-12 text-red">
  125. 侵权处理:{{ copyright.violation }}
  126. </view>
  127. </view>
  128. </view>
  129. <!-- 评论展示区域 -->
  130. <view class="comment-wrap bg-white mt-24 pa-24 round-4">
  131. <commentList :disallowComment="result.disallowComment" :postId="result.id" :post="result" @on-comment-detail="fnOnShowCommentDetail" @on-loaded="fnOnCommentLoaded"></commentList>
  132. </view>
  133. </view>
  134. <!-- 弹幕效果 -->
  135. <barrage ref="barrage" :maxTop="240" :type="globalAppSettings.barrage.type"></barrage>
  136. <!-- 返回顶部 -->
  137. <tm-flotbutton :offset="[16, 80]" icon="icon-angle-up" color="bg-gradient-light-blue-accent" @click="fnToTopPage()"></tm-flotbutton>
  138. <tm-flotbutton :actions="btnOption.actions" actions-pos="left" :show-text="true" color="bg-gradient-orange-accent" @change="fnOnFlotButtonChange"></tm-flotbutton>
  139. </block>
  140. <!-- 评论详情 -->
  141. <tm-poup v-model="commentDetail.show" height="auto" :round="6" :over-close="true" position="bottom">
  142. <view class="pa-24">
  143. <view class="poup-head pb-24">
  144. <view class="poup-title text-align-center text-size-g text-weight-b mb-32">评论详情</view>
  145. <comment-item :useContentBg="false" :useActions="false" :isChild="false" :comment="commentDetail.comment" :postId="result.id"></comment-item>
  146. </view>
  147. <scroll-view :scroll-y="true" class="poup-body">
  148. <view v-if="commentDetail.loading != 'success'" class="poup-loading-wrap flex flex-center">
  149. <view v-if="commentDetail.loading == 'loading'" class="loading flex flex-center flex-col">
  150. <text class="e-loading-icon iconfont icon-loading text-blue"></text>
  151. <view class="text-size-n text-grey-lighten-1 py-12 mt-12">加载中,请稍等...</view>
  152. </view>
  153. <view v-else-if="commentDetail.loading == 'error'" class="error">
  154. <tm-empty icon="icon-wind-cry" label="加载失败">
  155. <tm-button theme="bg-gradient-light-blue-accent" size="m" v-if="!disallowComment" @click="fnGetChildComments()">
  156. 刷新试试
  157. </tm-button>
  158. </tm-empty>
  159. </view>
  160. </view>
  161. <block v-else>
  162. <view v-if="commentDetail.list.length == 0" class="poup-empty flex flex-center">
  163. <tm-empty icon="icon-shiliangzhinengduixiang-" label="没有更多评论啦~"></tm-empty>
  164. </view>
  165. <block v-else>
  166. <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>
  167. </block>
  168. </block>
  169. </scroll-view>
  170. </view>
  171. </tm-poup>
  172. <!-- 海报 -->
  173. <tm-poup v-model="poster.show" width="90vw" height="auto" :round="6" :over-close="true" position="center">
  174. <view class="poster-content pt-12 bg-white">
  175. <view v-if="poster.loading" class="poster-loading flex flex-center text-grey-darken-1">
  176. <text class="e-loading-icon iconfont icon-loading"></text>
  177. <text class="ml-6">海报正在生成...</text>
  178. </view>
  179. <block v-if="poster.showCanvas">
  180. <r-canvas ref="rCanvas"></r-canvas>
  181. <view class="poster-save ma-24 mt-0 pt-20 flex flex-center">
  182. <tm-button theme="bg-gradient-light-blue-accent" size="m" @click="fnSavePoster()">
  183. 保存到相册
  184. </tm-button>
  185. <tm-button v-if="false" theme="bg-gradient-orange-accent" size="m" @click="fnShareTo()">
  186. 分享给好友
  187. </tm-button>
  188. <tm-button theme="bg-gradient-blue-grey-accent" size="m" @click="fnOnPosterClose()">
  189. 关 闭
  190. </tm-button>
  191. </view>
  192. </block>
  193. </view>
  194. </tm-poup>
  195. <!-- 密码访问解密弹窗 -->
  196. <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>
  197. </view>
  198. </template>
  199. <script>
  200. import MarkdownConfig from '@/common/markdown/markdown.config.js';
  201. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  202. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  203. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  204. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  205. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  206. import tmDialog from '@/tm-vuetify/components/tm-dialog/tm-dialog.vue';
  207. import tmMore from '@/tm-vuetify/components/tm-more/tm-more.vue';
  208. import mpHtml from '@/components/mp-html/components/mp-html/mp-html.vue';
  209. import commentList from '@/components/comment-list/comment-list.vue';
  210. import commentItem from '@/components/comment-item/comment-item.vue';
  211. import rCanvas from '@/components/r-canvas/r-canvas.vue';
  212. import barrage from '@/components/barrage/barrage.vue';
  213. import { haloWxShareMixin } from '@/common/mixins/wxshare.mixin.js';
  214. export default {
  215. components: {
  216. tmSkeleton,
  217. tmPoup,
  218. tmFlotbutton,
  219. tmButton,
  220. tmEmpty,
  221. tmDialog,
  222. tmMore,
  223. mpHtml,
  224. commentList,
  225. commentItem,
  226. rCanvas,
  227. barrage
  228. },
  229. mixins: [haloWxShareMixin],
  230. data() {
  231. return {
  232. loading: 'loading',
  233. markdownConfig: MarkdownConfig,
  234. btnOption: {
  235. actions: [{
  236. icon: 'icon-like',
  237. color: 'bg-gradient-orange-accent'
  238. },
  239. {
  240. icon: 'icon-commentdots-fill',
  241. color: 'bg-gradient-green-accent'
  242. },
  243. {
  244. icon: 'icon-share1',
  245. color: 'bg-gradient-blue-accent'
  246. }
  247. ]
  248. },
  249. queryParams: {
  250. articleId: null
  251. },
  252. result: {},
  253. commentDetail: {
  254. loading: 'loading',
  255. show: false,
  256. comment: {},
  257. postId: undefined,
  258. list: []
  259. },
  260. poster: {
  261. show: false,
  262. showCanvas: false,
  263. loading: true,
  264. res: null
  265. },
  266. metas: [], // 自定义元数据
  267. // 文章加密(弹窗输入密码解密)
  268. validVisitModal: {
  269. show: false,
  270. useCancel: false,
  271. value: undefined
  272. },
  273. showValidVisitMore: true,
  274. };
  275. },
  276. computed: {
  277. copyright() {
  278. return getApp().globalData.copyright;
  279. },
  280. calcUrl() {
  281. return url => {
  282. if (this.$utils.checkIsUrl(url)) {
  283. return url;
  284. }
  285. return getApp().globalData.baseApiUrl + url;
  286. };
  287. },
  288. // 获取博主信息
  289. bloggerInfo() {
  290. let blogger = this.$tm.vx.getters().getBlogger;
  291. blogger.avatar = this.$utils.checkAvatarUrl(blogger.avatar, true);
  292. return blogger;
  293. },
  294. // 原文链接:个人资质=可以打开公众号文章;非个人:任意链接地址(需在小程序后台配置)
  295. originalURL() {
  296. const target = this.metas.find(x => x.key == 'unihalo_originalURL');
  297. if (!target) return '';
  298. return target.value || '';
  299. },
  300. // 是否使用文章密码功能,如果值不为空,则优先于 useVisitMore:unihalo_useVisitPwd
  301. useVisitPwd() {
  302. const target = this.metas.find(x => x.key == 'unihalo_useVisitPwd');
  303. if (!target) return false;
  304. return target.value || false;
  305. },
  306. // 是否启用查看完整文章的功能的密码:unihalo_useVisitMorePwd
  307. useVisitMorePwd() {
  308. const target = this.metas.find(x => x.key == 'unihalo_useVisitMorePwd');
  309. if (!target) return false;
  310. return target.value || false;
  311. },
  312. // 当前是使用哪一种类型的密码验证 0=不使用任何 1=默认弹窗密码 2=查看部分内容
  313. useVisitMode() {
  314. if (this.useVisitPwd != false) {
  315. return 1
  316. }
  317. if (this.useVisitMorePwd != false) {
  318. return 2
  319. }
  320. return 0
  321. }
  322. },
  323. watch: {
  324. useVisitPwd(val) {
  325. if (val) {
  326. this.validVisitModal.show = true
  327. }
  328. },
  329. useVisitMode(val) {
  330. if (val != 2) {
  331. this.showValidVisitMore = true
  332. } else {
  333. this.showValidVisitMore = false
  334. }
  335. }
  336. },
  337. onLoad(e) {
  338. this.fnSetPageTitle('文章加载中...');
  339. this.queryParams.articleId = e.articleId;
  340. this.fnGetData();
  341. },
  342. onPullDownRefresh() {
  343. this.fnGetData();
  344. },
  345. methods: {
  346. fnGetData() {
  347. this.loading = 'loading';
  348. uni.showLoading({
  349. mask: true,
  350. title: '加载中...'
  351. });
  352. this.$httpApi
  353. .getArticleDetail(this.queryParams.articleId)
  354. .then(res => {
  355. if (res.status == 200) {
  356. this.result = res.data;
  357. this.metas = res.data.metas;
  358. this.fnSetPageTitle('文章详情');
  359. this.loading = 'success';
  360. this.fnSetWxShareConfig({
  361. title: this.result.title,
  362. desc: this.result.summary,
  363. imageUrl: this.$utils.checkThumbnailUrl(this.result.thumbnail),
  364. path: `/pagesA/article-detail/article-detail?articleId=${this.queryParams.articleId}`,
  365. copyLink: this.$haloConfig.apiUrl,
  366. query: {}
  367. });
  368. } else {
  369. this.loading = 'error';
  370. }
  371. })
  372. .catch(err => {
  373. this.loading = 'error';
  374. })
  375. .finally(() => {
  376. uni.hideLoading();
  377. uni.stopPullDownRefresh();
  378. });
  379. },
  380. // 浮动按钮点击
  381. fnOnFlotButtonChange(index) {
  382. switch (index) {
  383. case 0:
  384. this.fnDoLikes();
  385. break;
  386. case 1:
  387. this.fnToComment();
  388. break;
  389. case 2:
  390. this.fnShowShare();
  391. break;
  392. }
  393. },
  394. fnToComment() {
  395. if (this.result.disallowComment) {
  396. return uni.$tm.toast('文章已开启禁止评论!');
  397. }
  398. this.$Router.push({
  399. path: '/pagesA/comment/comment',
  400. query: {
  401. id: this.result.id,
  402. parentId: 0,
  403. title: this.result.title,
  404. from: 'posts',
  405. formPage: 'comment_list',
  406. type: 'post'
  407. }
  408. });
  409. },
  410. fnDoLikes() {
  411. this.$httpApi
  412. .postLikePost(this.result.id)
  413. .then(res => {
  414. if (res.status == 200) {
  415. this.result.likes += 1;
  416. uni.$tm.toast('\(^o^)/~点赞成功!');
  417. } else {
  418. uni.showToast({
  419. icon: 'none',
  420. title: res.message
  421. });
  422. }
  423. })
  424. .catch(err => {
  425. uni.showToast({
  426. icon: 'none',
  427. title: err.message
  428. });
  429. });
  430. },
  431. fnShowShare() {
  432. this.poster.show = true;
  433. setTimeout(() => {
  434. this.poster.showCanvas = true;
  435. this.fnCreatePoster(res => {
  436. this.poster.res = res;
  437. });
  438. }, 500);
  439. },
  440. // 绘制虚线:https://blog.csdn.net/a460550542/article/details/124821248
  441. drawDashedLine(ctx, x, y, w, h, pattern, color) {
  442. ctx.lineWidth = h;
  443. ctx.strokeStyle = color;
  444. ctx.beginPath();
  445. ctx.setLineDash(pattern);
  446. ctx.moveTo(x, y);
  447. ctx.lineTo(w, y);
  448. ctx.stroke();
  449. y += 20;
  450. },
  451. fnCreatePoster(callback) {
  452. this.$nextTick(async () => {
  453. const systemInfo = await uni.getSystemInfoSync();
  454. const _bloggerAvatar = this.$utils.checkAvatarUrl(this.bloggerInfo.avatar, true);
  455. const _articleCover = this.$utils.checkThumbnailUrl(this.result.thumbnail, true);
  456. // 初始化
  457. await this.$refs.rCanvas.init({
  458. canvas_id: 'rCanvas',
  459. // canvas_width: systemInfo.windowWidth - uni.upx2px(76),
  460. canvas_width: 337,
  461. canvas_height: 460,
  462. background_color: 'rgba(255,255,255,0)'
  463. });
  464. // 画圆角背景
  465. await this.$refs.rCanvas
  466. .fillRoundRect({
  467. x: 0,
  468. y: 0,
  469. w: 337,
  470. h: 460,
  471. radius: 12,
  472. fill_color: '#fff'
  473. })
  474. .catch(err_msg => {
  475. uni.showToast({
  476. title: err_msg,
  477. icon: 'none'
  478. });
  479. });
  480. // 博主信息
  481. await this.$refs.rCanvas
  482. .drawImage({
  483. url: _bloggerAvatar,
  484. x: 12,
  485. y: 12,
  486. w: 48,
  487. h: 48,
  488. border_radius: 24
  489. })
  490. .catch(err_msg => {
  491. uni.showToast({
  492. title: err_msg,
  493. icon: 'none'
  494. });
  495. });
  496. await this.$refs.rCanvas
  497. .drawText({
  498. text: this.bloggerInfo.nickname,
  499. max_width: 0,
  500. x: 70,
  501. y: 30,
  502. font_color: '#000',
  503. font_size: 15
  504. })
  505. .catch(err_msg => {
  506. uni.showToast({
  507. title: err_msg,
  508. icon: 'none'
  509. });
  510. });
  511. await this.$refs.rCanvas
  512. .drawText({
  513. text: this.bloggerInfo.description,
  514. max_width: 0,
  515. x: 70,
  516. y: 52,
  517. font_color: '#666',
  518. font_size: 12
  519. })
  520. .catch(err_msg => {
  521. uni.showToast({
  522. title: err_msg,
  523. icon: 'none'
  524. });
  525. });
  526. // 文章封面图
  527. await this.$refs.rCanvas
  528. .drawImage({
  529. url: _articleCover,
  530. x: 12,
  531. y: 75,
  532. w: 312,
  533. h: 180,
  534. border_radius: 6
  535. })
  536. .catch(err_msg => {
  537. uni.showToast({
  538. title: err_msg,
  539. icon: 'none'
  540. });
  541. });
  542. // 文章标题
  543. await this.$refs.rCanvas
  544. .drawText({
  545. text: this.result.title,
  546. max_width: 312,
  547. line_clamp: 1,
  548. x: 12,
  549. y: 285,
  550. font_weight: 'bold',
  551. font_color: '#333',
  552. font_size: 14
  553. })
  554. .catch(err_msg => {
  555. uni.showToast({
  556. title: err_msg,
  557. icon: 'none'
  558. });
  559. });
  560. await this.$refs.rCanvas
  561. .drawText({
  562. text: this.result.summary,
  563. max_width: 312,
  564. line_clamp: 2,
  565. x: 12,
  566. y: 310,
  567. font_color: '#333',
  568. font_size: 13,
  569. line_height: 20
  570. })
  571. .catch(err_msg => {
  572. uni.showToast({
  573. title: err_msg,
  574. icon: 'none'
  575. });
  576. });
  577. this.drawDashedLine(this.$refs.rCanvas.ctx, 14, 356, 332, 0.5, [8, 5, 5, 5], '#999');
  578. // 小程序信息
  579. await this.$refs.rCanvas
  580. .drawImage({
  581. url: this.$haloConfig.miniCodeImageUrl,
  582. x: 20,
  583. y: 360,
  584. w: 80,
  585. h: 80
  586. })
  587. .catch(err_msg => {
  588. uni.showToast({
  589. title: err_msg,
  590. icon: 'none'
  591. });
  592. });
  593. await this.$refs.rCanvas
  594. .drawText({
  595. text: '长按识别小程序',
  596. x: 150,
  597. y: 390,
  598. font_color: '#333',
  599. font_size: 15,
  600. font_weight: 'bold',
  601. line_height: 22
  602. })
  603. .catch(err_msg => {
  604. uni.showToast({
  605. title: err_msg,
  606. icon: 'none'
  607. });
  608. });
  609. await this.$refs.rCanvas
  610. .drawText({
  611. text: '关注我,给你分享更多有趣的知识',
  612. x: 115,
  613. y: 425,
  614. font_color: '#333',
  615. font_size: 12,
  616. line_height: 22
  617. })
  618. .catch(err_msg => {
  619. uni.showToast({
  620. title: err_msg,
  621. icon: 'none'
  622. });
  623. });
  624. // 生成海报
  625. await this.$refs.rCanvas.draw(res => {
  626. //res.tempFilePath:生成成功,返回base64图片
  627. // 保存图片
  628. this.poster.loading = false;
  629. callback(res);
  630. });
  631. });
  632. },
  633. fnOnPosterClose() {
  634. this.poster.show = false;
  635. this.poster.showCanvas = false;
  636. this.poster.loading = true;
  637. },
  638. fnSavePoster() {
  639. this.$refs.rCanvas.saveImage(this.poster.res.tempFilePath);
  640. uni.$tm.toast('保存成功');
  641. },
  642. fnShareTo() {
  643. // #ifdef MP-WEIXIN
  644. uni.$tm.toast('点击右上角分享给好友!');
  645. // #endif
  646. // #ifdef APP-PLUS
  647. uni.share({
  648. provider: 'weixin',
  649. scene: 'WXSceneSession',
  650. type: 0,
  651. href: this.$haloConfig.apiUrl,
  652. title: this.result.title,
  653. summary: this.result.summary,
  654. imageUrl: this.poster.res.tempFilePath,
  655. success: function(res) {
  656. console.log('success:' + JSON.stringify(res));
  657. },
  658. fail: function(err) {
  659. console.log('fail:' + JSON.stringify(err));
  660. }
  661. });
  662. // #endif
  663. },
  664. fnOnShowCommentDetail(data) {
  665. const { postId, comment } = data;
  666. this.commentDetail.comment = comment;
  667. this.commentDetail.postId = postId;
  668. this.commentDetail.list = [];
  669. this.commentDetail.show = true;
  670. this.fnGetChildComments();
  671. },
  672. fnGetChildComments() {
  673. this.commentDetail.loading = 'loading';
  674. this.$httpApi
  675. .getPostChildrenCommentList(this.commentDetail.postId, this.commentDetail.comment.id, {})
  676. .then(res => {
  677. if (res.status == 200) {
  678. this.commentDetail.loading = 'success';
  679. this.commentDetail.list = res.data;
  680. } else {
  681. this.commentDetail.loading = 'error';
  682. }
  683. console.log('getPostChildrenCommentList', res);
  684. })
  685. .catch(err => {
  686. this.commentDetail.loading = 'error';
  687. });
  688. },
  689. fnToCate(category) {
  690. uni.navigateTo({
  691. url: `/pagesA/category-detail/category-detail?slug=${category.slug}&name=${category.name}`
  692. });
  693. },
  694. fnToTag(tag) {
  695. uni.navigateTo({
  696. url: `/pagesA/tag-detail/tag-detail?id=${tag.id}&slug=${tag.slug}&name=${tag.name}`
  697. });
  698. },
  699. async fnOnCommentLoaded(data) {
  700. const _list = [];
  701. const _handleData = list => {
  702. return new Promise(resolve => {
  703. if (list.length == 0) {
  704. resolve();
  705. } else {
  706. list.forEach(item => {
  707. _list.push(item);
  708. if (item.children && item.children.length != 0) {
  709. _handleData(item.children);
  710. }
  711. resolve();
  712. });
  713. }
  714. });
  715. };
  716. await _handleData(data);
  717. if (this.globalAppSettings.barrage.use) {
  718. this.$nextTick(() => {
  719. if (_list.length != 0) {
  720. _handleAddBarrage();
  721. }
  722. });
  723. }
  724. const _handleRemove = () => {
  725. this.$refs['barrage'] && this.$refs['barrage'].remove({
  726. duration: 5000, // 延迟关闭的时间
  727. speed: 600 // 弹幕消失的速度
  728. });
  729. };
  730. let index = 0;
  731. const _handleAddBarrage = () => {
  732. setTimeout(() => {
  733. this.$refs['barrage'] && this.$refs['barrage'].add(_list[index]);
  734. index += 1;
  735. if (index < _list.length - 1) {
  736. _handleAddBarrage();
  737. } else {
  738. _handleRemove();
  739. }
  740. }, 1000);
  741. };
  742. },
  743. fnToWebview(data) {
  744. uni.navigateTo({
  745. url: '/pagesC/website/website?data=' +
  746. JSON.stringify({
  747. title: data.title,
  748. url: data.url
  749. })
  750. });
  751. },
  752. fnToOriginal(originalURL) {
  753. this.fnToWebview({ title: this.result.title, url: originalURL });
  754. },
  755. // 查看密码验证确认
  756. fnOnValidVisitConfirm() {
  757. if (this.useVisitMode == 1) {
  758. if (this.validVisitModal.value === this.useVisitPwd) {
  759. this.validVisitModal.show = false;
  760. return;
  761. }
  762. } else if (this.useVisitMode == 2) {
  763. if (this.validVisitModal.value === this.useVisitMorePwd) {
  764. this.showValidVisitMore = true;
  765. this.validVisitModal.show = false;
  766. return;
  767. }
  768. }
  769. uni.$tm.toast("验证密码不正确!")
  770. },
  771. fnOnValidVisitCancel() {
  772. this.validVisitModal.show = false;
  773. this.validVisitModal.useCancel = true;
  774. this.validVisitModal.value = undefined;
  775. },
  776. // 点击解锁弹出密码输入框
  777. fnOnShowValidVisitMore() {
  778. this.validVisitModal.useCancel = true;
  779. this.validVisitModal.value = undefined;
  780. this.validVisitModal.show = true;
  781. }
  782. }
  783. };
  784. </script>
  785. <style lang="scss" scoped>
  786. .app-page {
  787. width: 100vw;
  788. min-height: 100vh;
  789. display: flex;
  790. flex-direction: column;
  791. box-sizing: border-box;
  792. background-color: #fafafd;
  793. padding-bottom: 24rpx;
  794. }
  795. .bg-image {
  796. position: fixed;
  797. left: 0;
  798. top: 0;
  799. right: 0;
  800. bottom: 0;
  801. width: 100vw;
  802. height: 100vh;
  803. z-index: 0;
  804. }
  805. .loading-wrap {
  806. padding: 0 24rpx;
  807. height: inherit;
  808. background-color: #fff;
  809. }
  810. .head {
  811. display: flex;
  812. flex-direction: column;
  813. align-items: center;
  814. justify-content: center;
  815. padding: 36rpx 24rpx;
  816. background-color: #ffffff;
  817. box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.03);
  818. // box-shadow: 0rpx 6rpx 30rpx rgba(182, 223, 255, 0.3);
  819. border-radius: 12rpx;
  820. .title {
  821. font-size: 36rpx;
  822. font-weight: 600;
  823. text-align: center;
  824. }
  825. .detail {
  826. width: 100%;
  827. margin-top: 24rpx;
  828. font-size: 26rpx;
  829. .author {
  830. text-align: center;
  831. font-size: 24rpx;
  832. color: #666;
  833. &-name {}
  834. &-time {
  835. margin-left: 36rpx;
  836. }
  837. }
  838. .cover {
  839. margin-top: 24rpx;
  840. width: 100%;
  841. height: 280rpx;
  842. &-img {
  843. width: 100%;
  844. height: 100%;
  845. border-radius: 12rpx;
  846. }
  847. }
  848. .count {
  849. margin-top: 24rpx;
  850. display: flex;
  851. justify-content: space-between;
  852. &.no-thumbnail {
  853. border-top: 2rpx solid #f2f2f2;
  854. padding-top: 12rpx;
  855. .count-item {
  856. position: relative;
  857. color: #666;
  858. &::after {
  859. content: '';
  860. position: absolute;
  861. right: 0;
  862. background-color: #eee;
  863. width: 2rpx;
  864. height: 32rpx;
  865. }
  866. &:last-child {
  867. &::after {
  868. display: none;
  869. }
  870. }
  871. }
  872. }
  873. &-item {
  874. flex: 1;
  875. display: flex;
  876. align-items: flex-end;
  877. justify-content: center;
  878. color: #666;
  879. .label {
  880. font-size: 24rpx;
  881. padding-left: 8rpx;
  882. }
  883. .value {
  884. font-size: 32rpx;
  885. }
  886. }
  887. }
  888. }
  889. }
  890. .category {
  891. margin: 0 24rpx;
  892. padding: 24rpx;
  893. background-color: #ffffff;
  894. border-radius: 12rpx;
  895. // box-shadow: 0rpx 0rpx 24rpx rgba(182, 223, 255, 0.3);
  896. box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.03);
  897. // border: 2rpx solid #f8f8f8;
  898. font-size: 28rpx;
  899. &-type {
  900. line-height: 55rpx;
  901. }
  902. &-tag {
  903. background-color: #5bb8fa;
  904. color: #fff;
  905. padding: 6rpx 12rpx;
  906. border-radius: 6rpx;
  907. font-size: 24rpx;
  908. &.is-empty {
  909. background-color: #607d8b;
  910. }
  911. }
  912. }
  913. .category-tag+.category-tag {
  914. margin-left: 12rpx;
  915. }
  916. .content {
  917. margin-top: 24rpx;
  918. }
  919. .markdown-wrap,
  920. .evan-markdown,
  921. .ad-wrap,
  922. .copyright-wrap,
  923. .comment-wrap {
  924. box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.03);
  925. }
  926. .markdown-wrap {
  927. overflow: hidden;
  928. border-radius: 12rpx;
  929. }
  930. .copyright-title {
  931. position: relative;
  932. box-sizing: border-box;
  933. padding-left: 24rpx;
  934. font-size: 30rpx;
  935. &:before {
  936. content: '';
  937. position: absolute;
  938. left: 0rpx;
  939. top: 8rpx;
  940. width: 8rpx;
  941. height: 26rpx;
  942. background-color: rgb(3, 174, 252);
  943. border-radius: 6rpx;
  944. }
  945. }
  946. .poup-head {
  947. border-bottom: 2rpx solid #f5f5f5;
  948. }
  949. .poup-body {
  950. height: 50vh;
  951. }
  952. .poup-empty {
  953. width: 100%;
  954. height: 40vh;
  955. }
  956. .poup-loading-wrap {
  957. width: 100%;
  958. height: 40vh;
  959. .e-loading-icon {
  960. font-size: 80rpx;
  961. }
  962. }
  963. .poster-content {
  964. width: 100%;
  965. min-height: 60vh;
  966. overflow: hidden;
  967. }
  968. .copyright-text {
  969. line-height: 1.7;
  970. }
  971. .poster-loading {
  972. width: 100%;
  973. position: absolute;
  974. left: 0;
  975. top: 0;
  976. right: 0;
  977. bottom: 0;
  978. // background-color: rgba(0, 0, 0, 0.1);
  979. z-index: 666;
  980. }
  981. .poster-save {
  982. box-sizing: border-box;
  983. border-top: 2rpx dashed #eee;
  984. }
  985. .original-url {
  986. display: flex;
  987. &_left {
  988. flex-shrink: 0;
  989. width: 84rpx;
  990. }
  991. &_right {
  992. flex-grow: 1;
  993. display: inline-flex;
  994. align-items: center;
  995. &__link {
  996. width: 410rpx;
  997. display: inline-block;
  998. overflow: hidden;
  999. text-overflow: ellipsis;
  1000. white-space: nowrap;
  1001. }
  1002. &__btn {
  1003. flex-grow: 1;
  1004. flex-shrink: 0;
  1005. display: block;
  1006. text-align: right;
  1007. }
  1008. }
  1009. }
  1010. </style>