index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <view class="protocol-page">
  3. <view class="protocol-nav">
  4. <view class="protocol-nav__bar">
  5. <view
  6. class="protocol-nav__back"
  7. hover-class="protocol-nav__back--hover"
  8. @click.stop="goBack"
  9. >
  10. <text class="protocol-nav__back-icon">‹</text>
  11. </view>
  12. <text class="protocol-nav__title">{{ doc.title }}</text>
  13. <view class="protocol-nav__placeholder" />
  14. </view>
  15. </view>
  16. <view class="protocol-body">
  17. <view class="protocol-meta">更新日期:{{ doc.updatedAt }}</view>
  18. <view
  19. v-for="(sec, idx) in doc.sections"
  20. :key="idx"
  21. class="protocol-section"
  22. >
  23. <view class="protocol-section__title">{{ sec.heading }}</view>
  24. <view
  25. v-for="(p, pIdx) in sec.paragraphs"
  26. :key="pIdx"
  27. class="protocol-section__p"
  28. >
  29. {{ p }}
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { getProtocol } from '../../utils/protocol-content.js'
  37. export default {
  38. data() {
  39. return {
  40. doc: getProtocol('user')
  41. }
  42. },
  43. onLoad(query) {
  44. const type = query && query.type === 'privacy' ? 'privacy' : 'user'
  45. this.doc = getProtocol(type)
  46. },
  47. methods: {
  48. goBack() {
  49. const pages = getCurrentPages()
  50. if (pages && pages.length > 1) {
  51. uni.navigateBack({
  52. delta: 1,
  53. fail: () => this.fallbackToLogin()
  54. })
  55. // H5 上偶发 navigateBack 既不成功也不进 fail,短暂后再确认是否离开
  56. setTimeout(() => {
  57. const curPages = getCurrentPages()
  58. const cur = curPages && curPages[curPages.length - 1]
  59. const route = (cur && (cur.route || (cur.$page && cur.$page.fullPath))) || ''
  60. if (String(route).indexOf('protocol') !== -1) {
  61. this.fallbackToLogin()
  62. }
  63. }, 280)
  64. return
  65. }
  66. this.fallbackToLogin()
  67. },
  68. fallbackToLogin() {
  69. uni.reLaunch({ url: '/pages/login/index' })
  70. }
  71. }
  72. }
  73. </script>