version.js 1.9 KB

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