component.uvue 4.4 KB
Newer Older
1 2
<template>
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
4 5
  <!-- #endif -->
    <view class="uni-container">
6
      <view v-if="!hasLeftWin" class="uni-header-logo">
7 8
        <image class="uni-header-image" src="/static/componentIndex.png"></image>
      </view>
9
      <view v-if="!hasLeftWin" class="uni-text-box">
10 11 12 13
        <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
14
      <uni-collapse>
15
        <uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
DCloud-WZF's avatar
DCloud-WZF 已提交
16 17 18
          class="item">
          <view v-for="page in menuItem.pages" :key="page!.path" class="uni-navigate-item" hover-class="is--active"
            @click="goPage(`/${page.path}`)">
19
            <text class="uni-navigate-text" :class="{'left-win-active': leftWinActive === page.path && hasLeftWin}">{{
DCloud-WZF's avatar
DCloud-WZF 已提交
20 21 22 23 24 25 26 27
                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}`)">
28
                <text class="uni-navigate-text" :class="{'left-win-active': leftWinActive === childPage.path && hasLeftWin}">{{
DCloud-WZF's avatar
DCloud-WZF 已提交
29 30 31 32 33 34 35
                    childPage.style["navigationBarTitleText"]
                  }}</text>
                <image :src="arrowRightIcon" class="uni-icon-size"></image>
              </view>
            </uni-collapse-item>
          </uni-collapse>
        </uni-collapse-item>
36 37
      </uni-collapse>

38
      <!-- #ifdef UNI-APP-X && APP -->
39 40 41 42 43 44 45 46 47
      <uni-upgrade-center-app ref="upgradePopup" @show="upgradePopupShow" @close="upgradePopupClose" />
      <!-- #endif -->
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
48 49 50
  import { generateMenu } from './generateMenu.uts'
  import { MenuItem } from './generateMenu.uts'
  const menu = generateMenu('pages/component')
51
  // #ifdef UNI-APP-X && APP
52 53
  import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
  // #endif
54
  import { state } from '@/store/index.uts'
55 56 57
  export default {
    data() {
      return {
58
        menu: menu as (MenuItem | null)[],
59 60 61
        arrowRightIcon: '/static/icons/arrow-right.png' as string.ImageURIString,
        pageHiden: false
      }
62 63
    },
    computed: {
Anne_LXM's avatar
Anne_LXM 已提交
64
      hasLeftWin():boolean{
65 66
        return !state.noMatchLeftWindow
      },
Anne_LXM's avatar
Anne_LXM 已提交
67
      leftWinActive():string{
68 69 70
        return state.leftWinActive.slice(1)
      }
    },
71
    methods: {
72 73 74
      goPage(url : string) {
        uni.navigateTo({ url })
      },
75
      // #ifdef UNI-APP-X && APP
76
      upgradePopupShow() {
77 78 79 80 81 82 83 84 85 86
        console.log('upgradePopup show');
        if (!this.pageHiden) {
          uni.hideTabBar()?.catch(_ => { })
        }
      }
      , upgradePopupClose() {
        console.log('upgradePopup close');
        uni.showTabBar()?.catch(_ => { })
      }
      // #endif
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    },
    // #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)
              })
            }
    			}
    		}
    	}
    },
    // #endif
105
    onReady() {
106
      // #ifdef UNI-APP-X && APP
107 108
      checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
      // #endif
109
    },
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    onShow() {
      this.pageHiden = false
    },
    onHide() {
      this.pageHiden = true
    },
    beforeUnmount() {
      uni.showTabBar()?.catch(_ => { })
    }
  }
</script>

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