agreement.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="agreement-container">
  3. <!-- <view class="agreement-header">
  4. <view class="back-btn" @click="goBack">
  5. <text class="iconfont icon-back">&#xe679;</text>
  6. </view>
  7. <view class="title">用户协议</view>
  8. <view class="placeholder"></view>
  9. </view> -->
  10. <scroll-view scroll-y class="agreement-content">
  11. <!-- <view class="agreement-title">《用户协议》</view> -->
  12. <!-- 使用v-if控制加载状态 -->
  13. <view v-if="loading" class="loading">
  14. <text>加载中...</text>
  15. </view>
  16. <!-- 使用v-else-if显示错误信息 -->
  17. <view v-else-if="error" class="error">
  18. <text>{{errorMsg}}</text>
  19. <button class="retry-btn" @click="fetchAgreement">重新加载</button>
  20. </view>
  21. <!-- 使用v-else和v-html动态渲染协议内容 -->
  22. <rich-text :nodes="agreementContent"></rich-text>
  23. </scroll-view>
  24. </view>
  25. </template>
  26. <script>
  27. import { getUserAgreement } from '@/api/user';
  28. import { apiBaseUrl } from '@/common/config.js';
  29. export default {
  30. data() {
  31. return {
  32. agreementContent: '',
  33. loading: true,
  34. error: false,
  35. errorMsg: '加载失败,请重试'
  36. }
  37. },
  38. onLoad() {
  39. this.fetchAgreement();
  40. },
  41. methods: {
  42. goBack() {
  43. uni.navigateBack();
  44. },
  45. async fetchAgreement() {
  46. this.loading = true;
  47. this.error = false;
  48. const res = await uni.request({
  49. url: `${apiBaseUrl}/api/public/agreements/terms_of_service/`,
  50. method: 'GET',
  51. });
  52. console.log(res);
  53. if(res.statusCode==200){
  54. this.loading = false;
  55. this.agreementContent = res.data.content || '';
  56. }
  57. /* getUserAgreement()
  58. .then(res => {
  59. console.log(res);
  60. this.loading = false;
  61. // 假设API返回的数据中有content字段包含协议内容
  62. this.agreementContent = res.content || '';
  63. console.log(this.agreementContent);
  64. })
  65. .catch(err => {
  66. console.error('获取用户协议失败:', err);
  67. this.error = true;
  68. this.errorMsg = '网络异常,请稍后重试';
  69. })
  70. .finally(() => {
  71. this.loading = false;
  72. }); */
  73. }
  74. }
  75. }
  76. </script>
  77. <style>
  78. .agreement-container {
  79. /* display: flex;
  80. flex-direction: column; */
  81. height: 100vh;
  82. background-color: #fff;
  83. }
  84. .agreement-header {
  85. display: flex;
  86. align-items: center;
  87. justify-content: space-between;
  88. height: 90rpx;
  89. background-color: #fff;
  90. padding: 0 30rpx;
  91. position: relative;
  92. border-bottom: 1rpx solid #eee;
  93. }
  94. .back-btn {
  95. width: 60rpx;
  96. height: 60rpx;
  97. display: flex;
  98. align-items: center;
  99. justify-content: center;
  100. }
  101. .icon-back {
  102. font-size: 40rpx;
  103. color: #333;
  104. }
  105. .title {
  106. font-size: 34rpx;
  107. font-weight: 500;
  108. color: #333;
  109. }
  110. .placeholder {
  111. width: 60rpx;
  112. }
  113. .agreement-content {
  114. width: 100%;
  115. padding: 20rpx 30rpx;
  116. box-sizing: border-box;
  117. background-color: #fff;
  118. }
  119. .agreement-title {
  120. font-size: 36rpx;
  121. font-weight: bold;
  122. text-align: center;
  123. margin-bottom: 40rpx;
  124. color: #333;
  125. }
  126. .section {
  127. margin-bottom: 30rpx;
  128. }
  129. .section-title {
  130. font-size: 32rpx;
  131. font-weight: 500;
  132. color: #333;
  133. margin-bottom: 20rpx;
  134. }
  135. .section-content {
  136. font-size: 28rpx;
  137. color: #666;
  138. line-height: 1.6;
  139. }
  140. .paragraph {
  141. display: block;
  142. margin-bottom: 20rpx;
  143. text-align: justify;
  144. }
  145. .loading, .error {
  146. display: flex;
  147. flex-direction: column;
  148. align-items: center;
  149. justify-content: center;
  150. padding: 40rpx;
  151. color: #666;
  152. font-size: 28rpx;
  153. }
  154. .error {
  155. color: #ff4d4f;
  156. }
  157. .retry-btn {
  158. margin-top: 20rpx;
  159. padding: 10rpx 30rpx;
  160. background-color: #1890ff;
  161. color: #fff;
  162. border-radius: 8rpx;
  163. font-size: 28rpx;
  164. }
  165. </style>