journal-card.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="journal-card mb-24 round-3 bg-white ">
  3. <view class="head pa-24 pb-0 flex flex-between">
  4. <view class="left flex">
  5. <cache-image class="avatar rounded" radius="50%" width="70rpx" height="70rpx" :url="bloggerInfo.avatar"
  6. :fileMd5="bloggerInfo.avatar" mode="scaleToFill"></cache-image>
  7. <view class="info pl-16 flex flex-col">
  8. <view class="nickname text-weight-b text-grey-darken-4">{{ bloggerInfo.nickname }}</view>
  9. <view class="mt-3 time text-size-m ">
  10. {{ $tm.dayjs(journal.createTime).format('YYYY-MM-DD HH:mm:ss') }}</view>
  11. </view>
  12. </view>
  13. <view class="right">
  14. <tm-button v-if="useLike" :shadow="0" theme="light-blue" size="s"
  15. @click="fnLike(journal)">点赞({{ journal.likes }})</tm-button>
  16. <tm-button v-if="useEdit" :shadow="0" theme="light-blue" size="s"
  17. @click="$emit('on-edit', journal)">编辑</tm-button>
  18. <tm-button v-if="useDel" :shadow="0" theme="red" size="s" @click="fnDel(journal)">删除</tm-button>
  19. </view>
  20. </view>
  21. <tm-more v-if="journal.content.length > 50" :maxHeight="100" label="查看全部内容" open-label="隐藏部分内容">
  22. <mp-html class="evan-markdown" lazy-load :domain="markdownConfig.domain"
  23. :loading-img="markdownConfig.loadingGif" :scroll-table="true" :selectable="true"
  24. :tag-style="markdownConfig.tagStyle" :container-style="markdownConfig.containStyle"
  25. :content="journal.content" :markdown="true" :showLineNumber="true" :showLanguageName="true"
  26. :copyByLongPress="true" />
  27. </tm-more>
  28. <mp-html v-else class="evan-markdown" lazy-load :domain="markdownConfig.domain"
  29. :loading-img="markdownConfig.loadingGif" :scroll-table="true" :selectable="true"
  30. :tag-style="markdownConfig.tagStyle" :container-style="markdownConfig.containStyle"
  31. :content="journal.content" :markdown="true" :showLineNumber="true" :showLanguageName="true"
  32. :copyByLongPress="true" />
  33. </view>
  34. </template>
  35. <script>
  36. import MarkdownConfig from '@/common/markdown/markdown.config.js';
  37. import mpHtml from '@/components/mp-html/components/mp-html/mp-html.vue';
  38. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  39. import tmMore from '@/tm-vuetify/components/tm-more/tm-more.vue';
  40. export default {
  41. name: 'journal-card',
  42. components: {
  43. mpHtml,
  44. tmButton,
  45. tmMore
  46. },
  47. props: {
  48. isAdmin: {
  49. type: Boolean,
  50. default: false
  51. },
  52. journal: {
  53. type: Object,
  54. default: () => {}
  55. },
  56. useLike: {
  57. type: Boolean,
  58. default: false
  59. },
  60. useEdit: {
  61. type: Boolean,
  62. default: false
  63. },
  64. useDel: {
  65. type: Boolean,
  66. default: false
  67. }
  68. },
  69. data() {
  70. return {
  71. markdownConfig: MarkdownConfig
  72. };
  73. },
  74. computed: {
  75. bloggerInfo() {
  76. let blogger = this.$tm.vx.getters().getConfigs.authorConfig.blogger;
  77. blogger.avatar = this.$utils.checkAvatarUrl(blogger.avatar, true);
  78. return blogger;
  79. },
  80. },
  81. methods: {
  82. fnLike(journal) {
  83. uni.showLoading({
  84. mask: true,
  85. title: '正在点赞中...'
  86. });
  87. this.$httpApi
  88. .postJournalLikes(journal.id)
  89. .then(res => {
  90. if (res.status == 200) {
  91. journal.likes += 1;
  92. uni.$tm.toast('o( ̄▽ ̄)d点赞成功!');
  93. } else {
  94. uni.$tm.toast('Ծ‸Ծ点赞失败了~');
  95. }
  96. })
  97. .catch(err => {
  98. uni.$tm.toast('Ծ‸Ծ点赞失败了~');
  99. });
  100. },
  101. fnDel(journal) {
  102. uni.$eShowModal({
  103. title: '提示',
  104. content: '您确定要删除该日记吗?',
  105. showCancel: true,
  106. cancelText: '否',
  107. cancelColor: '#999999',
  108. confirmText: '是',
  109. confirmColor: '#03a9f4'
  110. })
  111. .then(res => {
  112. this.$httpApi.admin
  113. .deleteJournalsById(journal.id)
  114. .then(res => {
  115. if (res.status == 200) {
  116. this.$emit('on-del', journal);
  117. uni.$tm.toast('删除成功!');
  118. } else {
  119. uni.$tm.toast('Ծ‸Ծ删除失败~');
  120. }
  121. })
  122. .catch(err => {
  123. uni.$tm.toast('Ծ‸Ծ删除失败~');
  124. });
  125. })
  126. .catch(() => {});
  127. }
  128. }
  129. };
  130. </script>
  131. <style scoped lang="scss">
  132. .journal-card {
  133. box-sizing: border-box;
  134. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.05);
  135. overflow: hidden;
  136. .avatar {
  137. width: 70rpx;
  138. height: 70rpx;
  139. border: 6rpx solid #fff;
  140. box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.05);
  141. }
  142. .info {
  143. justify-content: center;
  144. .nickname {
  145. font-size: 30rpx;
  146. }
  147. .time {
  148. font-size: 26rpx;
  149. }
  150. }
  151. }
  152. </style>