component.uvue 5.2 KB
Newer Older
1 2
<template>
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1;" 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>
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 28
            <view v-if="childMenuItem.items.length==0" style="padding-left: 18px" class="uni-navigate-item"
              hover-class="is--active" @click="goPage(`/${childMenuItem.path}`)">
              <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>
            </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"
DCloud-WZF's avatar
DCloud-WZF 已提交
29
                  v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem.path"
30 31 32 33 34 35 36 37 38 39
                  @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>
40
        </uni-collapse-item>
41 42
      </uni-collapse>

43
      <!-- #ifdef UNI-APP-X && APP -->
44 45 46 47 48 49 50 51 52
      <uni-upgrade-center-app ref="upgradePopup" @show="upgradePopupShow" @close="upgradePopupClose" />
      <!-- #endif -->
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
53 54 55
  import { generateMenu } from './generateMenu.uts'
  import { MenuItem } from './generateMenu.uts'
  const menu = generateMenu('pages/component')
56
  // #ifdef UNI-APP-X && APP
57 58
  import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
  // #endif
59
  import { state } from '@/store/index.uts'
60 61 62
  export default {
    data() {
      return {
DCloud-WZF's avatar
DCloud-WZF 已提交
63
        menu: menu as MenuItem[],
64 65 66
        arrowRightIcon: '/static/icons/arrow-right.png' as string.ImageURIString,
        pageHiden: false
      }
67 68 69 70 71 72 73 74 75
    },
    computed: {
      hasLeftWin() : boolean {
        return !state.noMatchLeftWindow
      },
      leftWinActive() : string {
        return state.leftWinActive.slice(1)
      }
    },
76
    methods: {
DCloud-WZF's avatar
DCloud-WZF 已提交
77
      goPage(url : string) {
DCloud-WZF's avatar
DCloud-WZF 已提交
78
        if (this.hasLeftWin) {
DCloud-WZF's avatar
DCloud-WZF 已提交
79 80 81
          uni.reLaunch({ url })
        } else {
          uni.navigateTo({ url })
82
        }
83
      },
84
      // #ifdef UNI-APP-X && APP
85
      upgradePopupShow() {
86 87 88 89 90 91 92 93 94 95
        console.log('upgradePopup show');
        if (!this.pageHiden) {
          uni.hideTabBar()?.catch(_ => { })
        }
      }
      , upgradePopupClose() {
        console.log('upgradePopup close');
        uni.showTabBar()?.catch(_ => { })
      }
      // #endif
96 97 98 99 100 101 102
    },
    // #ifdef WEB
    watch: {
      $route: {
        immediate: true,
        handler(newRoute) {
          if (newRoute.matched.length) {
103
            const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.items.some(item => this.leftWinActive && this.leftWinActive === item?.path))
104 105 106 107 108 109 110 111 112
            if (activeCategoryIndex > -1) {
              this.$nextTick(() => {
                ((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true)
              })
            }
          }
        }
      }
    },
113
    // #endif
114
    onReady() {
115
      // #ifdef UNI-APP-X && APP
116 117 118 119 120 121 122 123 124 125 126 127 128
      uni.getPrivacySetting({
        success(res) {
          if (res.needAuthorization) {
            uni.onPrivacyAuthorizationChange((res) => {
              if (!res.needAuthorization) {
                checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
              }
            })
          } else {
            checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
          }
        }
      })
129
      // #endif
130
    },
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    onShow() {
      this.pageHiden = false
    },
    onHide() {
      this.pageHiden = true
    },
    beforeUnmount() {
      uni.showTabBar()?.catch(_ => { })
    }
  }
</script>

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