user-agreement.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="user-agreement">
  3. <view class="agreement-title">{{ agreementData.title }}</view>
  4. <view class="agreement-content">
  5. <u-parse
  6. v-if="articleHtml"
  7. :html="articleHtml"
  8. :autoscroll="true"
  9. :autoset-title="false"
  10. :tag-style="articleTagStyle"
  11. class="agreement-parse"
  12. />
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import { ARTICLE_CODE, ARTICLE_TITLE } from '@/utils/policy-config.js'
  18. import { ARTICLE_TAG_STYLE, formatArticleHtml } from '@/utils/article-content.js'
  19. export default {
  20. data() {
  21. return {
  22. articleCode: ARTICLE_CODE.orderAgreement,
  23. agreementData: {
  24. title: '',
  25. content: '',
  26. },
  27. articleHtml: '',
  28. articleTagStyle: ARTICLE_TAG_STYLE,
  29. }
  30. },
  31. onLoad(options) {
  32. const code = options.code || ARTICLE_CODE.orderAgreement
  33. let title = ARTICLE_TITLE.orderAgreement
  34. if (options.title) {
  35. title = decodeURIComponent(options.title)
  36. } else {
  37. Object.keys(ARTICLE_CODE).forEach((key) => {
  38. if (ARTICLE_CODE[key] === code && ARTICLE_TITLE[key]) {
  39. title = ARTICLE_TITLE[key]
  40. }
  41. })
  42. }
  43. this.articleCode = code
  44. uni.setNavigationBarTitle({ title })
  45. this.fetchAgreement()
  46. },
  47. methods: {
  48. fetchAgreement() {
  49. uni.showLoading({
  50. title: '加载中...',
  51. })
  52. uni.$u.http
  53. .get(`/token/getArticleOne?code=${this.articleCode}`)
  54. .then((res) => {
  55. if (res.code === 200) {
  56. this.agreementData = res.data
  57. this.articleHtml = formatArticleHtml(res.data.content || '')
  58. } else {
  59. this.$u.toast(res.msg || '获取协议内容失败')
  60. }
  61. })
  62. .finally(() => {
  63. uni.hideLoading()
  64. })
  65. },
  66. },
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .user-agreement {
  71. min-height: 100vh;
  72. background-color: $app-theme-bg-color;
  73. padding: 30rpx;
  74. padding-bottom: 50px;
  75. .agreement-title {
  76. font-size: 36rpx;
  77. font-weight: bold;
  78. color: $app-theme-text-color;
  79. text-align: center;
  80. margin-bottom: 40rpx;
  81. }
  82. .agreement-content {
  83. font-size: 28rpx;
  84. color: $app-theme-text-color;
  85. line-height: 1.8;
  86. width: 100%;
  87. overflow: hidden;
  88. }
  89. .agreement-parse {
  90. width: 100%;
  91. }
  92. }
  93. /* u-parse 表格外层滚动容器(autoscroll 生成的 div) */
  94. ::v-deep .agreement-parse {
  95. .interlayer {
  96. width: 100%;
  97. max-width: 100%;
  98. }
  99. .article-table-scroll,
  100. view[style*='overflow'] {
  101. width: 100% !important;
  102. max-width: 100%;
  103. overflow-x: auto !important;
  104. overflow-y: hidden;
  105. -webkit-overflow-scrolling: touch;
  106. }
  107. }
  108. </style>