1
0

article-detail.vue 44 KB

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