API.uvue 16.9 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
<template>
Y
yurj26 已提交
2 3
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
4
  <!-- #endif -->
Y
yurj26 已提交
5 6 7 8 9 10
    <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>
11
        <u-link :href="'https://uniapp.dcloud.io/uni-app-x/api/'" :text="'https://uniapp.dcloud.io/uni-app-x/api/'" :inWhiteList="true"></u-link>
Y
yurj26 已提交
12
      </view>
M
mehaotian 已提交
13

Y
yurj26 已提交
14 15 16
      <uni-collapse>
        <template v-for="item in list" :key="item.id">
          <uni-collapse-item :title="item.name" class="item">
17 18
            <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>
19
              <image :src="arrowRightIcon" class="uni-icon-size"></image>
Y
yurj26 已提交
20 21 22 23
            </view>
          </uni-collapse-item>
        </template>
      </uni-collapse>
M
mehaotian 已提交
24

Y
yurj26 已提交
25
    </view>
26
  <!-- #ifdef APP -->
Y
yurj26 已提交
27 28
  </scroll-view>
  <!-- #endif -->
29
  <view ref="pop" @click="hidePop()" class="popup">
Y
yurj26 已提交
30 31 32
    <view style="width: 90%;background-color: white;" @click="stopClickPop">
      <api-set-tabbar></api-set-tabbar>
    </view>
W
wanganxp 已提交
33
  </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35
</template>

