version.js 919 B

12345678910111213141516171819202122232425262728293031323334353637
  1. let systemInfo;
  2. function getSystemInfo() {
  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]);
  20. const num2 = parseInt(v2[i]);
  21. if (num1 > num2) {
  22. return 1;
  23. }
  24. else if (num1 < num2) {
  25. return -1;
  26. }
  27. }
  28. return 0;
  29. }
  30. function judgeByVersion(version) {
  31. const currentSDKVersion = getSystemInfo().SDKVersion;
  32. return compareVersion(currentSDKVersion, version) >= 0;
  33. }
  34. export function canIUseFormFieldButton() {
  35. const version = '2.10.3';
  36. return judgeByVersion(version);
  37. }