Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

71 righe
1.5 KiB

  1. <template>
  2. <view class="page">
  3. <view class="content-body" v-if="loaded">
  4. <mp-html :content="content" :tag-style="mpHtmlTagStyle" />
  5. </view>
  6. <view v-else class="loading">
  7. <u-loading-icon />
  8. </view>
  9. </view>
  10. </template>
  11. <script setup>
  12. import { ref } from 'vue'
  13. import { onLoad } from '@dcloudio/uni-app'
  14. import { get } from '@/utils/request.js'
  15. import mpHtml from '@/uni_modules/mp-html/components/mp-html/mp-html.vue'
  16. const mpHtmlTagStyle = {
  17. h1: 'font-size:inherit;font-weight:inherit;',
  18. h2: 'font-size:inherit;font-weight:inherit;',
  19. h3: 'font-size:inherit;font-weight:inherit;',
  20. h4: 'font-size:inherit;font-weight:inherit;',
  21. h5: 'font-size:inherit;font-weight:inherit;',
  22. h6: 'font-size:inherit;font-weight:inherit;',
  23. ol: 'list-style:none;margin:0;padding:0;',
  24. ul: 'list-style:none;margin:0;padding:0;',
  25. menu: 'list-style:none;'
  26. }
  27. const content = ref('')
  28. const loaded = ref(false)
  29. onLoad((options) => {
  30. const key = (options && options.key) || ''
  31. if (key) {
  32. loadContent(key)
  33. }
  34. })
  35. const loadContent = async (key) => {
  36. try {
  37. const res = await get('/api/content', { key })
  38. if (res.data) {
  39. content.value = res.data.content || ''
  40. uni.setNavigationBarTitle({ title: res.data.title || '' })
  41. }
  42. } catch (e) {
  43. console.error('获取内容失败', e)
  44. } finally {
  45. loaded.value = true
  46. }
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .page {
  51. min-height: 100vh;
  52. background: #fff;
  53. }
  54. .content-body {
  55. padding: 32rpx;
  56. }
  57. .loading {
  58. display: flex;
  59. justify-content: center;
  60. padding: 100rpx 0;
  61. }
  62. </style>