version.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // 获取系统信息
  2. let systemInfo;
  3. function getSystemInfo() {
  4. if (systemInfo == null) {
  5. systemInfo = wx.getSystemInfoSync();
  6. }
  7. return systemInfo;
  8. }
  9. // 版本号比较, 参考:https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html
  10. function compareVersion(v1, v2) {
  11. v1 = v1.split('.');
  12. v2 = v2.split('.');
  13. const len = Math.max(v1.length, v2.length);
  14. while (v1.length < len) {
  15. v1.push('0');
  16. }
  17. while (v2.length < len) {
  18. v2.push('0');
  19. }
  20. for (let i = 0; i < len; i++) {
  21. const num1 = parseInt(v1[i]);
  22. const num2 = parseInt(v2[i]);
  23. if (num1 > num2) {
  24. return 1;
  25. }
  26. else if (num1 < num2) {
  27. return -1;
  28. }
  29. }
  30. return 0;
  31. }
  32. function judgeByVersion(version) {
  33. const currentSDKVersion = getSystemInfo().SDKVersion;
  34. return compareVersion(currentSDKVersion, version) >= 0;
  35. }
  36. export function canIUseFormFieldButton() {
  37. const version = '2.10.3';
  38. return judgeByVersion(version);
  39. }
  40. //# sourceMappingURL=version.js.map