index.ts 1.2 KB

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