123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <template>
- <view class="horizonal-tab">
- <scroll-view class="scroll-tab" scroll-x="true" scroll-with-animation>
- <block v-for="(item,index) in protocolList" :key="index">
- <view class="scroll-tab-item" :class="{'active': tabIndex==index}" @tap="toggleTab(index)">
- {{item.name}}
- <view class="scroll-tab-line"></view>
- </view>
- </block>
- </scroll-view>
- </view>
- <view class="text-area">
- <text>{{text}}</text>
- </view>
- </template>
- <script setup>
- import {
- reactive,
- ref
- } from 'vue'
- import {
- onLoad
- } from '@dcloudio/uni-app'
- let tabIndex = ref(0)
- let text = ref('')
- let baseUrl = 'https://test.cloud.boyuantech.net/protocol/'
- const protocolList = reactive([{
- name: '使用须知',
- content: ''
- }, {
- name: '隐私政策',
- content: ''
- }, {
- name: '个人信息授权',
- content: ''
- }, {
- name: '反恐法',
- content: ''
- }, {
- name: '旅游业治安管理办法',
- content: ''
- }])
- //切换选项卡
- async function toggleTab(index) {
- console.log('toggle index', index)
- tabIndex.value = index;
- if (!protocolList[index].content) {
- const res = await uni.request({
- url: baseUrl + protocolList[index].name + '.txt',
- method: 'GET'
- })
- if (res.statusCode === 200) {
- protocolList[index].content = res.data
- } else {
- uni.showToast({
- title: '请求失败!'
- })
- }
- }
- text.value = protocolList[index].content
- }
- onLoad(async () => {
- await toggleTab(0)
- })
- </script>
- <style lang="scss">
- .horizonal-tab {
- .scroll-tab {
- white-space: nowrap;
- border-bottom: 1rpx solid #ffffff;
- text-align: center;
- .scroll-tab-item {
- display: inline-block;
- text-align: center;
- margin: 20rpx 30rpx 0 30rpx;
- &.active {
- color: #a09cc4;
- }
- .scroll-tab-line {
- display: none; // 默认不显示
- border-bottom: 5rpx solid transparent;
- border-top: 5rpx solid transparent;
- border-radius: 20rpx;
- width: 100%;
- }
- &.active .scroll-tab-line {
- display: block;
- border-bottom-color: #a09cc4;
- border-top-color: #a09cc4;
- }
- }
- }
- }
- .text-area {
- background-color: #EFEFF4;
- }
- </style>
|