detail.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div class="main">
  3. <p class="title">{{ title }}</p>
  4. <div class="flex-start mt-36">
  5. <v-lazy-image
  6. class="logo"
  7. :src="authorProfileImageUrl"
  8. src-placeholder="https://photoprism.hichinatravel.com/api/v1/t/07dac61cc5dfec34dd9358f37bd70ce32de68488/32mcf2k4/fit_720"
  9. alt=""
  10. />
  11. <div class="name flex-item ml-24">
  12. <p>{{ username }}</p>
  13. <el-button class="follow mt-10">Follow</el-button>
  14. </div>
  15. </div>
  16. <div class="info flex-between mt-30">
  17. <p>{{ createdTime }}</p>
  18. <p class="flex-between">
  19. <el-icon size="24">
  20. <svg-icon icon-class="eye-open" color="#2a82e4" />
  21. </el-icon>
  22. <span>{{pageViewCnt}}</span>
  23. </p>
  24. <p class="flex-between">
  25. <span>Collect this</span>
  26. <el-icon size="30">
  27. <svg-icon icon-class="book" color="#2a82e4" />
  28. </el-icon>
  29. </p>
  30. </div>
  31. </div>
  32. <div class="content">
  33. <div class="content-main">
  34. <div class="rich-text" v-html="content"></div>
  35. </div>
  36. </div>
  37. <!-- <div class="list" :class="{show: scrollY > 200}">
  38. <div class="list-item">
  39. <p>Relavant Destinations</p>
  40. <div class="img mt-4">
  41. <v-lazy-image src="@/assets/images/banner-1.jpg" alt="" />
  42. <span class="tag">Dali</span>
  43. </div>
  44. </div>
  45. <div class="list-item">
  46. <p>Relavant Tours</p>
  47. <div class="img mt-4">
  48. <v-lazy-image src="@/assets/images/banner-1.jpg" alt="" />
  49. <span class="tag">Dali</span>
  50. </div>
  51. </div>
  52. </div> -->
  53. </template>
  54. <script setup>
  55. import VLazyImage from "v-lazy-image";
  56. import { useRouter } from "vue-router";
  57. import { useWindowScroll } from "@vueuse/core";
  58. import { AXIOS } from "@/common/http-commons";
  59. import { useSeoMeta } from 'unhead'
  60. const { y: scrollY } = useWindowScroll();
  61. console.log(scrollY.value);
  62. const title = ref("");
  63. const username = ref("");
  64. const content = ref("");
  65. const createdTime = ref("");
  66. const authorInfo = ref({});
  67. const authorProfileImageUrl = ref("");
  68. const pageViewCnt = ref(0)
  69. const siteData = reactive({
  70. title: 'My Awesome Blog',
  71. shortContent: 'Hichina Travel Blog'
  72. })
  73. // useHead({
  74. // title: computed(()=>'fuck'),
  75. // meta: [
  76. // { hid: 'Description', name: 'Description', content: removeHtmlTag(content.value).substring(0,50)},
  77. // { hid: 'Keywords', name: 'Keywords', content: title.value}
  78. // ]
  79. // })
  80. const route = useRoute();
  81. function getAuthorPrincipal() {
  82. AXIOS.get("/api/public/blog/blog-author-profile-image/" + route.params.blogId)
  83. .then(function (response) {
  84. console.log("blog author profile image");
  85. console.log(response.data);
  86. if (response.data.ok == true) {
  87. authorProfileImageUrl.value = response.data.data;
  88. } else {
  89. ElNotification({
  90. title: "Error",
  91. message: response.data.message,
  92. type: "error",
  93. });
  94. }
  95. })
  96. .catch(function (error) {
  97. console.log(error);
  98. });
  99. }
  100. function loadBlogDetail() {
  101. AXIOS.get("/api/public/blog/" + route.params.blogId)
  102. .then((response) => {
  103. title.value = response.data.data.title;
  104. username.value = response.data.data.authorName;
  105. content.value = response.data.data.content;
  106. createdTime.value = response.data.data.createdTime;
  107. // set head meta for seo
  108. // Set the title meta tag
  109. siteData.title = title.value;
  110. siteData.shortContent = removeHtmlTag(content.value).substring(0,50)
  111. useSeoMeta({
  112. title: siteData.title,
  113. description: siteData.shortContent,
  114. ogDescription: siteData.shortContent,
  115. ogTitle: siteData.title,
  116. ogImage: 'https://www.hichinatravel.com/static/png/name-67280b81.png',
  117. twitterCard: 'summary_large_image',
  118. })
  119. })
  120. .catch((e) => {
  121. console.log("get blog detail err");
  122. console.log(e);
  123. });
  124. }
  125. function removeHtmlTag(input){
  126. var div = document.createElement("div");
  127. div.innerHTML = input;
  128. var text = div.textContent || div.innerText || "";
  129. return text;
  130. }
  131. function logView(){
  132. AXIOS.post("/api/public/pagestats/view-blog/"+route.params.blogId)
  133. .then((res) => {
  134. console.log("view cnt of this blog:")
  135. console.log(res.data);
  136. pageViewCnt.value = res.data.data
  137. })
  138. .catch((err) => {
  139. console.error("Error:", err);
  140. });
  141. }
  142. onMounted(() => {
  143. logView()
  144. getAuthorPrincipal();
  145. loadBlogDetail();
  146. });
  147. </script>
  148. <style scoped lang="scss">
  149. .content-main,
  150. .main {
  151. min-width: 560px;
  152. width: 70%;
  153. padding-left: 100px;
  154. margin: 0 auto;
  155. }
  156. .main {
  157. padding-top: 105px;
  158. }
  159. .title {
  160. color: rgba(80, 80, 80, 1);
  161. font-size: 3em;
  162. font-weight: bold;
  163. }
  164. .logo {
  165. width: 104px;
  166. height: 104px;
  167. border-radius: 50%;
  168. }
  169. .name {
  170. color: rgba(80, 80, 80, 1);
  171. font-size: 26px;
  172. }
  173. .follow {
  174. width: 157px;
  175. height: 30px;
  176. color: rgba(255, 255, 255, 1);
  177. background-color: rgba(42, 130, 228, 1);
  178. border-radius: 5px;
  179. font-size: 19px;
  180. line-height: 30px;
  181. text-align: center;
  182. }
  183. .info {
  184. color: rgba(80, 80, 80, 1);
  185. font-size: 27px;
  186. }
  187. .content {
  188. margin: 40px 17px 0;
  189. border-top: 1px solid #e5e5e5;
  190. }
  191. .rich-text {
  192. color: rgba(80, 80, 80, 1);
  193. font-size: 22px;
  194. }
  195. .content-main {
  196. padding-top: 28px;
  197. img {
  198. width: 100%;
  199. }
  200. }
  201. .list {
  202. position: fixed;
  203. left: -251px;
  204. bottom: 300px;
  205. transition: 0.3s;
  206. &.show {
  207. left: 20px;
  208. }
  209. &-item {
  210. margin-bottom: 33px;
  211. color: rgba(42, 130, 228, 1);
  212. font-size: 17px;
  213. text-align: center;
  214. }
  215. .img {
  216. position: relative;
  217. width: 201px;
  218. height: 155px;
  219. img {
  220. width: 100%;
  221. height: 100%;
  222. }
  223. .tag {
  224. position: absolute;
  225. left: 0;
  226. top: 25px;
  227. width: 56px;
  228. height: 30px;
  229. color: rgba(255, 255, 255, 1);
  230. background-color: rgba(42, 130, 228, 1);
  231. border-radius: 4px;
  232. font-size: 12px;
  233. line-height: 30px;
  234. text-align: center;
  235. }
  236. }
  237. }
  238. </style>