API.uvue 21.3 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2
<template>
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
DCloud-WZF's avatar
DCloud-WZF 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  <!-- #endif -->
    <view class="uni-container">
      <view class="uni-header-logo">
        <image class="uni-header-image" src="/static/apiIndex.png"></image>
      </view>
      <view class="uni-text-box">
        <text class="hello-text">以下将演示uni-app接口能力,详细文档见:</text>
        <u-link :href="'https://uniapp.dcloud.io/uni-app-x/api/'" :text="'https://uniapp.dcloud.io/uni-app-x/api/'"
          :inWhiteList="true"></u-link>
      </view>

      <uni-collapse>
        <template v-for="item in list" :key="item.id">
          <uni-collapse-item :title="item.name" class="item">
            <view class="uni-navigate-item" :hover-class="page.enable == false ? '' : 'is--active'"
              v-for="(page, key) in item.pages" :key="key" @click="goDetailPage(page)">
              <text class="uni-navigate-text"
                :class="page.enable == false ? 'text-disabled' : ''">{{ page.name }}</text>
              <image :src="arrowRightIcon" class="uni-icon-size"></image>
            </view>
          </uni-collapse-item>
        </template>
      </uni-collapse>
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

      <text>---------------</text>
      <uni-collapse>
        <template v-for="menuItem in menu" :key="menuItem.id">
          <uni-collapse-item :title="menuItem.name" class="item">
            <view v-for="page in menuItem.pages" :key="page.path" class="uni-navigate-item" hover-class="is--active"
              @click="goPage(`/${page.path}`)">
              <text class="uni-navigate-text">{{
                page.style["navigationBarTitleText"]
              }}</text>
              <image :src="arrowRightIcon" class="uni-icon-size"></image>
            </view>
            <uni-collapse style="width: 100%" v-for="childMenu in menuItem.children" :key="childMenu.id">
              <uni-collapse-item :title="childMenu.name" class="item" style="margin-bottom: 0">
                <view class="uni-navigate-item" hover-class="is--active" v-for="childPage in childMenu.pages"
                  :key="childPage.path" @click="goPage(`/${childPage.path}`)">
                  <text class="uni-navigate-text">{{
                    childPage.style["navigationBarTitleText"]
                  }}</text>
                  <image :src="arrowRightIcon" class="uni-icon-size"></image>
                </view>
              </uni-collapse-item>
            </uni-collapse>
          </uni-collapse-item>
        </template>
      </uni-collapse>
DCloud-WZF's avatar
DCloud-WZF 已提交
53 54 55 56 57 58 59 60 61 62 63 64
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
  <view ref="pop" @click="hidePop()" class="popup">
    <view style="width: 90%; background-color: white" @click="stopClickPop">
      <api-set-tabbar></api-set-tabbar>
    </view>
  </view>
</template>

<script lang="uts">
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 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 119
  import { pages } from '@/target-pages.json'

  type PagesJsonPageGroup = {
    id : string,
    name : string
  }

  type PagesJsonPage = {
    path : string,
    style : UTSJSONObject,
    group ?: PagesJsonPageGroup[] | null
  }

  type MenuItem = {
    id : string,
    name : string,
    children : MenuItem[],
    pages : PagesJsonPage[]
  }
  const menu : MenuItem[] = []
  const menuKeyMap = new Map<string, number>()
  // #ifdef APP-ANDROID
  const apiPages = JSON.parse<PagesJsonPage[]>(JSON.stringify(pages))!.filter((page : PagesJsonPage) : boolean => page.path.startsWith('pages/API') && page.group !== null)
  // #endif
  // #ifdef WEB || APP-IOS
  const apiPages = (pages as unknown as PagesJsonPage[]).filter(page => page.path.startsWith('pages/API') && page.group)
  // #endif
  apiPages.forEach(page => {
    let currentArr : MenuItem[] = menu
    let currentMenu : MenuItem | null = null
    if (page.group !== null) {
      page.group!.forEach((item, index) => {
        const { id, name } = item
        const ids = id.split('.')
        const _id = ids[ids.length - 1]
        if (!menuKeyMap.has(id)) {
          menuKeyMap.set(id, currentArr.length)
          currentArr.push({
            id: _id,
            name,
            children: [] as MenuItem[],
            pages: [] as PagesJsonPage[]
          } as MenuItem)
        }
        currentMenu = currentArr[menuKeyMap.get(id)!]
        if (index < page.group!.length - 1) {
          currentArr = currentArr[menuKeyMap.get(id)!].children as MenuItem[]
        }
      })
    }
    if (currentMenu !== null) {
      (currentMenu as MenuItem).pages.push(page)
    }
  })
  console.log('menu', menu)
