index.uvue 10.3 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view>
      <uni-collapse>
7
        <uni-collapse-item v-for="menu in menus" :key="menu.id" :title="menu.name" class="menu">
DCloud-WZF's avatar
DCloud-WZF 已提交
8
          <view v-for="(page, index) in menu.pages" :key="page.name">
9 10
            <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
11 12 13 14 15 16 17 18 19
            </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 }"
20 21 22
                    @click="goDetailPage(`${menu.id}/${page.id}`, child)"
                  >
                    <text :class="{ 'text-disabled': child.enable == false }" class="text">{{ child.name }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36
                  </view>
                </uni-collapse-item>
              </uni-collapse>
            </template>
          </view>
        </uni-collapse-item>
      </uni-collapse>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
37
import { setLifeCycleNum, state } from '@/store/index.uts';
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39

type Page = {
40 41 42 43 44 45
  id: string;
  name: string;
  enable?: boolean;
  url?: string;
  children?: Page[];
};
DCloud-WZF's avatar
DCloud-WZF 已提交
46 47

type Menu = {
48 49 50 51 52 53
  id: string;
  name: string;
  pages: Page[];
  url?: string;
  enable?: boolean;
};
DCloud-WZF's avatar
DCloud-WZF 已提交
54 55 56 57 58 59 60 61 62 63 64 65

export default {
  data() {
    return {
      menus: [
        {
          id: 'app-instance',
          name: 'App 实例',
          pages: [
            {
              id: 'component',
              name: 'component',
66
              url: 'component/component'
DCloud-WZF's avatar
DCloud-WZF 已提交
67 68 69 70 71 72 73 74
            },
            {
              id: 'globalProperties',
              name: 'globalProperties',
              children: [
                {
                  id: 'globalProperties-options',
                  name: 'globalProperties  选项式 API',
75
                  url: 'globalProperties-options'
DCloud-WZF's avatar
DCloud-WZF 已提交
76 77 78 79
                },
                {
                  id: 'globalProperties-composition',
                  name: 'globalProperties 组合式 API',
80
                  url: 'globalProperties-composition'
DCloud-WZF's avatar
DCloud-WZF 已提交
81 82 83 84 85 86 87 88 89 90
                }
              ]
            },
            {
              id: 'use',
              name: 'use',
              children: [
                {
                  id: 'use-options',
                  name: 'use 选项式 API',
91
                  url: 'use-composition'
DCloud-WZF's avatar
DCloud-WZF 已提交
92 93 94 95
                },
                {
                  id: 'use-composition',
                  name: 'use 组合式 API',
96
                  url: 'use-composition'
DCloud-WZF's avatar
DCloud-WZF 已提交
97 98 99
                }
              ]
            }
100
          ] as Page[]
101
        },
102
        {
DCloud-WZF's avatar
DCloud-WZF 已提交
103 104 105 106 107 108 109 110 111
          id: 'component-instance',
          name: '组件 实例',
          pages: [
            {
              id: 'attrs',
              name: 'attrs',
              children: [
                {
                  id: 'attrs-options',
DCloud-WZF's avatar
DCloud-WZF 已提交
112
                  name: 'attrs 选项式 API',
113
                  url: 'attrs-options'
DCloud-WZF's avatar
DCloud-WZF 已提交
114 115 116 117
                },
                {
                  id: 'attrs-composition',
                  name: 'attrs 组合式 API',
118
                  url: 'attrs-composition'
DCloud-WZF's avatar
DCloud-WZF 已提交
119 120
                }
              ]
121 122
            },
            {
DCloud-WZF's avatar
DCloud-WZF 已提交
123 124 125 126 127 128
              id: 'data',
              name: 'data',
              children: [
                {
                  id: 'data-options',
                  name: 'data 选项式 API',
129
                  url: 'data-options'
DCloud-WZF's avatar
DCloud-WZF 已提交
130 131 132 133
                },
                {
                  id: 'data-composition',
                  name: 'data 组合式 API',
134
                  url: 'data-composition'
DCloud-WZF's avatar
DCloud-WZF 已提交
135 136
                }
              ]
137 138
            },
            {
DCloud-WZF's avatar
DCloud-WZF 已提交
139 140 141 142 143 144
              id: 'props',
              name: 'props',
              children: [
                {
                  id: 'props-options',
                  name: 'props 选项式 API',
145
                  url: 'props-options'
DCloud-WZF's avatar
DCloud-WZF 已提交
146 147 148 149
                },
                {
                  id: 'props-composition',
                  name: 'props 组合式 API',
150
                  url: 'props-composition'
DCloud-WZF's avatar
DCloud-WZF 已提交
151 152
                }
              ]
153 154
            },
            {
DCloud-WZF's avatar
DCloud-WZF 已提交
155 156 157 158 159 160
              id: 'el',
              name: '$el',
              children: [
                {
                  id: 'el-options',
                  name: '$el 选项式 API',
161
                  url: 'el-options'
DCloud-WZF's avatar
DCloud-WZF 已提交
162 163 164 165
                },
                {
                  id: 'el-composition',
                  name: '$el 组合式 API',
166
                  url: 'el-composition'
DCloud-WZF's avatar
DCloud-WZF 已提交
167 168
                }
              ]
169 170
            },
            {
171 172 173 174 175 176
              id: 'options',
              name: '$options',
              children: [
                {
                  id: 'options-options',
                  name: '$options 选项式 API',
177
                  url: 'options-options'
178 179 180 181
                },
                {
                  id: 'options-composition',
                  name: '$options 组合式 API',
182
                  url: 'options-composition'
183 184
                }
              ]
185 186
            },
            {
187 188 189 190 191 192
              id: 'parent',
              name: '$parent',
              children: [
                {
                  id: 'parent-options',
                  name: '$parent 选项式 API',
193
                  url: 'parent-options'
194 195 196 197
                },
                {
                  id: 'parent-composition',
                  name: '$parent 组合式 API',
198
                  url: 'parent-composition'
199 200
                }
              ]
DCloud-WZF's avatar
DCloud-WZF 已提交
201
            },
202
            // #ifdef APP
DCloud-WZF's avatar
DCloud-WZF 已提交
203 204 205 206 207 208 209
            {
              id: 'root',
              name: '$root',
              children: [
                {
                  id: 'root-options',
                  name: '$root 选项式 API',
210
                  url: 'root-options'
DCloud-WZF's avatar
DCloud-WZF 已提交
211 212 213 214
                },
                {
                  id: 'root-composition',
                  name: '$root 组合式 API',
215
                  url: 'root-composition'
DCloud-WZF's avatar
DCloud-WZF 已提交
216 217
                }
              ]
218
            }
DCloud-WZF's avatar
DCloud-WZF 已提交
219
            // #endif
220
          ] as Page[]
221
        },
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
        {
          id: 'lifecycle',
          name: '生命周期',
          pages: [
            {
              id: 'page',
              name: '页面生命周期',
              children: [
                {
                  id: 'page-options',
                  name: '页面生命周期(选项式)',
                  url: 'page-options'
                },

                {
                  id: 'page-composition',
                  name: '页面生命周期(组合式)',
                  url: 'page-composition'
                }
              ]
            }
          ] as Page[]
        },
        {
          id: 'built-in',
          name: '内置组件',
          pages: [
            {
              id: 'component/keep-alive',
              name: 'keep-alive',
              children: [
                {
                  id: 'keep-alive-options',
                  name: 'keep-alive(选项式)',
                  url: 'keep-alive-options'
                },

                {
                  id: 'keep-alive-composition',
                  name: 'keep-alive(组合式)',
                  url: 'keep-alive-composition'
                }
              ]
            },
            {
              id: 'component/teleport',
              name: 'teleport',
              children: [
                {
                  id: 'teleport-options',
                  name: 'teleport(选项式)',
                  url: 'teleport-options'
                },

                {
                  id: 'teleport-composition',
                  name: 'teleport(组合式)',
                  url: 'teleport-composition'
                }
              ]
            },
            {
              id: 'component/component',
              name: 'component',
              children: [
                {
                  id: 'component-options',
                  name: 'component(选项式)',
                  url: 'component-options'
                },

                {
                  id: 'component-composition',
                  name: 'component(组合式)',
                  url: 'component-composition'
                }
              ]
            },
            {
              id: 'component/slots',
              name: 'slot',
              children: [
                {
                  id: 'slots-options',
                  name: 'slots(选项式)',
                  url: 'slots-options'
                },

                {
                  id: 'slots-composition',
                  name: 'slots(组合式)',
                  url: 'slots-composition'
                }
              ]
            },
            {
              id: 'component/template',
              name: 'template',
              children: [
                {
                  id: 'template-options',
                  name: 'template(选项式)',
                  url: 'template-options'
                },

                {
                  id: 'template-composition',
                  name: 'template(组合式)',
                  url: 'template-composition'
                }
              ]
            }
          ] as Page[]
        }
      ] as Menu[]
    };
DCloud-WZF's avatar
DCloud-WZF 已提交
338 339
  },
  methods: {
340
    goDetailPage(parentUrl: string, page: Page) {
DCloud-WZF's avatar
DCloud-WZF 已提交
341 342 343
      if (page.enable == false) {
        uni.showToast({
          icon: 'none',
344 345 346
          title: '暂不支持'
        });
        return;
DCloud-WZF's avatar
DCloud-WZF 已提交
347 348
      }
      uni.navigateTo({
349 350
        url: `/pages/${parentUrl}/${page.url}`
      });
DCloud-WZF's avatar
DCloud-WZF 已提交
351 352
    },
    // 自动化测试
353 354
    setLifeCycleNum(num: number) {
      setLifeCycleNum(num);
DCloud-WZF's avatar
DCloud-WZF 已提交
355 356
    },
    // 自动化测试
357 358
    getLifeCycleNum(): number {
      return state.lifeCycleNum;
DCloud-WZF's avatar
DCloud-WZF 已提交
359 360
    },
    // 自动化测试
361 362 363 364 365 366
    checkLaunchPath(): boolean {
      const app = getApp();
      return app.checkLaunchPath();
    }
  }
};
DCloud-WZF's avatar
DCloud-WZF 已提交
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
</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;
    }
  }
}
390
</style>