publicMethods.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { toast } from '@whale.io/mini/es/utils/fn';
  2. export * from '@whale.io/common/es/utils/fn';
  3. let systemInfo;
  4. /**
  5. * 转换rpx为px.
  6. *
  7. * @param rpx responsive pixel.
  8. * @returns pixel unit.
  9. * @see https://opendocs.alipay.com/mini/framework/acss#rpx
  10. */
  11. function rpxToPx(rpx) {
  12. if (!systemInfo) {
  13. systemInfo = my.getSystemInfoSync();
  14. }
  15. return rpx * (systemInfo.windowWidth / 750);
  16. }
  17. /**
  18. * 解析小程序之间相互跳转scheme.
  19. *
  20. * @param scheme Schema需符合`alipays://platformapi/startapp?appId=&page=`形式,page中如果还有其它url参数需encode.
  21. * @returns
  22. */
  23. function parseMiniScheme(scheme) {
  24. let miniParams = {};
  25. scheme = scheme || '';
  26. if (scheme.indexOf('alipays://platformapi/startapp') >= 0) {
  27. const schemaSegments = scheme.split('?');
  28. const pathParams = schemaSegments[1];
  29. const values = pathParams.split('&');
  30. values.forEach(item => {
  31. miniParams = miniParams || {};
  32. const [key, val] = item.split('=');
  33. miniParams[key] = val;
  34. });
  35. }
  36. return miniParams;
  37. }
  38. export { rpxToPx, toast, parseMiniScheme };