detail.vue 6.7 KB

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