CSS.uvue 3.8 KB
Newer Older
M
mehaotian 已提交
1
<template>
W
wanganxp 已提交
2
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
4
  <!-- #endif -->
W
wanganxp 已提交
5
    <view class="uni-container">
6
      <view v-if="!hasLeftWin" class="uni-header-logo">
W
wanganxp 已提交
7 8
        <image class="uni-header-image" src="/static/cssIndex.png"></image>
      </view>
9
      <view v-if="!hasLeftWin" class="uni-text-box">
W
wanganxp 已提交
10
        <text class="hello-text">uni-app x目前已支持的CSS属性,展示样式仅供参考,文档详见:</text>
W
wanganxp 已提交
11
        <u-link :href="'https://uniapp.dcloud.io/uni-app-x/css/'" :text="'https://uniapp.dcloud.io/uni-app-x/css/'"
W
wanganxp 已提交
12 13
          :inWhiteList="true"></u-link>
      </view>
14 15 16
      <uni-collapse>
        <uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem!.id" :title="menuItem.name"
          class="item">
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
          <template v-for="childMenuItem in menuItem.items" :key="childMenuItem!.id">
            <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"
                  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>
40
        </uni-collapse-item>
41
      </uni-collapse>
W
wanganxp 已提交
42
    </view>
43
  <!-- #ifdef APP -->
W
wanganxp 已提交
44 45
  </scroll-view>
  <!-- #endif -->
M
mehaotian 已提交
46 47
</template>

Y
yurj26 已提交
48
<script lang="uts">
49 50 51
  import { generateMenu } from './generateMenu.uts'
  import { MenuItem } from './generateMenu.uts'
  const menu = generateMenu('pages/CSS')
52
  import { state } from '@/store/index.uts'
W
wanganxp 已提交
53 54 55
  export default {
    data() {
      return {
56
        menu: menu as (MenuItem | null)[],
W
wanganxp 已提交
57 58
        arrowRightIcon: '/static/icons/arrow-right.png',
      }
59 60 61 62 63 64 65 66
    },
    computed: {
      hasLeftWin() : boolean {
        return !state.noMatchLeftWindow
      },
      leftWinActive() : string {
        return state.leftWinActive.slice(1)
      }
W
wanganxp 已提交
67 68
    },
    methods: {
69 70 71
      goPage(url : string) {
        uni.navigateTo({ url })
      },
72 73 74 75 76 77 78
    },
    // #ifdef WEB
    watch: {
      $route: {
        immediate: true,
        handler(newRoute) {
          if (newRoute.matched.length) {
79
            const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.items.some(item => this.leftWinActive && this.leftWinActive === item?.path))
80 81 82 83 84 85 86 87 88
            if (activeCategoryIndex > -1) {
              this.$nextTick(() => {
                ((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex]).$callMethod('openCollapse', true)
              })
            }
          }
        }
      }
    },
89
    // #endif
W
wanganxp 已提交
90
  }
M
mehaotian 已提交
91 92 93
</script>

<style>
W
wanganxp 已提交
94 95 96
  .item {
    margin-bottom: 12px;
  }
Y
yurj26 已提交
97
</style>