version.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. let systemInfo;
  2. export function getSystemInfoSync() {
  3. if (systemInfo == null) {
  4. systemInfo = wx.getSystemInfoSync();
  5. }
  6. return systemInfo;
  7. }
  8. function compareVersion(v1, v2) {
  9. v1 = v1.split('.');
  10. v2 = v2.split('.');
  11. const len = Math.max(v1.length, v2.length);
  12. while (v1.length < len) {
  13. v1.push('0');
  14. }
  15. while (v2.length < len) {
  16. v2.push('0');
  17. }
  18. for (let i = 0; i < len; i++) {
  19. const num1 = parseInt(v1[i], 10);
  20. const num2 = parseInt(v2[i], 10);
  21. if (num1 > num2) {
  22. return 1;
  23. }
  24. if (num1 < num2) {
  25. return -1;
  26. }
  27. }
  28. return 0;
  29. }
  30. function gte(version) {
  31. const system = getSystemInfoSync();
  32. return compareVersion(system.SDKVersion, version) >= 0;
  33. }
  34. export function canIUseModel() {
  35. return gte('2.9.3');
  36. }
  37. export function canIUseFormFieldButton() {
  38. return gte('2.10.3');
  39. }
  40. export function canIUseAnimate() {
  41. return gte('2.9.0');
  42. }
  43. export function canIUseGroupSetData() {
  44. return gte('2.4.0');
  45. }
  46. export function canIUseNextTick() {
  47. try {
  48. return wx.canIUse('nextTick');
  49. }
  50. catch (e) {
  51. return gte('2.7.1');
  52. }
  53. }
  54. export function canIUseCanvas2d() {
  55. return gte('2.9.0');
  56. }
  57. export function canIUseGetUserProfile() {
  58. return !!wx.getUserProfile;
  59. }