-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathzfjs-sdk.js
152 lines (142 loc) · 4.76 KB
/
zfjs-sdk.js
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
! function (windowz, n) {
n(windowz, !0)
}(window, function (windowz, open) {
/**
* 调用zfJSBridge执行api
* @param {String} apiName
* @param {Any} params
* @param {
* success:((res:String)->Unit)?,
* fail:((res:String)->Unit)?)?
* cancel:((res:String)->Unit)?)?
* complete:((res:String)->Unit)?)? 操作完成后一定会调用
* } callBack res对象包括 errCode errMsg
*/
function call(apiName, params, callBack) {
windowz.zfJSBridge ? windowz.zfJSBridge.call(apiName, checkParams(params), function (ret) {
callBack._complete && callBack._complete(ret) || delete callBack._complete
var errCode = ret && ret['errCode']
switch (errCode) {
case 0:
callBack.success && callBack.success(ret)
break
case 1:
callBack.cancel && callBack.cancel(ret)
break
default:
callBack.fail && callBack.fail(ret)
break
}
callBack.complete && callBack.complete(ret)
}) : defCall(apiName, callBack)
}
function checkParams(params) {
return params || {}
}
function defCall(apiName, callBack) {
callBack.complete && callBack.complete()
console.log("zfJSBridge not found ," + apiName)
}
function on(eventName, callBack) {
windowz.zfJSBridge ? windowz.zfJSBridge.on(eventName, function (ret) {
callBack(ret)
}) : defOn(eventName, callBack)
}
function defOn(eventName, callBack) {
callBack.complete && callBack.complete()
console.log("zfJSBridge not found ," + eventName)
}
var api = {
config: function (e) {
call("config", {}, (e._complete = function () {
console.log("_complete config")
}, e))
}, setTitle: function (e) {
call("setTitle", {
title: e.title || ""
}, e)
}, backCloseWindow: function (e) {
call("backCloseWindow", {
}, e)
}, closeWindow: function (e) {
call("closeWindow", {
}, e)
}, putLocalStorageKV: function (e) {
call("putLocalStorageKV", {
key: e.key || "",
value: e.value || ""
}, e)
}, getLocalStorageKV: function (e) {
call("getLocalStorageKV", {
key: e.key || ""
}, e)
},
choosePhotos: function (e) {
call("choosePhotos", {
enableCount: e.enableCount || (e.enableCount == undefined ? 0 : e.enableCount)
}, e)
},
uploadPhotos: function (e) {
call("uploadPhotos", {
nativeResourceUrls: e.nativeResourceUrls || []
}, e)
},
previewPhotos: function (e) {
call("previewPhotos", {
urls: e.urls || [],
index: e.index || (e.index == undefined ? 0 : e.index)
}, e)
},
chooseVideos: function (e) {
call("chooseVideos", {
enableCount: e.enableCount || (e.enableCount == undefined ? 0 : e.enableCount)
}, e)
},
uploadVideos: function (e) {
call("uploadVideos", {
nativeResourceUrls: e.nativeResourceUrls || []
}, e)
},
previewVideo: function (e) {
call("previewVideo", {
url: e.url || ""
}, e)
},
chooseFile: function (e) {
call("chooseFile", {
enableCount: e.enableCount || (e.enableCount == undefined ? 0 : e.enableCount),
maxSize: e.maxSize || (e.maxSize == undefined ? 0 : e.maxSize),
isMultiSelect: e.isMultiSelect || (e.isMultiSelect == undefined ? true : e.isMultiSelect)
}, e)
},
uploadFile: function (e) {
call("uploadFile", {
nativeResourceUrls: e.nativeResourceUrls || []
}, e)
},
previewFile: function (e) {
call("previewFile", {
url: e.url || ""
}, e)
},
chooseLocation: function (e) {
call("chooseLocation", {
}, e)
},
getLocation: function (e) {
call("getLocation", {
}, e)
},
previewLocation: function (e) {
call("previewLocation", {
}, e)
},
onContainerResume: function (e) {
on("onContainerResume", e)
},
onContainerPause: function (e) {
on("onContainerPause", e)
}
}
return open && (windowz.zfApi = api), api
})