AppNews.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div class="lookDetailBox">
  3. <div>
  4. <h2>{{ detailForm.title }}</h2>
  5. <p>
  6. <span>发布时间:{{ detailForm.adddate }}</span>
  7. <span style="margin-left: 60px">阅读次数:{{ detailForm.readNum }}</span>
  8. </p>
  9. <div v-html="detailForm.content"></div>
  10. </div>
  11. </div>
  12. </template>
  13. <script setup lang="ts">
  14. import request from '@/config/axios'
  15. const detailForm = ref<{
  16. title: string
  17. adddate: string
  18. readNum: number
  19. content: string
  20. }>({
  21. title: '',
  22. adddate: '',
  23. readNum: 0,
  24. content: ''
  25. })
  26. async function queryDetailById(idStr: any): Promise<void> {
  27. const urlApi = `/adm/article/query/detailById`
  28. const params = {
  29. id: idStr
  30. }
  31. const result = await request.get({ url: urlApi, params })
  32. if (result) {
  33. detailForm.value = result
  34. }
  35. }
  36. function addReadNum(idStr: any) {
  37. const urlApi = `/adm/article/readNum/add`
  38. const params = {
  39. id: idStr
  40. }
  41. request.get({ url: urlApi, params })
  42. }
  43. const getUrlParams = (url: string) => {
  44. const arr1 = url.split('?')
  45. const arr2 = arr1[arr1.length - 1].split('&')
  46. const map = {}
  47. arr2.forEach((item) => {
  48. const arr3 = item.split('=')
  49. map[arr3[0]] = arr3[1]
  50. })
  51. return map
  52. }
  53. const query = getUrlParams(location.href) as {
  54. id: string
  55. }
  56. if (query.id) {
  57. queryDetailById(query.id)
  58. addReadNum(query.id)
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. .lookDetailBox {
  63. background-color: #fff;
  64. padding: 20px 0px;
  65. position: relative;
  66. > div {
  67. width: 60vw;
  68. margin: auto;
  69. > h2 {
  70. text-align: center;
  71. font-size: 36px;
  72. font-weight: bold;
  73. }
  74. > p {
  75. text-align: center;
  76. padding: 40px;
  77. color: #444452;
  78. border-bottom: solid 1px #d8d8d8;
  79. margin-bottom: 30px;
  80. }
  81. }
  82. }
  83. </style>