Y
yurj26 已提交
36
<script lang="uts">
Y
yurj26 已提交
37 38 39 40
  type Page = {
    name : string
    url : string
    enable ?: boolean
41
    api ?: Array<string>
Y
yurj26 已提交
42 43 44 45 46 47 48 49 50 51 52 53
  }
  type ListItem = {
    id : string
    name : string
    pages : Page[]
    url ?: string
    enable ?: boolean
  }
  export default {
    data() {
      return {
        list: [
54
          {
D
DCloud_LXH 已提交
55
            id: 'global',
Y
yurj26 已提交
56 57 58 59 60 61
            name: '全局',
            pages: [
              {
                name: 'getApp',
                url: 'get-app',
              },
雪洛's avatar
雪洛 已提交
62 63 64
              {
                name: 'getCurrentPages',
                url: 'get-current-pages',
Y
yurj26 已提交
65 66 67 68 69 70 71 72 73 74 75
              }
            ] as Page[],
          },
          {
            id: 'base',
            name: '基础',
            pages: [
              {
                name: '事件总线event-bus',
                url: 'event-bus',
                api: ["$on", "$once", "$off", "$emit"]
雪洛's avatar
雪洛 已提交
76 77 78 79 80
              },
              {
                name: '拦截器',
                url: 'interceptor',
                api: ["addInterceptor", "removeInterceptor"]
Y
yurj26 已提交
81 82 83 84
              },
              {
                name: '获取启动参数',
                url: 'get-launch-options-sync',
85
              },
W
wanganxp 已提交
86
              // #ifdef APP-ANDROID
Y
yurj26 已提交
87 88 89
              {
                name: '退出应用',
                url: 'exit',
90
              },
W
wanganxp 已提交
91
              // #endif
Y
yurj26 已提交
92 93 94 95 96 97 98 99 100
            ] as Page[],
          },
          {
            id: 'page',
            name: '页面和路由',
            pages: [
              {
                name: '页面跳转',
                url: 'navigator',
D
DCloud_LXH 已提交
101
                api: ["navigateTo", "reLaunch", "navigateBack", "redirectTo", "switchTab"]
Y
yurj26 已提交
102
              },
DCloud-WZF's avatar
DCloud-WZF 已提交
103

Y
yurj26 已提交
104 105 106
              {
                name: '设置导航条标题',
                url: 'set-navigation-bar-title',
DCloud-WZF's avatar
DCloud-WZF 已提交
107
              },
Y
yurj26 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
              {
                name: '设置导航条颜色',
                url: 'set-navigation-bar-color',
              },
              {
                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: [
H
hdx 已提交
132 133 134 135
              // {
              //   name: "创建动画",
              //   url: "animation",
              //   enable: false
136
              // },
H
hdx 已提交
137 138 139 140 141
              // {
              //   name: "创建绘画",
              //   url: "canvas",
              //   enable: true
              // },
H
hdx 已提交
142 143 144 145
              // {
              //   name: "节点布局交互状态",
              //   url: "intersection-observer",
              //   enable: false
146
              // },
DCloud-WZF's avatar
DCloud-WZF 已提交
147
              {
W
wanganxp 已提交
148
                name: 'element元素',
DCloud-WZF's avatar
DCloud-WZF 已提交
149
                url: 'get-element-by-id',
雪洛's avatar
雪洛 已提交
150 151
                api: ["getElementById"],
              },
152
              // #ifdef APP
雪洛's avatar
雪洛 已提交
153 154 155
              {
                name: 'element draw',
                url: 'element-draw',
156
                api: ["Element.getDrawableContext"]
157
              }, {
雪洛's avatar
雪洛 已提交
158 159
                name: 'element截图',
                url: 'element-takesnapshot',
160
                api: ["Element.takeSnapshot"]
161
              },
W
wanganxp 已提交
162
              // #endif
Y
yurj26 已提交
163
              {
W
wanganxp 已提交
164
                name: 'node节点',
Y
yurj26 已提交
165 166 167 168
                url: 'nodes-info',
                api: ["createSelectorQuery"]
              },
              {
W
wanganxp 已提交
169 170 171 172 173
                name: '动态加载字体',
                url: 'load-font-face',
              },
              {
                name: 'actionSheet操作菜单',
Y
yurj26 已提交
174 175 176
                url: 'action-sheet',
              },
              {
W
wanganxp 已提交
177
                name: 'showModal模态弹窗',
Y
yurj26 已提交
178 179 180 181
                url: 'modal',
                api: ["showModal"]
              },
              {
W
wanganxp 已提交
182
                name: 'showLoading等待框',
183
                url: 'loading',
Y
yurj26 已提交
184 185
              },
              {
W
wanganxp 已提交
186
                name: 'showToast轻提示框',
Y
yurj26 已提交
187 188
                url: 'toast',
                api: ["showToast"]
W
wanganxp 已提交
189
              }
Y
yurj26 已提交
190
            ] as Page[],
雪洛's avatar
雪洛 已提交
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
          },
          {
            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[],
Y
yurj26 已提交
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
          },
          {
            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',
243
              },
W
wanganxp 已提交
244
              // #ifdef APP
Y
yurj26 已提交
245 246 247 248 249 250 251
              {
                name: '获取APP授权设置',
                url: 'get-app-authorize-setting',
              },
              {
                name: '获取系统设置',
                url: 'get-system-setting',
252
              },
W
wanganxp 已提交
253
              // #endif
Y
yurj26 已提交
254 255 256
              {
                name: '电量',
                url: 'get-battery-info',
257
              },
W
wanganxp 已提交
258
              // #ifdef APP-ANDROID
雪洛's avatar
雪洛 已提交
259 260 261
              {
                name: '安装Apk',
                url: 'install-apk'
262
              },
W
wanganxp 已提交
263
              // #endif
Y
yurj26 已提交
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
              /* {
                name: "打电话",
                url: "make-phone-call",
              },
              {
                name: "震动",
                url: "vibrate",
              },
              {
                name: "添加手机联系人",
                url: "add-phone-contact",
              },
              {
                name: "扫码",
                url: "scan-code",
              },
              {
                name: "剪贴板",
                url: "clipboard",
              },
              {
                name: "屏幕亮度",
                url: "brightness",
              },
              {
                name: "蓝牙",
                url: "bluetooth",
              },
              {
                name: "生物认证",
                url: "soter",
              },
              {
                name: "iBeacon",
                url: "ibeacon",
              },
              {
                name: "监听加速度传感器",
                url: "on-accelerometer-change",
              },
              {
                name: "监听罗盘数据",
                url: "on-compass-change",
              },
              {
                name: "监听距离传感器",
                url: "/platforms/app-plus/proximity/proximity",
              },
              {
                name: "监听方向传感器",
                url: "/platforms/app-plus/orientation/orientation",
              }, */
            ] as Page[],
          },
          {
            id: 'media',
            name: '媒体',
雪洛's avatar
雪洛 已提交
321 322 323 324
            pages: [
              {
                name: "拍照和相册选择",
                url: 'choose-image'
张磊 已提交
325
              },
Y
yurj26 已提交
326
              {
W
wanganxp 已提交
327
                name: '图片预览',
Y
yurj26 已提交
328
                url: 'preview-image',
W
wanganxp 已提交
329
                api: ["previewImage", "closePreviewImage"]
330
              },
W
wanganxp 已提交
331
              // #ifdef APP
Y
yurj26 已提交
332 333
              {
                name: "保存图片到相册",
334
                url: 'save-image-to-photos-album'
335
              },
W
wanganxp 已提交
336
              // #endif
Y
yurj26 已提交
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 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
              /* {
                name: "图片选择和拍照",
                url: "image",
                enable: false
              },{
                name: "音频",
                url: "inner-audio",
              },
              {
                name: "录音",
                url: "voice",
              },
              {
                name: "背景音频",
                url: "background-audio",
              },
              {
                name: "视频选择和拍照",
                url: "video",
                enable: false
              },
              {
                name: "文件",
                url: "file",
              },
              {
                name: "保存媒体到本地",
                url: "save-media",
              }, */
            ] as Page[],
          },
          {
            id: 'location',
            name: '位置',
            pages: [
              {
                name: '获取当前位置',
                url: 'get-location',
              },
              /* {
                name: "使用地图查看位置",
                url: "open-location",
              },
              {
                name: "使用地图选择位置",
                url: "choose-location",
              },
              {
                name: "地图控制",
                url: "map",
              },
              {
                name: "地图搜索",
                url: "map-search",
              }, */
            ] as Page[],
393
          },
Y
yurj26 已提交
394 395 396 397 398 399 400
          {
            id: 'storage',
            name: '数据存储',
            pages: [
              {
                name: 'storage(key-value存储)',
                url: 'storage',
D
DCloud_LXH 已提交
401
                api: ["getStorageInfo", "getStorageInfoSync", "getStorage", "getStorageSync", "setStorage", "setStorageSync", "removeStorage", "removeStorageSync", "clearStorage", "clearStorageSync"]
雪洛's avatar
雪洛 已提交
402
              }
W
wanganxp 已提交
403
            ] as Page[],
404 405
          },
          // #ifdef APP-ANDROID
W
wanganxp 已提交
406
          {
W
wanganxp 已提交
407 408 409
            id: 'file',
            name: '文件',
            pages: [
雪洛's avatar
雪洛 已提交
410 411 412 413 414
              {
                name: 'fileSystemManager文件管理',
                url: 'get-file-system-manager'
              },
            ] as Page[],
415
          },
W
wanganxp 已提交
416
          // #endif
雪洛's avatar
雪洛 已提交
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
          {
            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',
Y
yurj26 已提交
447
              },
雪洛's avatar
雪洛 已提交
448 449 450 451
              {
                name: '实人认证',
                url: 'facial-recognition-verify',
              }
Y
yurj26 已提交
452
            ] as Page[],
雪洛's avatar
雪洛 已提交
453
          },
W
wanganxp 已提交
454
          // #endif
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
          // #ifdef APP-ANDROID
          {
            id: 'ad',
            name: '广告',
            pages: [
              {
                name: '激励视频广告',
                url: 'rewarded-video-ad',
              }
            ] as Page[],
          },
          {
            id: 'permission-listener',
            name: '权限申请监听',
            pages: [
              {
                name: '权限申请监听',
                url: 'create-request-permission-listener',
              }
            ] as Page[]
M
mahaifeng 已提交
475 476 477 478 479 480 481 482 483 484 485
          },
          {
            id: "payment",
            name: "支付",
            pages: [
              {
                name: "发起支付",
                url: "request-payment",
              },
            ] as Page[],
          }
486
          // #endif
Y
yurj26 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
          /* {
            id: "rewarded-video-ad",
            url: "rewarded-video-ad",
            name: "激励视频广告",
            enable: false,
            pages: [] as Page[]
          },
          {
            id: "full-screen-video-ad",
            url: "full-screen-video-ad",
            name: "全屏视频广告",
            enable: false,
            pages: [] as Page[]
          },
          {
            id: "login",
            name: "登录",
            pages: [
              {
                name: "登录",
                url: "login",
              },
              {
                name: "获取用户信息",
                url: "get-user-info",
              },
            ] as Page[],
          },
          {
            id: "share",
            name: "分享",
            pages: [
              {
                name: "分享",
                url: "share",
              },
            ] as Page[],
          },
          {
            id: "payment",
            name: "支付",
            pages: [
              {
                name: "发起支付",
                url: "request-payment",
              },
            ] as Page[],
          },
W
wanganxp 已提交
535
          */
Y
yurj26 已提交
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
        ] as ListItem[],
        arrowUpIcon: '/static/icons/arrow-up.png',
        arrowDownIcon: '/static/icons/arrow-down.png',
        arrowRightIcon: '/static/icons/arrow-right.png',
      }
    },
    methods: {
      goDetailPage(e : Page) {
        if (e.enable == false) {
          uni.showToast({
            title: '暂不支持',
            icon: 'none',
          })
          return
        }
        if (e.url === 'set-tabbar') {
          this.showPop()
          return;
W
wanganxp 已提交
554
        }
Y
yurj26 已提交
555 556 557 558 559 560 561
        const url =
          e.url.indexOf('platform') > -1 ? e.url : `/pages/API/${e.url}/${e.url}`
        uni.navigateTo({
          url,
        })
      },
      showPop: function () {
DCloud-yyl's avatar
DCloud-yyl 已提交
562
        (this.$refs["pop"] as UniElement).style.setProperty("display", "flex")
Y
yurj26 已提交
563 564
      },
      hidePop: function () {
DCloud-yyl's avatar
DCloud-yyl 已提交
565
        (this.$refs["pop"] as UniElement).style.setProperty("display", "none")
Y
yurj26 已提交
566
      },
张磊 已提交
567
      stopClickPop: function (e : PointerEvent) {
Y
yurj26 已提交
568
        e.stopPropagation() //点击到pop的非灰色区域,拦截点击事件
W
wanganxp 已提交
569
      }
Y
yurj26 已提交
570 571
    },
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
572 573 574
</script>

<style>
Y
yurj26 已提交
575 576 577
  .item {
    margin-bottom: 12px;
  }
578 579

  .popup {
580
    width: 100%;
581 582
    /* #ifdef APP */
    position: absolute;
583 584 585 586 587
    height: 100%;
    /* #else */
    position: fixed;
    top: var(--window-top);
    bottom: var(--window-bottom);
588 589 590 591 592 593 594
    /* #endif */
    align-items: center;
    justify-content: center;
    display: none;
    background-color: rgba(16, 16, 16, 0.5);
  }
</style>