article-detail.vue 28 KB

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