index.uvue 17.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>
DCloud-WZF's avatar
DCloud-WZF 已提交
7 8 9 10 11
        <uni-collapse-item
          v-for="menu in menus"
          :key="menu.id"
          :title="menu.name"
          class="menu">
DCloud-WZF's avatar
DCloud-WZF 已提交
12
          <view v-for="(page, index) in menu.pages" :key="page.name">
DCloud-WZF's avatar
DCloud-WZF 已提交
13 14 15 16 17 18 19 20 21 22
            <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 已提交
23 24 25 26
            </view>
            <template v-if="page.children">
              <uni-collapse style="flex: 1">
                <uni-collapse-item :title="page.name" class="menu">
D
DCloud_LXH 已提交
27 28 29 30 31
                  <view
                    v-for="(child, index) in page.children"
                    :key="child.url"
                    class="page-item"
                    :class="{ 'first-child': index == 0 }"
DCloud-WZF's avatar
DCloud-WZF 已提交
32 33 34 35 36 37
                    @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 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51
                  </view>
                </uni-collapse-item>
              </uni-collapse>
            </template>
          </view>
        </uni-collapse-item>
      </uni-collapse>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
D
DCloud_LXH 已提交
52
import { setLifeCycleNum, state } from '@/store/index.uts'
DCloud-WZF's avatar
DCloud-WZF 已提交
53

D
DCloud_LXH 已提交
54 55 56 57 58 59 60
type Page = {
  id: string
  name: string
  enable?: boolean
  url?: string
  children?: Page[]
}
DCloud-WZF's avatar
DCloud-WZF 已提交
61

D
DCloud_LXH 已提交
62 63 64 65 66 67 68
type Menu = {
  id: string
  name: string
  pages: Page[]
  url?: string
  enable?: boolean
}
DCloud-WZF's avatar
DCloud-WZF 已提交
69

D
DCloud_LXH 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 116 117 118
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',
                  url: 'globalProperties-options'
                },
                {
                  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[]
        },
        {
          id: 'component-instance',
119
          name: '组件实例',
D
DCloud_LXH 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
          pages: [
            {
              id: 'attrs',
              name: 'attrs',
              children: [
                {
                  id: 'attrs-options',
                  name: 'attrs 选项式 API',
                  url: 'attrs-options'
                },
                {
                  id: 'attrs-composition',
                  name: 'attrs 组合式 API',
                  url: 'attrs-composition'
                }
              ]
            },
            {
              id: 'data',
              name: 'data',
              children: [
                {
                  id: 'data-options',
                  name: 'data 选项式 API',
                  url: 'data-options'
                },
                {
                  id: 'data-composition',
                  name: 'data 组合式 API',
                  url: 'data-composition'
                }
              ]
            },
            {
              id: 'props',
              name: 'props',
              children: [
                {
                  id: 'props-options',
                  name: 'props 选项式 API',
                  url: 'props-options'
                },
                {
                  id: 'props-composition',
                  name: 'props 组合式 API',
                  url: 'props-composition'
                }
              ]
            },
            {
              id: 'el',
              name: '$el',
              children: [
                {
                  id: 'el-options',
                  name: '$el 选项式 API',
                  url: 'el-options'
                },
                {
                  id: 'el-composition',
                  name: '$el 组合式 API',
                  url: 'el-composition'
                }
              ]
            },
            {
              id: 'options',
              name: '$options',
              children: [
                {
                  id: 'options-options',
                  name: '$options 选项式 API',
                  url: 'options-options'
                },
                {
                  id: 'options-composition',
                  name: '$options 组合式 API',
                  url: 'options-composition'
                }
              ]
            },
            {
              id: 'parent',
              name: '$parent',
              children: [
                {
                  id: 'parent-options',
                  name: '$parent 选项式 API',
                  url: 'parent-options'
                },
                {
                  id: 'parent-composition',
                  name: '$parent 组合式 API',
                  url: 'parent-composition'
                }
              ]
            },
            // #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'
                }
              ]
233
            },
