-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
70 lines (62 loc) · 1.8 KB
/
Copy pathapp.js
File metadata and controls
70 lines (62 loc) · 1.8 KB
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
import config from './utils/config.js';
import { ensureUser } from './utils/auth.js';
import { addDiagnostic } from './utils/diagnostics.js';
import { syncPendingConsentState } from './utils/privacy.js';
function fallbackUser() {
return {
id: 'guest_fallback',
nickname: '附近用户',
avatarUrl: '',
role: 'user',
isGuest: true,
profileCompleted: false,
loggedInAt: 0
};
}
App({
globalData: {
user: null,
center: { ...config.defaultCenter },
locationKnown: false,
cloudReady: false
},
onLaunch() {
if (config.cloud.enabled && config.cloud.envId && wx.cloud && wx.cloud.init) {
try {
wx.cloud.init({
env: config.cloud.envId,
traceUser: false
});
this.globalData.cloudReady = true;
} catch (error) {
this.globalData.cloudReady = false;
addDiagnostic('app.cloud.init', error);
}
} else if (config.cloud.enabled) {
addDiagnostic('app.cloud.skip', 'wx.cloud is unavailable or envId is empty');
}
try {
this.globalData.user = ensureUser();
} catch (error) {
addDiagnostic('app.ensureUser', error);
this.globalData.user = fallbackUser();
}
syncPendingConsentState().then((result) => {
if (result && result.pending) {
addDiagnostic('app.consent.sync', result.code || 'pending');
}
}).catch((error) => addDiagnostic('app.consent.sync', error));
},
onError(error) {
addDiagnostic('app.onError', error);
console.error(error);
},
onUnhandledRejection(event) {
const reason = event && event.reason ? event.reason : event;
addDiagnostic('app.unhandledRejection', reason);
console.error(reason);
},
onPageNotFound(event) {
addDiagnostic('app.pageNotFound', event && event.path ? event.path : event);
}
});