index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_platform_provider_wechat_index = require("./provider/wechat/index.js");
  4. const sheep_platform_provider_apple_index = require("./provider/apple/index.js");
  5. const sheep_platform_share = require("./share.js");
  6. const sheep_platform_pay = require("./pay.js");
  7. const device = common_vendor.index.getSystemInfoSync();
  8. const os = device.platform;
  9. let name = "";
  10. let provider = "";
  11. let platform = "";
  12. let isWechatInstalled = true;
  13. name = "WechatMiniProgram";
  14. platform = "miniProgram";
  15. provider = "wechat";
  16. if (common_vendor.lodashExports.isEmpty(name)) {
  17. common_vendor.index.showToast({
  18. title: "暂不支持该平台",
  19. icon: "none"
  20. });
  21. }
  22. const load = () => {
  23. if (provider === "wechat") {
  24. sheep_platform_provider_wechat_index.wechat.load();
  25. }
  26. };
  27. const useProvider = (_provider = "") => {
  28. if (_provider === "")
  29. _provider = provider;
  30. if (_provider === "wechat")
  31. return sheep_platform_provider_wechat_index.wechat;
  32. if (_provider === "apple")
  33. return sheep_platform_provider_apple_index.apple;
  34. };
  35. const pay = (payment, orderType, orderSN) => {
  36. return new sheep_platform_pay.SheepPay(payment, orderType, orderSN);
  37. };
  38. const checkUpdate = (silence = false) => {
  39. useProvider().checkUpdate(silence);
  40. };
  41. async function checkNetwork() {
  42. const networkStatus = await common_vendor.index.getNetworkType();
  43. if (networkStatus.networkType == "none") {
  44. return Promise.resolve(false);
  45. }
  46. return Promise.resolve(true);
  47. }
  48. const getCapsule = () => {
  49. let capsule2 = common_vendor.index.getMenuButtonBoundingClientRect();
  50. if (!capsule2) {
  51. capsule2 = {
  52. bottom: 56,
  53. height: 32,
  54. left: 278,
  55. right: 365,
  56. top: 24,
  57. width: 87
  58. };
  59. }
  60. return capsule2;
  61. };
  62. const capsule = getCapsule();
  63. const getNavBar = () => {
  64. return device.statusBarHeight + 44;
  65. };
  66. const navbar = getNavBar();
  67. function getLandingPage() {
  68. let page = "";
  69. return page;
  70. }
  71. const landingPage = getLandingPage();
  72. const _platform = {
  73. name,
  74. device,
  75. os,
  76. provider,
  77. platform,
  78. useProvider,
  79. checkUpdate,
  80. checkNetwork,
  81. pay,
  82. share: sheep_platform_share.$share,
  83. load,
  84. capsule,
  85. navbar,
  86. landingPage,
  87. isWechatInstalled
  88. };
  89. exports._platform = _platform;