index.uvue 7.4 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view>
      <uni-collapse>
        <uni-collapse-item
          v-for="menu in menus"
          :key="menu.id"
          :title="menu.name"
          class="menu">
          <view v-for="(page, index) in menu.pages" :key="page.name">
            <view
              v-if="page.url"
              class="page-item"
              :class="{ 'first-child': index == 0 }"
              @click="goDetailPage(menu.id, page)">
              <text
                :class="{ 'text-disabled': page.enable == false }"
                class="text"
                >{{ page.name }}</text
              >
            </view>
            <template v-if="page.children">
              <uni-collapse style="flex: 1">
                <uni-collapse-item :title="page.name" class="menu">
                  <view
                    v-for="(child, index) in page.children"
                    :key="child.url"
                    class="page-item"
                    :class="{ 'first-child': index == 0 }"
                    @click="goDetailPage(`${menu.id}/${page.id}`, child)">
                    <text
                      :class="{ 'text-disabled': child.enable == false }"
                      class="text"
                      >{{ child.name }}</text
                    >
                  </view>
                </uni-collapse-item>
              </uni-collapse>
            </template>
          </view>
        </uni-collapse-item>
      </uni-collapse>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
import { setLifeCycleNum, state } from '@/store/index.uts'

type Page = {
  id: string,
  name : string
  enable?: boolean
  url ?: string
  children?: Page[]
}

type Menu = {
  id : string
  name : string
  pages : Page[]
  url ?: string
  enable ?: boolean
}

export default {
  data() {
    return {
      menus: [
        {
          id: 'app-instance',
          name: 'App 实例',
          pages: [
            {
              id: 'component',
              name: 'component',
              url: 'component/component',
            },
            {
              id: 'globalProperties',
              name: 'globalProperties',
              children: [
                {
                  id: 'globalProperties-options',
                  name: 'globalProperties  选项式 API',
DCloud-WZF's avatar
DCloud-WZF 已提交
90
                  url: 'globalProperties-options',
DCloud-WZF's avatar
DCloud-WZF 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
                },
                {
                  id: 'globalProperties-composition',
                  name: 'globalProperties 组合式 API',
                  url: 'globalProperties-composition',
                }
              ]
            },
            {
              id: 'use',
              name: 'use',
              children: [
                {
                  id: 'use-options',
                  name: 'use 选项式 API',
                  url: 'use-composition',
                },
                {
                  id: 'use-composition',
                  name: 'use 组合式 API',
                  url: 'use-composition',
                }
              ]
            }
          ] as Page[],
DCloud-WZF's avatar
DCloud-WZF 已提交
116 117 118 119 120 121 122 123 124 125
        },{
          id: 'component-instance',
          name: '组件 实例',
          pages: [
            {
              id: 'attrs',
              name: 'attrs',
              children: [
                {
                  id: 'attrs-options',
DCloud-WZF's avatar
DCloud-WZF 已提交
126
                  name: 'attrs 选项式 API',
DCloud-WZF's avatar
DCloud-WZF 已提交
127 128 129 130 131 132 133 134
                  url: 'attrs-options',
                },
                {
                  id: 'attrs-composition',
                  name: 'attrs 组合式 API',
                  url: 'attrs-composition',
                }
              ]
DCloud-WZF's avatar
DCloud-WZF 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
            },{
              id: 'data',
              name: 'data',
              children: [
                {
                  id: 'data-options',
                  name: 'data 选项式 API',
                  url: 'data-options',
                },
                {
                  id: 'data-composition',
                  name: 'data 组合式 API',
                  url: 'data-composition',
                }
              ]
DCloud-WZF's avatar
DCloud-WZF 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
            },{
              id: 'props',
              name: 'props',
              children: [
                {
                  id: 'props-options',
                  name: 'props 选项式 API',
                  url: 'props-options',
                },
                {
                  id: 'props-composition',
                  name: 'props 组合式 API',
                  url: 'props-composition',
                }
              ]
DCloud-WZF's avatar
DCloud-WZF 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
            },{
              id: 'el',
              name: '$el',
              children: [
                {
                  id: 'el-options',
                  name: '$el 选项式 API',
                  url: 'el-options',
                },
                {
                  id: 'el-composition',
                  name: '$el 组合式 API',
                  url: 'el-composition',
                }
              ]
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            },{
              id: 'options',
              name: '$options',
              children: [
                {
                  id: 'options-options',
                  name: '$options 选项式 API',
                  url: 'options-options',
                },
                {
                  id: 'options-composition',
                  name: '$options 组合式 API',
                  url: 'options-composition',
                }
              ]
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
            },{
              id: 'parent',
              name: '$parent',
              children: [
                {
                  id: 'parent-options',
                  name: '$parent 选项式 API',
                  url: 'parent-options',
                },
                {
                  id: 'parent-composition',
                  name: '$parent 组合式 API',
                  url: 'parent-composition',
                }
              ]
DCloud-WZF's avatar
DCloud-WZF 已提交
210
            },
DCloud-WZF's avatar
DCloud-WZF 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
            // #ifdef APP 
            {
              id: 'root',
              name: '$root',
              children: [
                {
                  id: 'root-options',
                  name: '$root 选项式 API',
                  url: 'root-options',
                },
                {
                  id: 'root-composition',
                  name: '$root 组合式 API',
                  url: 'root-composition',
                }
              ]
            },
            // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
229
          ] as Page[],
DCloud-WZF's avatar
DCloud-WZF 已提交
230 231 232 233 234
        }
      ] as Menu[],
    }
  },
  methods: {
DCloud-WZF's avatar
DCloud-WZF 已提交
235
    goDetailPage(parentUrl : string, page : Page) {
DCloud-WZF's avatar
DCloud-WZF 已提交
236 237 238 239 240 241 242 243
      if (page.enable == false) {
        uni.showToast({
          icon: 'none',
          title: '暂不支持',
        })
        return
      }
      uni.navigateTo({
DCloud-WZF's avatar
DCloud-WZF 已提交
244
        url: `/pages/${parentUrl}/${page.url}`,
DCloud-WZF's avatar
DCloud-WZF 已提交
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
      })
    },
    // 自动化测试
    setLifeCycleNum(num : number) {
      setLifeCycleNum(num)
    },
    // 自动化测试
    getLifeCycleNum() : number {
      return state.lifeCycleNum
    },
    // 自动化测试
    checkLaunchPath() : boolean {
      const app = getApp()
      return app.checkLaunchPath()
    },
  },
}
</script>

<style lang="scss">
.menu {
  border-bottom: 1px solid #dbd9d9;
  &.open {
    border-bottom: none;
  }
}
.page-item {
  padding: 12px 10px;
  border-bottom: 1px solid #dbd9d9;
  &.first-child {
    border-top: 1px solid #dbd9d9;
  }
  .text {
    font-size: 14px;
    color: #333;
    &.text-disabled {
      color: #999;
    }
  }
}
</style>