plus.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.initPlus = void 0;
  4. const shared_1 = require("@vue/shared");
  5. const merge_1 = require("merge");
  6. const wxPageOrientationMapping = {
  7. auto: [
  8. 'portrait-primary',
  9. 'portrait-secondary',
  10. 'landscape-primary',
  11. 'landscape-secondary',
  12. ],
  13. portrait: ['portrait-primary', 'portrait-secondary'],
  14. landscape: ['landscape-primary', 'landscape-secondary'],
  15. };
  16. function initPlus(manifestJson, pagesJson) {
  17. initUniStatistics(manifestJson);
  18. // 转换为老版本配置
  19. if (manifestJson.plus.modules) {
  20. manifestJson.permissions = manifestJson.plus.modules;
  21. delete manifestJson.plus.modules;
  22. }
  23. const distribute = manifestJson.plus.distribute;
  24. if (distribute) {
  25. if (distribute.android) {
  26. manifestJson.plus.distribute.google = distribute.android;
  27. delete manifestJson.plus.distribute.android;
  28. }
  29. if (distribute.ios) {
  30. manifestJson.plus.distribute.apple = distribute.ios;
  31. delete manifestJson.plus.distribute.ios;
  32. }
  33. if (distribute.sdkConfigs) {
  34. manifestJson.plus.distribute.plugins = distribute.sdkConfigs;
  35. delete manifestJson.plus.distribute.sdkConfigs;
  36. }
  37. if (manifestJson.plus.darkmode) {
  38. if (!(distribute.google || (distribute.google = {})).defaultNightMode) {
  39. distribute.google.defaultNightMode = 'auto';
  40. }
  41. if (!(distribute.apple || (distribute.apple = {})).UIUserInterfaceStyle) {
  42. distribute.apple.UIUserInterfaceStyle = 'Automatic';
  43. }
  44. }
  45. }
  46. // 屏幕启动方向
  47. if (manifestJson.plus.screenOrientation) {
  48. // app平台优先使用 manifest 配置
  49. manifestJson.screenOrientation = manifestJson.plus.screenOrientation;
  50. delete manifestJson.plus.screenOrientation;
  51. }
  52. else if (pagesJson.globalStyle?.pageOrientation) {
  53. // 兼容微信小程序
  54. const pageOrientationValue = wxPageOrientationMapping[pagesJson.globalStyle
  55. .pageOrientation];
  56. if (pageOrientationValue) {
  57. manifestJson.screenOrientation = pageOrientationValue;
  58. }
  59. }
  60. // 全屏配置
  61. manifestJson.fullscreen = manifestJson.plus.fullscreen;
  62. // 地图坐标系
  63. if (manifestJson.permissions && manifestJson.permissions.Maps) {
  64. manifestJson.permissions.Maps.coordType = 'gcj02';
  65. }
  66. if (!manifestJson.permissions) {
  67. manifestJson.permissions = {};
  68. }
  69. manifestJson.permissions.UniNView = {
  70. description: 'UniNView原生渲染',
  71. };
  72. // 允许内联播放视频
  73. manifestJson.plus.allowsInlineMediaPlayback = true;
  74. if (!manifestJson.plus.distribute) {
  75. manifestJson.plus.distribute = {
  76. plugins: {},
  77. };
  78. }
  79. if (!manifestJson.plus.distribute.plugins) {
  80. manifestJson.plus.distribute.plugins = {};
  81. }
  82. // 录音支持 mp3
  83. manifestJson.plus.distribute.plugins.audio = {
  84. mp3: {
  85. description: 'Android平台录音支持MP3格式文件',
  86. },
  87. };
  88. // 有效值为 close,none
  89. if (!['close', 'none'].includes(manifestJson.plus.popGesture)) {
  90. manifestJson.plus.popGesture = 'close';
  91. }
  92. }
  93. exports.initPlus = initPlus;
  94. function initUniStatistics(manifestJson) {
  95. // 根节点配置了统计
  96. if (manifestJson.uniStatistics) {
  97. manifestJson.plus.uniStatistics = (0, merge_1.recursive)(true, manifestJson.uniStatistics, manifestJson.plus.uniStatistics);
  98. delete manifestJson.uniStatistics;
  99. }
  100. if (!process.env.UNI_CLOUD_PROVIDER) {
  101. return;
  102. }
  103. let spaces = [];
  104. try {
  105. spaces = JSON.parse(process.env.UNI_CLOUD_PROVIDER);
  106. }
  107. catch (e) { }
  108. if (!(0, shared_1.isArray)(spaces) || !spaces.length) {
  109. return;
  110. }
  111. const space = spaces[0];
  112. if (!space) {
  113. return;
  114. }
  115. const uniStatistics = manifestJson.plus?.uniStatistics;
  116. if (!uniStatistics) {
  117. return;
  118. }
  119. if (uniStatistics.version === 2 || uniStatistics.version === '2') {
  120. if (uniStatistics.uniCloud && uniStatistics.uniCloud.spaceId) {
  121. return;
  122. }
  123. uniStatistics.uniCloud = {
  124. provider: space.provider,
  125. spaceId: space.spaceId,
  126. clientSecret: space.clientSecret,
  127. endpoint: space.endpoint,
  128. };
  129. }
  130. }