journal-card.vue 4.3 KB

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