protocol.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view class="horizonal-tab">
  3. <scroll-view class="scroll-tab" scroll-x="true" scroll-with-animation>
  4. <block v-for="(item,index) in protocolList" :key="index">
  5. <view class="scroll-tab-item" :class="{'active': tabIndex==index}" @tap="toggleTab(index)">
  6. {{item.name}}
  7. <view class="scroll-tab-line"></view>
  8. </view>
  9. </block>
  10. </scroll-view>
  11. </view>
  12. <view class="text-area">
  13. <text>{{text}}</text>
  14. </view>
  15. </template>
  16. <script setup>
  17. import {
  18. reactive,
  19. ref
  20. } from 'vue'
  21. import {
  22. onLoad
  23. } from '@dcloudio/uni-app'
  24. let tabIndex = ref(0)
  25. let text = ref('')
  26. let baseUrl = 'https://test.cloud.boyuantech.net/protocol/'
  27. const protocolList = reactive([{
  28. name: '使用须知',
  29. content: ''
  30. }, {
  31. name: '隐私政策',
  32. content: ''
  33. }, {
  34. name: '个人信息授权',
  35. content: ''
  36. }, {
  37. name: '反恐法',
  38. content: ''
  39. }, {
  40. name: '旅游业治安管理办法',
  41. content: ''
  42. }])
  43. //切换选项卡
  44. async function toggleTab(index) {
  45. console.log('toggle index', index)
  46. tabIndex.value = index;
  47. if (!protocolList[index].content) {
  48. const res = await uni.request({
  49. url: baseUrl + protocolList[index].name + '.txt',
  50. method: 'GET'
  51. })
  52. if (res.statusCode === 200) {
  53. protocolList[index].content = res.data
  54. } else {
  55. uni.showToast({
  56. title: '请求失败!'
  57. })
  58. }
  59. }
  60. text.value = protocolList[index].content
  61. }
  62. onLoad(async () => {
  63. await toggleTab(0)
  64. })
  65. </script>
  66. <style lang="scss" scoped>
  67. .horizonal-tab {
  68. .scroll-tab {
  69. white-space: nowrap;
  70. border-bottom: 1rpx solid #ffffff;
  71. text-align: center;
  72. .scroll-tab-item {
  73. display: inline-block;
  74. text-align: center;
  75. margin: 20rpx 30rpx 0 30rpx;
  76. &.active {
  77. color: #a09cc4;
  78. }
  79. .scroll-tab-line {
  80. display: none; // 默认不显示
  81. border-bottom: 5rpx solid transparent;
  82. border-top: 5rpx solid transparent;
  83. border-radius: 20rpx;
  84. width: 100%;
  85. }
  86. &.active .scroll-tab-line {
  87. display: block;
  88. border-bottom-color: #a09cc4;
  89. border-top-color: #a09cc4;
  90. }
  91. }
  92. }
  93. }
  94. .text-area {
  95. background-color: #EFEFF4;
  96. }
  97. </style>