D
DCloud_LXH 已提交
234
            // #endif
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
            {
              id: 'slots',
              name: '$slots',
              children: [
                {
                  id: 'slots-options',
                  name: '$slots 选项式 API',
                  url: 'slots-options'
                },
                {
                  id: 'slots-composition',
                  name: '$slots 组合式 API',
                  url: 'slots-composition'
                }
              ]
D
DCloud_LXH 已提交
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
            },
            {
              id: 'refs',
              name: '$refs',
              children: [
                {
                  id: 'refs-options',
                  name: '$refs 选项式 API',
                  url: 'refs-options'
                },
                {
                  id: 'refs-composition',
                  name: '$refs 组合式 API',
                  url: 'refs-composition'
                }
              ]
D
DCloud_LXH 已提交
266 267 268 269 270 271 272 273 274 275 276 277 278
            },
            {
              id: 'emit-function',
              name: '$emit',
              children: [
                {
                  id: 'emit-options',
                  name: '$emit 选项式 API',
                  url: 'emit-function-options'
                },
                {
                  id: 'emit-composition',
                  name: 'defineEmits 组合式 API',
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
                  url: 'emit-function-composition'
                }
              ]
            },
            {
              id: 'force-update',
              name: '$force-update',
              children: [
                {
                  id: 'force-update-options',
                  name: '$forceUpdate 选项式 API',
                  url: 'force-update-options'
                },
                {
                  id: 'force-update-composition',
                  name: '$forceUpdate 组合式 API',
                  url: 'force-update-composition'
D
DCloud_LXH 已提交
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
            },
            {
              id: 'methods',
              name: '$methods',
              children: [
                {
                  id: 'call-method-easycom-uni-modules-options',
                  name: '调用 uni_modules easycom 组件方法 选项式 API',
                  url: 'call-method-easycom-uni-modules-options'
                },
                {
                  id: 'call-method-easycom-uni-modules-composition',
                  name: '调用 uni_modules easycom 组件方法 组合式 API',
                  url: 'call-method-easycom-uni-modules-composition'
                },
                {
                  id: 'call-method-uni-element-options',
                  name: '调用内置组件方法 选项式 API',
                  url: 'call-method-uni-element-options'
                },
                {
                  id: 'call-method-uni-element-composition',
                  name: '调用内置组件方法 组合式 API',
                  url: 'call-method-uni-element-composition'
                },
                {
                  id: 'call-method-other-options',
                  name: '调用自定义组件方法 选项式 API',
                  url: 'call-method-other-options'
                },
                {
                  id: 'call-method-other-composition',
                  name: '调用自定义组件方法 组合式 API',
                  url: 'call-method-other-composition'
                }
              ]
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
            },
            {
              id: 'provide',
              name: 'provide',
              children: [
                {
                  id: 'provide-options-1',
                  name: 'provide 选项式 API 字面量方式',
                  url: 'provide-options-1'
                },
                {
                  id: 'provide-options-2',
                  name: 'provide 选项式 API 函数方式',
                  url: 'provide-options-2'
                },
                {
                  id: 'provide-composition',
                  name: 'provide 组合式 API',
                  url: 'provide-composition'
                },
              ]
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
            },
            {
              id: 'nextTick',
              name: 'nextTick',
              children: [
                {
                  id: 'nextTick-options',
                  name: 'nextTick 选项式 API',
                  url: 'nextTick-options'
                },
                {
                  id: 'nextTick-composition',
                  name: 'nextTick 组合式 API',
                  url: 'nextTick-composition'
                },
              ]
371
            }
D
DCloud_LXH 已提交
372 373 374 375 376 377 378 379 380 381 382 383
          ] as Page[]
        },
        {
          id: 'lifecycle',
          name: '生命周期',
          pages: [
            {
              id: 'page',
              name: '页面生命周期',
              children: [
                {
                  id: 'page-options',
384
                  name: '页面生命周期 选项式 API',
D
DCloud_LXH 已提交
385 386
                  url: 'page-options'
                },
387

D
DCloud_LXH 已提交
388 389
                {
                  id: 'page-composition',
390
                  name: '页面生命周期 组合式 API',
D
DCloud_LXH 已提交
391 392 393
                  url: 'page-composition'
                }
              ]
DCloud-WZF's avatar
DCloud-WZF 已提交
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
            }, {
              id: 'component',
              name: '组件生命周期',
              children: [
                {
                  id: 'component-options',
                  name: '组件生命周期 选项式 API',
                  url: 'component-options'
                },

                {
                  id: 'component-composition',
                  name: '组件生命周期 组合式 API',
                  url: 'component-composition'
                }
              ]
D
DCloud_LXH 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422
            }
          ] as Page[]
        },
        {
          id: 'built-in',
          name: '内置组件',
          pages: [
            {
              id: 'component/keep-alive',
              name: 'keep-alive',
              children: [
                {
                  id: 'keep-alive-options',
423
                  name: 'keep-alive 选项式 API',
D
DCloud_LXH 已提交
424 425
                  url: 'keep-alive-options'
                },
426

D
DCloud_LXH 已提交
427 428
                {
                  id: 'keep-alive-composition',
429
                  name: 'keep-alive 组合式 API',
D
DCloud_LXH 已提交
430 431 432 433 434 435 436 437 438 439
                  url: 'keep-alive-composition'
                }
              ]
            },
            {
              id: 'component/teleport',
              name: 'teleport',
              children: [
                {
                  id: 'teleport-options',
440
                  name: 'teleport 选项式 API',
D
DCloud_LXH 已提交
441 442
                  url: 'teleport-options'
                },
443

D
DCloud_LXH 已提交
444 445
                {
                  id: 'teleport-composition',
446
                  name: 'teleport 组合式 API',
D
DCloud_LXH 已提交
447 448 449 450 451 452 453 454 455 456
                  url: 'teleport-composition'
                }
              ]
            },
            {
              id: 'component/component',
              name: 'component',
              children: [
                {
                  id: 'component-options',
457
                  name: 'component 选项式 API',
D
DCloud_LXH 已提交
458 459
                  url: 'component-options'
                },
460

D
DCloud_LXH 已提交
461 462
                {
                  id: 'component-composition',
463
                  name: 'component 组合式 API',
D
DCloud_LXH 已提交
464 465 466 467 468
                  url: 'component-composition'
                }
              ]
            },
            {
D
DCloud_LXH 已提交
469 470 471 472 473
              id: 'component/slots',
              name: 'slot',
              children: [
                {
                  id: 'slots-options',
474
                  name: 'slots 选项式 API',
D
DCloud_LXH 已提交
475 476 477 478 479
                  url: 'slots-options'
                },

                {
                  id: 'slots-composition',
480
                  name: 'slots 组合式 API',
D
DCloud_LXH 已提交
481 482 483 484 485 486 487 488 489 490
                  url: 'slots-composition'
                }
              ]
            },
            {
              id: 'component/template',
              name: 'template',
              children: [
                {
                  id: 'template-options',
491
                  name: 'template 选项式 API',
D
DCloud_LXH 已提交
492 493 494 495 496
                  url: 'template-options'
                },

                {
                  id: 'template-composition',
497
                  name: 'template 组合式 API',
D
DCloud_LXH 已提交
498 499 500 501
                  url: 'template-composition'
                }
              ]
            }
D
DCloud_LXH 已提交
502 503 504 505 506 507 508 509
          ] as Page[]
        },
        {
          id: 'rendering',
          name: '渲染',
          pages: [
            {
              id: 'render',
510
              name: 'render Function 选项式 API',
D
DCloud_LXH 已提交
511 512 513 514 515 516 517 518
              url: 'render/render'
            },
            {
              id: 'unrecognized-component',
              name: 'unrecognized-component',
              url: 'unrecognized-component/unrecognized-component'
            }
          ] as Page[]
D
DCloud_LXH 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
        },
        {
          id: 'examples',
          name: '示例',
          pages: [
            {
              id: 'nested-component-communication',
              name: '嵌套组件通讯',
              children: [
                {
                  id: 'nested-component-communication-options',
                  name: '选项式',
                  url: 'nested-component-communication-options'
                },
                {
                  id: 'nested-component-communication-composition',
                  name: '组合式',
                  url: 'nested-component-communication-composition'
                }
              ]
            },
            {
              id: 'set-custom-child-component-root-node-class',
              name: '自定义组件中使用 class 定制另一个自定义组件根节点样式',
              children: [
                {
                  id: 'set-custom-child-component-root-node-class-options',
                  name: '选项式',
                  url: 'set-custom-child-component-root-node-class-options'
                },
                {
                  id: 'set-custom-child-component-root-node-class-composition',
                  name: '组合式',
                  url: 'set-custom-child-component-root-node-class-composition'
                }
              ]
            }
          ] as Page[]
D
DCloud_LXH 已提交
557
        }
