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