version.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { getAppBaseInfo } from './wechat';
  2. let systemInfo;
  3. function getSystemInfo() {
  4. if (systemInfo == null) {
  5. systemInfo = getAppBaseInfo();
  6. }
  7. return systemInfo;
  8. }
  9. export function compareVersion(v1, v2) {
  10. v1 = v1.split('.');
  11. v2 = v2.split('.');
  12. const len = Math.max(v1.length, v2.length);
  13. while (v1.length < len) {
  14. v1.push('0');
  15. }
  16. while (v2.length < len) {
  17. v2.push('0');
  18. }
  19. for (let i = 0; i < len; i++) {
  20. const num1 = parseInt(v1[i]);
  21. const num2 = parseInt(v2[i]);
  22. if (num1 > num2) {
  23. return 1;
  24. }
  25. else if (num1 < num2) {
  26. return -1;
  27. }
  28. }
  29. return 0;
  30. }
  31. function judgeByVersion(version) {
  32. const currentSDKVersion = getSystemInfo().SDKVersion;
  33. return compareVersion(currentSDKVersion, version) >= 0;
  34. }
  35. export function canIUseFormFieldButton() {
  36. return judgeByVersion('2.10.3');
  37. }
  38. export function canUseVirtualHost() {
  39. return judgeByVersion('2.19.2');
  40. }
  41. export function canUseProxyScrollView() {
  42. return judgeByVersion('2.19.2');
  43. }