D
DCloud_LXH 已提交
558 559 560 561 562 563 564 565 566 567 568
      ] as Menu[]
    }
  },
  methods: {
    goDetailPage(parentUrl: string, page: Page) {
      if (page.enable == false) {
        uni.showToast({
          icon: 'none',
          title: '暂不支持'
        })
        return
D
DCloud_LXH 已提交
569
      }
D
DCloud_LXH 已提交
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
      uni.navigateTo({
        url: `/pages/${parentUrl}/${page.url}`
      })
    },
    // 自动化测试
    setLifeCycleNum(num: number) {
      setLifeCycleNum(num)
    },
    // 自动化测试
    getLifeCycleNum(): number {
      return state.lifeCycleNum
    },
    // 自动化测试
    checkLaunchPath(): boolean {
      const app = getApp()
      return app.checkLaunchPath()
586
    }
D
DCloud_LXH 已提交
587 588
  }
}
DCloud-WZF's avatar
DCloud-WZF 已提交
589 590 591
</script>

<style lang="scss">
D
DCloud_LXH 已提交
592 593
.menu {
  border-bottom: 1px solid #dbd9d9;
D
DCloud_LXH 已提交
594

D
DCloud_LXH 已提交
595 596
  &.open {
    border-bottom: none;
DCloud-WZF's avatar
DCloud-WZF 已提交
597
  }
D
DCloud_LXH 已提交
598
}
D
DCloud_LXH 已提交
599

D
DCloud_LXH 已提交
600 601 602
.page-item {
  padding: 12px 10px;
  border-bottom: 1px solid #dbd9d9;
D
DCloud_LXH 已提交
603

D
DCloud_LXH 已提交
604 605 606
  &.first-child {
    border-top: 1px solid #dbd9d9;
  }
D
DCloud_LXH 已提交
607

D
DCloud_LXH 已提交
608 609 610
  .text {
    font-size: 14px;
    color: #333;
D
DCloud_LXH 已提交
611

D
DCloud_LXH 已提交
612 613
    &.text-disabled {
      color: #999;
DCloud-WZF's avatar
DCloud-WZF 已提交
614 615
    }
  }
D
DCloud_LXH 已提交
616
}
DCloud-WZF's avatar
DCloud-WZF 已提交
617
</style>