# PluginAuthorize 插件授权
# 介绍
统一插件落地页授权组件,用于插件授权检查,获取手机号等逻辑。
# 使用指南
# 一般用法

<tms-plugin-authorize
id="com-plg"
provider="{{provider}}"
options="{{options}}"
showAuth="{{showAuth}}" />
Page({
data: {
provider: {
title: '同程旅行',
logo: 'https://static.img.tai.qq.com/mp/images/sp/logo-tcbus.png',
agreement: 'busticket.html', // 授权协议 H5 地址
mpId: 'xxxx', // TMSGO 分配
authKey: 'xxxAuthStatus', // 授权状态标识
plugin: 'xxxxMain', // 插件名称
},
options: {},
showAuth: false,
},
async onLoad(options) {
wx.showLoading({ title: '加载中...' });
this.plugin = this.selectComponent('#com-plg');
await this.formatOptions(options); // 格式化参数
const authStatus = await this.plugin.fetchAuthStatus();
if (!authStatus) {
this.setData({ showAuth: true });
wx.setNavigationBarTitle({ title: '信息授权' });
} else {
this.plugin.goPlugin();
}
wx.hideLoading();
},
// 格式化参数
async formatOptions(originOptions) {
const { target, path, order } = originOptions;
const options = {};
options.pagePath = decodeURIComponent(path || '');
if (order) { // 订单进入
options.pagePath = '/orderDetail';
const openId = await this.plugin.fetchOpenId();
options.paramData = {
openId,
orderId: order,
};
}
this.setData({ options });
},
});
# 打开位置
从顶部弹出
<button bindtap="_showFromTop">打开</button>
<tms-popup show="{{showFromTop}}" position="top">
<view class="content"/>
</tms-popup>
# API
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| provider | 服务商信息 | object | - | - |
| options | onLoad 参数 | object | - | - |
| showAuth | 授权逻辑展示控制 | boolean | false | - |

