generated from CyanAsterisk/.github
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.ts
35 lines (31 loc) · 909 Bytes
/
app.ts
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
import { getSetting, getUserInfo } from "./utils/wxapi"
import {IAppOption} from "./appoption"
import { FreeCar } from "./service/pkg/request"
let resolveUserInfo: (value: WechatMiniprogram.UserInfo | PromiseLike<WechatMiniprogram.UserInfo>) => void
let rejectUserInfo: (reason?: any) => void
// app.ts
App<IAppOption>({
globalData: {
userInfo:new Promise((resolve,reject)=>{
resolveUserInfo = resolve
rejectUserInfo = reject
})
},
async onLaunch() {
//登录
await FreeCar.login()
// 获取用户信息
try {
const setting = await getSetting()
if (setting.authSetting['scope.userInfo']) {
const userInfoRes = await getUserInfo()
resolveUserInfo(userInfoRes.userInfo)
}
} catch (err) {
rejectUserInfo(err)
}
},
resolveUserInfo(userInfo: WechatMiniprogram.UserInfo) {
resolveUserInfo(userInfo)
}
})