-
Notifications
You must be signed in to change notification settings - Fork 19
/
wxopendata.ts
58 lines (49 loc) · 1.23 KB
/
wxopendata.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
declare const wx;
interface KVData
{
key:string;
value:string;
}
//改动后需同步改动 项目根目录/subdomain/consts.js
export const enum WxOpenDataKeys
{
Grade = "grade",
}
//改动后需同步改动 项目根目录/subdomain/consts.js
export const enum WxDomainAction
{
FetchFriend = 1,
FetchGroup = 2,
Paging = 3,
}
export interface WxDomainMessage
{
action:WxDomainAction;
data?:any; //https://developers.weixin.qq.com/minigame/dev/document/open-api/context/OpenDataContext.postMessage.html
}
class WxOpenData
{
wxSetUserCloudStorage(kvDatas:KVData[])
{
wx.setUserCloudStorage({
KVDataList:kvDatas,
success:res => {
console.log("setUserCloudStorage success", res);
},
fail:res => {
console.log("setUserCloudStorage fail", res);
},
});
}
wxPostMessageToSubDomain(msgObj:WxDomainMessage)
{
const openDataContext = wx.getOpenDataContext();
openDataContext.postMessage(msgObj);
}
wxGetSharedCanvas()
{
const openDataContext = wx.getOpenDataContext();
return openDataContext.canvas;
}
}
export const wxOpenData = new WxOpenData();