detail.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <view class="agreement-detail-page">
  3. <!-- 顶部渐变背景区域 -->
  4. <view class="header-bg" :style="{ paddingTop: statusBarHeight + 'px' }">
  5. <view class="header-content">
  6. <view class="back-btn" @click="handleBack">
  7. <text class="back-icon">‹</text>
  8. </view>
  9. <text class="header-title">{{ pageTitle }}</text>
  10. <view class="placeholder"></view>
  11. </view>
  12. </view>
  13. <!-- 页面内容 -->
  14. <view class="page-content">
  15. <scroll-view scroll-y class="content-scroll">
  16. <view class="agreement-content">
  17. <rich-text :nodes="agreementContent"></rich-text>
  18. </view>
  19. </scroll-view>
  20. </view>
  21. </view>
  22. </template>
  23. <script setup>
  24. import { ref, computed, onMounted } from 'vue'
  25. import { useI18n } from 'vue-i18n'
  26. import { getAgreementContent } from '@/apis/setting'
  27. const { t, locale } = useI18n()
  28. // 状态栏高度
  29. const statusBarHeight = ref(0)
  30. // 协议类型
  31. const agreementType = ref('')
  32. // 协议内容
  33. const agreementContent = ref('')
  34. // 加载状态
  35. const loading = ref(false)
  36. // 页面标题
  37. const pageTitle = computed(() => {
  38. return agreementType.value === 'user' ? '用户协议' : '隐私政策'
  39. })
  40. onMounted(async () => {
  41. // 获取系统信息
  42. const systemInfo = uni.getSystemInfoSync()
  43. statusBarHeight.value = systemInfo.statusBarHeight || 0
  44. // 获取页面参数
  45. const pages = getCurrentPages()
  46. const currentPage = pages[pages.length - 1]
  47. agreementType.value = currentPage.options.type || 'user'
  48. console.log('协议详情页面已加载, 类型:', agreementType.value)
  49. // 获取协议内容
  50. await fetchAgreementContent()
  51. })
  52. // 返回上一页
  53. const handleBack = () => {
  54. const pages = getCurrentPages()
  55. if (pages.length > 1) {
  56. uni.navigateBack()
  57. } else {
  58. uni.reLaunch({
  59. url: '/pages/index'
  60. })
  61. }
  62. }
  63. // 获取协议内容
  64. const fetchAgreementContent = async () => {
  65. try {
  66. loading.value = true
  67. // 显示加载提示
  68. uni.showLoading({
  69. title: '加载中...',
  70. mask: true
  71. })
  72. // 调用API获取内容
  73. const response = await getAgreementContent(agreementType.value)
  74. if (response && response.code === 200 && response.data && response.data.content) {
  75. // 解析JSON字符串
  76. try {
  77. const contentObj = JSON.parse(response.data.content)
  78. // 根据当前语言环境选择对应的内容
  79. const currentLocale = locale.value // 'zh-CN' 或 'en-US'
  80. const localeKey = currentLocale.replace('-', '_') // 转换为 'zh_CN' 或 'en_US'
  81. // 优先使用当前语言,如果不存在则使用中文,再不存在则使用任意可用语言
  82. agreementContent.value = contentObj[localeKey] ||
  83. contentObj['zh_CN'] ||
  84. contentObj['en_US'] ||
  85. Object.values(contentObj)[0] ||
  86. ''
  87. console.log('已加载协议内容,语言:', localeKey)
  88. } catch (parseError) {
  89. console.error('解析协议内容JSON失败:', parseError)
  90. // 如果解析失败,尝试直接使用原始内容
  91. agreementContent.value = response.data.content
  92. }
  93. } else {
  94. throw new Error(response?.msg || '获取失败')
  95. }
  96. } catch (error) {
  97. console.error('获取协议内容失败:', error)
  98. uni.showToast({
  99. title: error.message || '获取协议内容失败',
  100. icon: 'none',
  101. duration: 2000
  102. })
  103. // 失败时显示默认内容
  104. agreementContent.value = getDefaultContent()
  105. } finally {
  106. loading.value = false
  107. uni.hideLoading()
  108. }
  109. }
  110. // 获取默认内容(API失败时的后备方案)
  111. const getDefaultContent = () => {
  112. if (agreementType.value === 'user') {
  113. return `
  114. <div style="padding: 20px; line-height: 1.8; color: #333;">
  115. <h2 style="text-align: center; color: #1ec9c9; margin-bottom: 20px;">用户服务协议</h2>
  116. <p>协议内容加载失败,请稍后重试。</p>
  117. </div>
  118. `
  119. } else {
  120. return `
  121. <div style="padding: 20px; line-height: 1.8; color: #333;">
  122. <h2 style="text-align: center; color: #1ec9c9; margin-bottom: 20px;">隐私政策</h2>
  123. <p>协议内容加载失败,请稍后重试。</p>
  124. </div>
  125. `
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .agreement-detail-page {
  131. width: 100%;
  132. height: 100vh;
  133. display: flex;
  134. flex-direction: column;
  135. background-color: #f5f5f5;
  136. // 顶部渐变背景
  137. .header-bg {
  138. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  139. .header-content {
  140. height: 88rpx;
  141. display: flex;
  142. align-items: center;
  143. justify-content: space-between;
  144. padding: 0 24rpx;
  145. .back-btn {
  146. width: 60rpx;
  147. height: 60rpx;
  148. display: flex;
  149. align-items: center;
  150. justify-content: flex-start;
  151. .back-icon {
  152. font-size: 56rpx;
  153. color: #ffffff;
  154. font-weight: 300;
  155. }
  156. }
  157. .header-title {
  158. flex: 1;
  159. text-align: center;
  160. font-size: 32rpx;
  161. font-weight: 600;
  162. color: #ffffff;
  163. }
  164. .placeholder {
  165. width: 60rpx;
  166. }
  167. }
  168. }
  169. // 页面内容
  170. .page-content {
  171. flex: 1;
  172. display: flex;
  173. flex-direction: column;
  174. overflow: hidden;
  175. .content-scroll {
  176. flex: 1;
  177. width: 100%;
  178. height: 100%;
  179. .agreement-content {
  180. padding: 32rpx 24rpx;
  181. ::v-deep h1 {
  182. font-size: 40rpx;
  183. font-weight: 700;
  184. color: #333333;
  185. margin-bottom: 32rpx;
  186. line-height: 1.5;
  187. }
  188. ::v-deep h2 {
  189. font-size: 36rpx;
  190. font-weight: 600;
  191. color: #333333;
  192. margin: 40rpx 0 24rpx;
  193. line-height: 1.5;
  194. }
  195. ::v-deep h3 {
  196. font-size: 32rpx;
  197. font-weight: 600;
  198. color: #333333;
  199. margin: 32rpx 0 20rpx;
  200. line-height: 1.5;
  201. }
  202. ::v-deep p {
  203. font-size: 28rpx;
  204. line-height: 1.8;
  205. color: #666666;
  206. margin-bottom: 24rpx;
  207. text-align: justify;
  208. }
  209. ::v-deep ul, ::v-deep ol {
  210. padding-left: 40rpx;
  211. margin-bottom: 24rpx;
  212. li {
  213. font-size: 28rpx;
  214. line-height: 1.8;
  215. color: #666666;
  216. margin-bottom: 16rpx;
  217. }
  218. }
  219. ::v-deep strong, ::v-deep b {
  220. font-weight: 600;
  221. color: #333333;
  222. }
  223. ::v-deep a {
  224. color: #1ec9c9;
  225. text-decoration: underline;
  226. }
  227. ::v-deep div {
  228. font-size: 28rpx;
  229. line-height: 1.8;
  230. color: #666666;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. </style>