API.uvue 4.3 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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
     <uni-collapse>
       <uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
         class="item">
         <view v-for="page in menuItem.pages" :key="page!.path" class="uni-navigate-item"  hover-class="is--active"
           @click="goPage(`/${page.path}`)">
           <text class="uni-navigate-text" :class="{'left-win-active': leftWinActive === page.path && hasLeftWin}">{{page.style["navigationBarTitleText"]}}</text>
           <image :src="arrowRightIcon" class="uni-icon-size"></image>
         </view>
         <uni-collapse style="width: 100%" v-for="childMenu in menuItem.children" :key="childMenu!.id">
           <uni-collapse-item :title="childMenu.name" class="item" style="margin-bottom: 0">
             <view class="uni-navigate-item" hover-class="is--active" v-for="childPage in childMenu.pages"
               :key="childPage!.path" @click="goPage(`/${childPage.path}`)">
               <text class="uni-navigate-text">{{
                   childPage.style["navigationBarTitleText"]
                 }}</text>
               <image :src="arrowRightIcon" class="uni-icon-size"></image>
             </view>
           </uni-collapse-item>
         </uni-collapse>
       </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>
39
     </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
40 41 42 43 44 45 46
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

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

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

  .popup {
    width: 100%;
    /* #ifdef APP */
    position: absolute;
    height: 100%;
    /* #endif */
    /* #ifndef APP */
    position: fixed;
    top: var(--window-top);
    bottom: var(--window-bottom);
    /* #endif */
    align-items: center;
    justify-content: center;
    display: none;
    background-color: rgba(16, 16, 16, 0.5);
  }
125
</style>