DCloud-WZF's avatar
DCloud-WZF 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  type Page = {
    name : string
    url : string
    enable ?: boolean
    api ?: Array<string>
  }
  type ListItem = {
    id : string
    name : string
    pages : Page[]
    url ?: string
    enable ?: boolean
  }
  export default {
    data() {
      return {
136
        menu: menu as MenuItem[],
DCloud-WZF's avatar
DCloud-WZF 已提交
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
        list: [
          {
            id: 'global',
            name: '全局',
            pages: [
              {
                name: 'getApp',
                url: 'get-app',
              },
              {
                name: 'getCurrentPages',
                url: 'get-current-pages',
              }
            ] as Page[],
          },
          {
            id: 'base',
            name: '基础',
            pages: [
              {
                name: '事件总线event-bus',
                url: 'event-bus',
                api: ["$on", "$once", "$off", "$emit"]
              },
              {
                name: '拦截器',
                url: 'interceptor',
                api: ["addInterceptor", "removeInterceptor"]
              },
              {
                name: '获取启动参数',
                url: 'get-launch-options-sync',
169 170 171 172 173 174
              },
              // #ifndef WEB
              {
                name: 'env环境变量',
                url: 'env'
              },
W
wanganxp 已提交
175
              // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
176 177 178 179
              // #ifdef APP-ANDROID
              {
                name: '退出应用',
                url: 'exit',
W
wanganxp 已提交
180
              }
DCloud-WZF's avatar
DCloud-WZF 已提交
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 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
              // #endif
            ] as Page[],
          },
          {
            id: 'page',
            name: '页面和路由',
            pages: [
              {
                name: '页面跳转',
                url: 'navigator',
                api: ["navigateTo", "reLaunch", "navigateBack", "redirectTo", "switchTab"]
              },

              {
                name: '设置导航条标题',
                url: 'set-navigation-bar-title',
              },
              {
                name: '设置导航条颜色',
                url: 'set-navigation-bar-color',
              },
              {
                name: '设置页面容器背景色',
                url: 'set-page-backgroundColorContent',
              },
              {
                name: '设置TabBar',
                url: 'set-tabbar',
                api: ["showTabBar", "hideTabBar", "showTabBarRedDot", "hideTabBarRedDot", "setTabBarBadge", "removeTabBarBadge", "setTabBarStyle", "setTabBarItem"]
              },
              {
                name: '页面下拉刷新',
                url: 'pull-down-refresh',
                api: ["stopPullDownRefresh"]
              },
              {
                name: '将页面滚动到指定位置',
                url: 'page-scroll-to',
              },
            ] as Page[],
          },
          {
            id: 'ui',
            name: '界面',
            pages: [
              // {
              //   name: "创建动画",
              //   url: "animation",
              //   enable: false
              // },
              // {
              //   name: "创建绘画",
              //   url: "canvas",
              //   enable: true
              // },
              // {
              //   name: "节点布局交互状态",
              //   url: "intersection-observer",
              //   enable: false
              // },
              {
                name: 'element元素',
                url: 'get-element-by-id',
                api: ["getElementById"],
              },
              // #ifdef APP
              {
                name: 'element draw',
                url: 'element-draw',
                api: ["Element.getDrawableContext"]
              }, {
                name: 'element截图',
                url: 'element-takesnapshot',
                api: ["Element.takeSnapshot"]
              },
              // #endif
              {
                name: 'element大小变化监听',
                url: 'resize-observer'
              },
              {
                name: 'node节点',
                url: 'nodes-info',
                api: ["createSelectorQuery"]
              },
              {
                name: '动态加载字体',
                url: 'load-font-face',
              },
              {
                name: 'rpx2px',
                url: 'rpx2px'
              },
              {
                name: 'actionSheet操作菜单',
                url: 'action-sheet',
              },
              {
                name: 'showModal模态弹窗',
                url: 'modal',
                api: ["showModal"]
              },
              {
                name: 'showLoading等待框',
                url: 'loading',
              },
              {
                name: 'showToast轻提示框',
                url: 'toast',
                api: ["showToast"]
291 292 293 294 295 296 297
              }
              // #ifdef APP
              , {
                name: '主题切换',
                url: 'theme-change',
                api: ["setAppTheme", "onOsThemeChange", "offOsThemeChange", "onAppThemeChange", "offAppThemeChange"]
              }
298
              // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
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 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
            ] as Page[],
          },
          {
            id: 'network',
            name: '网络',
            pages: [
              {
                name: '发起请求request',
                url: 'request',
              },
              {
                name: '上传文件',
                url: 'upload-file',
              },
              {
                name: '下载文件',
                url: 'download-file',
              },
              {
                name: '获取设备网络状态',
                url: 'get-network-type',
              },
              {
                name: 'socketTask',
                url: 'websocket-socketTask',
                api: [""] //它不是uni.的api
              },
              {
                name: '全局websocket',
                url: 'websocket-global',
                api: ["connectSocket", "onSocketOpen", "onSocketError", "sendSocketMessage", "onSocketMessage", "closeSocket", "onSocketClose"]
              },
            ] as Page[],
          },
          {
            id: 'device',
            name: '设备',
            pages: [
              {
                name: '获取系统信息',
                url: 'get-system-info',
              },
              {
                name: '获取设备信息',
                url: 'get-device-info',
              },
              {
                name: '获取窗口信息',
                url: 'get-window-info',
              },
              {
                name: '获取APP基础信息',
                url: 'get-app-base-info',
              },
              // #ifdef APP
              {
                name: '获取APP授权设置',
                url: 'get-app-authorize-setting',
              },
              {
                name: '获取系统设置',
                url: 'get-system-setting',
              },
              // #endif
              {
                name: '电量',
                url: 'get-battery-info',
              },
              // #ifdef APP-ANDROID
              {
                name: '安装Apk',
                url: 'install-apk'
              },
372 373 374 375 376
              // #endif
              // #ifdef WEB
              {
                name: "打电话",
                url: "make-phone-call",
377 378 379 380 381 382 383 384
              },
              {
                name: "剪贴板",
                url: "clipboard",
              },
              {
                name: "监听罗盘数据",
                url: "on-compass-change",
385
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
386
              // #endif
Anne_LXM's avatar
Anne_LXM 已提交
387
              /*
DCloud-WZF's avatar
DCloud-WZF 已提交
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
              {
                name: "震动",
                url: "vibrate",
              },
              {
                name: "添加手机联系人",
                url: "add-phone-contact",
              },
              {
                name: "扫码",
                url: "scan-code",
              },
              {
                name: "屏幕亮度",
                url: "brightness",
              },
              {
                name: "蓝牙",
                url: "bluetooth",
              },
              {
                name: "生物认证",
                url: "soter",
              },
              {
                name: "iBeacon",
                url: "ibeacon",
              },
              {
                name: "监听加速度传感器",
                url: "on-accelerometer-change",
              },
              {
                name: "监听距离传感器",
                url: "/platforms/app-plus/proximity/proximity",
              },
              {
                name: "监听方向传感器",
                url: "/platforms/app-plus/orientation/orientation",
              }, */
            ] as Page[],
          },
          {
            id: 'media',
            name: '媒体',
            pages: [
              {
                name: "拍摄图片或从相册中选择图片",
                url: 'choose-image'
              },
              {
                name: '图片预览',
                url: 'preview-image',
                api: ["previewImage", "closePreviewImage"]
              },
              // #ifdef APP
              {
                name: "保存图片到相册",
                url: 'save-image-to-photos-album'
              },
              // #endif
              {
                name: "获取图片信息",
                url: 'get-image-info'
              },
453
              // #ifdef APP
DCloud-WZF's avatar
DCloud-WZF 已提交
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
              {
                name: "压缩图片",
                url: 'compress-image'
              },
              // #endif
              {
                name: "拍摄视频或从相册中选择视频",
                url: 'choose-video'
              },
              // #ifdef APP
              {
                name: "保存视频到相册",
                url: 'save-video-to-photos-album'
              },
              // #endif
              {
                name: "获取视频信息",
                url: 'get-video-info'
              },
473
              // #ifdef APP
DCloud-WZF's avatar
DCloud-WZF 已提交
474 475 476 477
              {
                name: "压缩视频",
                url: 'compress-video'
              },
478 479 480 481 482 483
              // #endif
              // #ifdef WEB
              {
                name: "音频",
                url: "inner-audio",
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
484
              // #endif
Anne_LXM's avatar
Anne_LXM 已提交
485
              /*
DCloud-WZF's avatar
DCloud-WZF 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
              {
                name: "背景音频",
                url: "background-audio",
              },
              {
                name: "录音",
                url: "rec",
              },
              {
                name: "文件",
                url: "file",
              },
              */
            ] as Page[],
          },
          {
            id: 'location',
            name: '位置',
            pages: [
              {
                name: '获取当前位置',
                url: 'get-location',
508 509 510 511 512 513 514 515 516 517
              },
              // #ifdef WEB
              {
                name: "使用地图查看位置",
                url: "open-location",
              },
              {
                name: "使用地图选择位置",
                url: "choose-location",
              },
518
              // #endif
519
              /*
DCloud-WZF's avatar
DCloud-WZF 已提交
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
              {
                name: "地图搜索",
                url: "map-search",
              }, */
            ] as Page[],
          },
          {
            id: 'storage',
            name: '数据存储',
            pages: [
              {
                name: 'storage(key-value存储)',
                url: 'storage',
                api: ["getStorageInfo", "getStorageInfoSync", "getStorage", "getStorageSync", "setStorage", "setStorageSync", "removeStorage", "removeStorageSync", "clearStorage", "clearStorageSync"]
              }
            ] as Page[],
          },
          // #ifdef APP
          {
            id: 'file',
            name: '文件',
            pages: [
              {
                name: 'fileSystemManager文件管理',
                url: 'get-file-system-manager'
545
              }
DCloud-WZF's avatar
DCloud-WZF 已提交
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
            ] as Page[],
          },
          // #endif
          {
            id: 'unicloud',
            name: 'uniCloud',
            pages: [
              {
                name: '云函数',
                url: 'unicloud-call-function',
              },
              {
                name: '云对象',
                url: 'unicloud-import-object',
              },
              {
                name: '云存储',
                url: 'unicloud-file-api',
              },
              {
                name: 'clientDB',
                url: 'unicloud-database',
              },
            ] as Page[],
          },
          // #ifdef APP
          {
            id: 'login',
            name: '登录与认证',
            pages: [
              {
                name: '一键登录',
                url: 'get-univerify-manager',
              },
              {
                name: '实人认证',
                url: 'facial-recognition-verify',
              }
            ] as Page[],
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
          },
          {
            id: 'ad',
            name: '广告',
            pages: [
              {
                name: '激励视频广告',
                url: 'rewarded-video-ad',
              }
              /* {
                id: "full-screen-video-ad",
                url: "full-screen-video-ad",
                name: "全屏视频广告",
                enable: false,
                pages: [] as Page[]
              }, */
            ] as Page[],
          },
DCloud-WZF's avatar
DCloud-WZF 已提交
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
          // #endif
          {
            id: "payment",
            name: "支付",
            pages: [
              // #ifndef WEB
              {
                name: "简易支付示例",
                url: "request-payment",
              },
              // #endif
              {
                name: "uni-pay支付示例",
                url: "request-payment-uni-pay",
              }
            ] as Page[],
619
          },
DCloud-WZF's avatar
DCloud-WZF 已提交
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
          // #ifdef APP-ANDROID
          {
            id: 'permission-listener',
            name: '权限申请监听',
            pages: [
              {
                name: '权限申请监听',
                url: 'create-request-permission-listener',
              }
            ] as Page[]
          },
          // #endif
          /*
          {
            id: "share",
            name: "分享",
            pages: [
              {
                name: "分享",
                url: "share",
              },
            ] as Page[],
          },
          */
        ] as ListItem[],
        arrowUpIcon: '/static/icons/arrow-up.png',
        arrowDownIcon: '/static/icons/arrow-down.png',
        arrowRightIcon: '/static/icons/arrow-right.png',
      }
    },
    onLoad() {
      // console.log("API page onLoad")
    },
    onShow() {
      // console.log("API page onShow")
    },
    onHide() {
      // console.log("API page onHide")
    },
    methods: {
      goDetailPage(e : Page) {
        if (e.enable == false) {
          uni.showToast({
            title: '暂不支持',
            icon: 'none',
          })
          return
        }
        if (e.url === 'set-tabbar') {
          this.showPop()
          return;
        }
        const url =
          e.url.indexOf('platform') > -1 ? e.url : `/pages/API/${e.url}/${e.url}`
        uni.navigateTo({
          url,
        })
      },
678 679 680
      goPage(url : string) {
        uni.navigateTo({ url })
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
      showPop: function () {
        (this.$refs["pop"] as UniElement).style.setProperty("display", "flex")
      },
      hidePop: function () {
        (this.$refs["pop"] as UniElement).style.setProperty("display", "none")
      },
      stopClickPop: function (e : PointerEvent) {
        e.stopPropagation() //点击到pop的非灰色区域,拦截点击事件
      }
    },
  }
</script>

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

  .popup {
    width: 100%;
    /* #ifdef APP */
    position: absolute;
    height: 100%;
    /* #endif */
    /* #ifndef APP */
    position: fixed;
    top: var(--window-top);
    bottom: var(--window-bottom);
    /* #endif */
    align-items: center;
    justify-content: center;
    display: none;
    background-color: rgba(16, 16, 16, 0.5);
  }
715
</style>