<template lang="">
  <div>
    <div class="">
      <div class="">window.webkit: {{ hasWebkit }}</div>
      <div class="">
        window.webkit.messageHandlers: {{ hasMessageHandlers }}
      </div>
      <div class="">
        window.webkit.messageHandlers.setShareInfo: {{ hasSetShareInfo }}
      </div>
      <div class="">
        window.webkit.messageHandlers.openShare: {{ hasOpenShare }}
      </div>
      <div class="">
        <div class="">messageHandlersKeys {{ messageHandlersKeys.length }}</div>
        <div v-for="item in messageHandlersKeys" :key="item">
          {{ item }}
        </div>
      </div>
    </div>
    <v-btn @click="setShareInfo">setShareInfo</v-btn>
    <v-btn @click="openShare">openShare</v-btn>
  </div>
</template>
<script>
export default {
  auth: false,
  data() {
    return {
      hasWebkit: !!window?.webkit,
      hasMessageHandlers: !!window?.webkit?.messageHandlers,
      hasSetShareInfo: !!window?.webkit?.messageHandlers?.setShareInfo,
      hasOpenShare: !!window?.webkit?.messageHandlers?.openShare,
      messageHandlersKeys: Object.keys(window?.webkit?.messageHandlers ?? {}),
    };
  },
  fetch() {
    try {
      this.setShareInfo();
    } catch (error) {}
  },
  mounted() {
    // this.
  },
  methods: {
    setShareInfo() {
      window.webkit.messageHandlers.setShareInfo.postMessage({
        title: '邀请好友赚星币',
        gotoUrl: 'http://www.baidu.com',
        shareImg:
          'http://gntest.phone.androidscloud.com:1280/cloud/phone/web/static/img/logo.c898a0c6.png',
      });
    },
    openShare() {
      window.webkit.messageHandlers.openShare.postMessage();
    },
  },
};
</script>
