get-provider.uvue 2.1 KB
Newer Older
1 2 3 4 5 6
<template>
  <!-- #ifdef APP -->
  <scroll-view class="page-scroll-view">
  <!-- #endif -->
    <view class="page">
      <page-head :title="title"></page-head>
H
hdx 已提交
7 8 9 10
      <view class="service-item" v-for="(item, index) in serviceList" :key="index">
        <text class="service-name">{{item.name}}:</text>
        <view class="provider-list">
          <text class="provider-item" v-for="(item2, index2) in item.provider" :key="index2">{{item2}}</text>
11 12 13 14 15 16 17 18
        </view>
      </view>
      <button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>
H
hdx 已提交
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
<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[]) {
H
hdx 已提交
52
        const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => {
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
          return item.service == service
        });
        if (item != null) {
          item.provider = provider
        }
      }
    }
  }
</script>

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

H
hdx 已提交
68 69
  .service-item {
    margin-top: 10px;
70 71
  }

H
hdx 已提交
72
  .service-name {
73
    font-weight: bold;
H
hdx 已提交
74 75 76 77 78 79 80 81 82 83 84 85
  }

  .provider-list {
    margin-left: 32px;
  }

  .provider-item {
    line-height: 1.5;
  }

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