API.uvue 5.1 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2
<template>
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
DCloud-WZF's avatar
DCloud-WZF 已提交
4 5
  <!-- #endif -->
    <view class="uni-container">
6
      <view v-if="!hasLeftWin" class="uni-header-logo">
DCloud-WZF's avatar
DCloud-WZF 已提交
7 8
        <image class="uni-header-image" src="/static/apiIndex.png"></image>
      </view>
9
      <view v-if="!hasLeftWin" class="uni-text-box">
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11 12 13
        <text class="hello-text">以下将演示uni-app接口能力,详细文档见:</text>
        <u-link :href="'https://uniapp.dcloud.io/uni-app-x/api/'" :text="'https://uniapp.dcloud.io/uni-app-x/api/'"
          :inWhiteList="true"></u-link>
      </view>
14
      <uni-collapse>
DCloud-WZF's avatar
DCloud-WZF 已提交
15
        <uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem.id" :title="menuItem.name"
16
          class="item">
DCloud-WZF's avatar
DCloud-WZF 已提交
17
          <template v-for="childMenuItem in menuItem.items" :key="childMenuItem.id">
18 19 20 21 22 23 24 25 26 27
            <view v-if="childMenuItem.items.length==0" style="padding-left: 18px;"
              :class="{'uni-navigate-item':childMenuItem.path !== 'set-tab-bar' || windowWidth <= 768}"
              hover-class="is--active"
              @click="goPage(`/${childMenuItem.path}`)">
              <template v-if="childMenuItem.path !== 'set-tab-bar' || windowWidth <= 768">
                <text class="uni-navigate-text"
                  :class="{'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin}"
                  >{{ childMenuItem.style["navigationBarTitleText"] }}</text>
                <image :src="arrowRightIcon" class="uni-icon-size"></image>
              </template>
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
            </view>
            <uni-collapse v-else style="width: 100%">
              <uni-collapse-item :title="childMenuItem.name" class="item"
                style="margin-bottom: 0; padding-left: 5px; padding-right: 5px">
                <view style="padding-left: 18px" class="uni-navigate-item" hover-class="is--active"
                  v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem!.path"
                  @click="goPage(`/${grandChildMenuItem.path}`)">
                  <text class="uni-navigate-text" :class="{
                      'left-win-active':
                        leftWinActive === grandChildMenuItem.path && hasLeftWin,
                    }">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
                  <image :src="arrowRightIcon" class="uni-icon-size"></image>
                </view>
              </uni-collapse-item>
            </uni-collapse>
          </template>
44 45 46 47 48 49 50
        </uni-collapse-item>
      </uni-collapse>
      <view v-if="!hasLeftWin" ref="pop" @click="hidePop()" class="popup">
        <view style="width: 90%; background-color: white" @click="stopClickPop">
          <api-set-tabbar></api-set-tabbar>
        </view>
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
51 52 53 54 55 56 57
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
58 59 60
  import { generateMenu } from './generateMenu.uts'
  import { MenuItem } from './generateMenu.uts'
  const menu = generateMenu('pages/API')
61
  import { state } from '@/store/index.uts'
DCloud-WZF's avatar
DCloud-WZF 已提交
62 63 64
  export default {
    data() {
      return {
DCloud-WZF's avatar
DCloud-WZF 已提交
65
        menu: menu as MenuItem[],
DCloud-WZF's avatar
DCloud-WZF 已提交
66 67
        arrowRightIcon: '/static/icons/arrow-right.png',
      }
68 69
    },
    computed: {
70
      hasLeftWin() : boolean {
71 72
        return !state.noMatchLeftWindow
      },
73
      leftWinActive() : string {
74
        return state.leftWinActive.slice(1)
75 76 77
      },
      windowWidth() : number {
        return uni.getSystemInfoSync().windowWidth
78
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
79 80
    },
    methods: {
81
      goPage(url : string) {
82 83
        if (url == '/set-tab-bar') {
          this.showPop()
84
        } else {
85
          if(this.hasLeftWin) {
86 87 88
            uni.reLaunch({ url })
          } else {
            uni.navigateTo({ url })
89
          }
90
        }
91
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
92 93 94 95 96 97 98 99 100
      showPop: function () {
        (this.$refs["pop"] as UniElement).style.setProperty("display", "flex")
      },
      hidePop: function () {
        (this.$refs["pop"] as UniElement).style.setProperty("display", "none")
      },
      stopClickPop: function (e : PointerEvent) {
        e.stopPropagation() //点击到pop的非灰色区域,拦截点击事件
      }
101 102
    },
    // #ifdef WEB
103 104 105 106 107
    watch: {
      $route: {
        immediate: true,
        handler(newRoute) {
          if (newRoute.matched.length) {
108
            const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.items.some(item => this.leftWinActive && this.leftWinActive === item?.path))
109 110 111 112 113
            if (activeCategoryIndex > -1) {
              this.$nextTick(() => {
                ((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true)
              })
            }
114 115 116
          }
        }
      }
117
    },
118
    // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
119 120 121 122 123 124 125 126 127 128
  }
</script>

<style>
  .item {
    margin-bottom: 12px;
  }

  .popup {
    position: fixed;
129 130 131 132
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
DCloud-WZF's avatar
DCloud-WZF 已提交
133 134 135 136 137
    align-items: center;
    justify-content: center;
    display: none;
    background-color: rgba(16, 16, 16, 0.5);
  }
138
</style>