version.js 1.1KB

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