@
xiangyuecn 根据老哥的建议,我已经把调用 native 接口时检测平台的逻辑移入 NativeMethods 类,通过装饰器注入检测平台逻辑,代码如下😇:
```
class NativeMethods {
// 同步到日历
@
p()
public syncCalendar(params: SyncCalendarParams) {
...
}
}
/**
* @
param {platforms} - 接口限制的平台
* @
return {Function} - 装饰器
*/
function p(platforms = ['android', 'ios']) {
return (target: AnyObject, name: string, descriptor: PropertyDescriptor) => {
if (!platforms.includes(window.$platform)) {
descriptor.value = () => {
return Vue.prototype.$toast(
`当前处在 ${window.$platform} 环境,无法调用接口哦`
);
};
}
return descriptor;
};
}
```