component.uvue 3.5 KB
Newer Older
1 2
<template>
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
4 5 6 7 8 9 10 11 12 13 14
  <!-- #endif -->
    <view class="uni-container">
      <view class="uni-header-logo">
        <image class="uni-header-image" src="/static/componentIndex.png"></image>
      </view>
      <view class="uni-text-box">
        <text class="hello-text">uni-app内置组件,展示样式仅供参考,文档详见:</text>
        <u-link :href="'https://uniapp.dcloud.io/uni-app-x/component/'"
          :text="'https://uniapp.dcloud.io/uni-app-x/component/'" :inWhiteList="true"></u-link>
      </view>
      <uni-collapse>
15
        <uni-collapse-item v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem!.name" class="item">
16
          <view v-for="page in menuItem!.pages" :key="page!.path" class="uni-navigate-item" hover-class="is--active"
17
            @click="goPage(`/${page!.path}`)">
18
            <text class="uni-navigate-text">{{
19
                page!.style["navigationBarTitleText"]
20
            }}</text>
21 22 23 24 25
            <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"
26
                :key="childPage!.path" @click="goPage(`/${childPage!.path}`)">
27
                <text class="uni-navigate-text">{{
28
                    childPage!.style["navigationBarTitleText"]
29
                }}</text>
30 31 32 33 34
                <image :src="arrowRightIcon" class="uni-icon-size"></image>
              </view>
            </uni-collapse-item>
          </uni-collapse>
        </uni-collapse-item>
35 36
      </uni-collapse>

37
      <!-- #ifdef UNI-APP-X && APP -->
38 39 40 41 42 43 44 45 46
      <uni-upgrade-center-app ref="upgradePopup" @show="upgradePopupShow" @close="upgradePopupClose" />
      <!-- #endif -->
    </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/component')
50
  // #ifdef UNI-APP-X && APP
51 52 53 54 55 56
  import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
  // #endif

  export default {
    data() {
      return {
57
        menu: menu as (MenuItem | null)[],
58 59 60 61 62
        arrowRightIcon: '/static/icons/arrow-right.png' as string.ImageURIString,
        pageHiden: false
      }
    },
    methods: {
63 64 65
      goPage(url : string) {
        uni.navigateTo({ url })
      },
66
      // #ifdef UNI-APP-X && APP
67
      upgradePopupShow() {
68 69 70 71 72 73 74 75 76 77 78 79
        console.log('upgradePopup show');
        if (!this.pageHiden) {
          uni.hideTabBar()?.catch(_ => { })
        }
      }
      , upgradePopupClose() {
        console.log('upgradePopup close');
        uni.showTabBar()?.catch(_ => { })
      }
      // #endif
    },
    onReady() {
80
      // #ifdef UNI-APP-X && APP
81 82
      checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
      // #endif
83
    },
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    onShow() {
      this.pageHiden = false
    },
    onHide() {
      this.pageHiden = true
    },
    beforeUnmount() {
      uni.showTabBar()?.catch(_ => { })
    }
  }
</script>

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