index.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // @ts-nocheck
  2. // #ifdef MP-ALIPAY
  3. interface My {
  4. SDKVersion: string
  5. }
  6. declare var my: My
  7. // #endif
  8. function compareVersion(v1:string, v2:string) {
  9. let a1 = v1.split('.');
  10. let a2 = v2.split('.');
  11. const len = Math.max(a1.length, a2.length);
  12. while (a1.length < len) {
  13. a1.push('0');
  14. }
  15. while (a2.length < len) {
  16. a2.push('0');
  17. }
  18. for (let i = 0; i < len; i++) {
  19. const num1 = parseInt(a1[i], 10);
  20. const num2 = parseInt(a2[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: string) {
  31. let {SDKVersion} = uni.getSystemInfoSync();
  32. // #ifdef MP-ALIPAY
  33. SDKVersion = my.SDKVersion
  34. // #endif
  35. return compareVersion(SDKVersion, version) >= 0;
  36. }
  37. /** 环境是否支持canvas 2d */
  38. export function canIUseCanvas2d() {
  39. // #ifdef MP-WEIXIN
  40. return gte('2.9.0');
  41. // #endif
  42. // #ifdef MP-ALIPAY
  43. return gte('2.7.0');
  44. // #endif
  45. // #ifdef MP-TOUTIAO
  46. return gte('1.78.0');
  47. // #endif
  48. // #ifndef MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO
  49. return false
  50. // #endif
  51. }