article-detail.vue 29 KB

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