cikenerd 186b0156df
fix: 修复插件内使用 van-tabs 切换 tab 报错的问题 (#5073)
* 修复插件内使用van-tabs切换tab报错的问题

* fix(van-tabs): 修复小程序插件内使用van-tabs切换tab没有反应的问题
feat(van-tabs): incorrect style
docs(van-tabs): 去除utils,version里面require循环依赖,修复插件内调用wx.canIUse抛异常问题

* fix(van-tabs): 修复小程序插件内使用van-tabs切换tab没有反应的问题
feat(van-tabs): incorrect style
docs(van-tabs): 去除utils,version里面require循环依赖,修复插件内调用wx.canIUse抛异常问题

* fix(van-tabs): incorrect style
feat(van-tabs): incorrect style
docs(van-tabs): incorrect style
2022-10-26 14:29:38 +08:00

74 lines
1.3 KiB
TypeScript

let systemInfo: WechatMiniprogram.SystemInfo;
export function getSystemInfoSync() {
if (systemInfo == null) {
systemInfo = wx.getSystemInfoSync();
}
return systemInfo;
}
function compareVersion(v1, v2) {
v1 = v1.split('.');
v2 = v2.split('.');
const len = Math.max(v1.length, v2.length);
while (v1.length < len) {
v1.push('0');
}
while (v2.length < len) {
v2.push('0');
}
for (let i = 0; i < len; i++) {
const num1 = parseInt(v1[i], 10);
const num2 = parseInt(v2[i], 10);
if (num1 > num2) {
return 1;
}
if (num1 < num2) {
return -1;
}
}
return 0;
}
function gte(version: string) {
const system = getSystemInfoSync();
return compareVersion(system.SDKVersion, version) >= 0;
}
export function canIUseModel() {
return gte('2.9.3');
}
export function canIUseFormFieldButton() {
return gte('2.10.3');
}
export function canIUseAnimate() {
return gte('2.9.0');
}
export function canIUseGroupSetData() {
return gte('2.4.0');
}
export function canIUseNextTick() {
try {
return wx.canIUse('nextTick');
} catch (e) {
return gte('2.7.1');
}
}
export function canIUseCanvas2d() {
return gte('2.9.0');
}
export function canIUseGetUserProfile() {
return !!wx.getUserProfile;
}