get-provider.uvue 2.0 KB
Newer Older
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
<template>
  <!-- #ifdef APP -->
  <scroll-view class="page-scroll-view">
  <!-- #endif -->
    <view class="page">
      <page-head :title="title"></page-head>
      <view>
        <view class="service-item" v-for="(item, index) in serviceList" :key="index">
          <text class="item-k">{{item.name}}</text>
          <view class="item-v">
            <text v-for="(item2, index2) in item.provider" :key="index2">{{item2}}</text>
          </view>
        </view>
      </view>
      <button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>
<script>
  type ProviderItem = {
    service : string,
    name : string,
    provider : string[]
  }

  export default {
    data() {
      return {
        title: 'provider',
        serviceList: [
          { service: "oauth", name: "登陆", provider: [] },
          { service: "share", name: "分享", provider: [] },
          { service: "payment", name: "支付", provider: [] },
          { service: "push", name: "推送", provider: [] },
          { service: "location", name: "定位", provider: [] }
        ] as ProviderItem[]
      }
    },
    methods: {
      getProvider() {
        this.serviceList.forEach((item : ProviderItem) => {
          uni.getProvider({
            service: item.service,
            success: (e) => {
              this.updateProvider(e.service, e.provider);
            }
          })
        })
      },
      updateProvider(service : string, provider : string[]) {
        const item = this.serviceList.find((item : ProviderItem) => {
          return item.service == service
        });
        if (item != null) {
          item.provider = provider
        }
      }
    }
  }
</script>

<style>
  .page {
    padding: 15px;
  }

  .item-k {
    line-height: 2;
  }

  .item-v {
    font-weight: bold;
    line-height: 2;
  }

  .btn-get-provider {
    margin-top: 50px;
  }
</style>