Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
IBMS
/
nativeview
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e2d37674
authored
Feb 22, 2022
by
huangzhicong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加新的测试页及js包
parent
a5fee3d8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
211 additions
and
147 deletions
+211
-147
app/src/main/assets/MRJssdk.es.js
+158
-0
app/src/main/assets/index.html
+53
-147
No files found.
app/src/main/assets/MRJssdk.es.js
0 → 100644
View file @
e2d37674
const
_Jssdk
=
class
{
constructor
({
timeout
,
isNative
})
{
this
.
eventList
=
/* @__PURE__ */
new
Map
();
this
.
callBackName
=
"__maxrockyWebViewJavascriptBridgeCallBack__"
;
this
.
timeout
=
timeout
!=
null
?
timeout
:
1
e3
*
5
;
this
.
isNative
=
isNative
!=
null
?
isNative
:
false
;
window
.
onMaxrockyReady
=
()
=>
{
this
.
isNative
=
true
;
};
window
.
__maxrockyWebViewJavascriptBridgeCallBack__
=
(...
res
)
=>
{
try
{
const
[
_
,
response
]
=
res
;
const
{
data
,
code
,
msg
,
sessionId
}
=
JSON
.
parse
(
response
);
const
promiseFun
=
this
.
eventList
.
get
(
sessionId
);
if
(
!
promiseFun
)
return
;
const
[
resolve
,
reject
,
timer
]
=
promiseFun
;
code
===
0
?
resolve
(
data
)
:
reject
(
msg
);
clearTimeout
(
timer
);
this
.
eventList
.
delete
(
sessionId
);
}
catch
(
error
)
{
console
.
error
(
error
);
}
};
}
getSessionid
()
{
if
(
_Jssdk
.
sessionid
>=
1
e4
)
_Jssdk
.
sessionid
=
0
;
return
_Jssdk
.
sessionid
;
}
jsBridgeCallBack
(...
res
)
{
try
{
const
[
_
,
response
]
=
res
;
const
{
data
,
code
,
msg
,
sessionId
}
=
JSON
.
parse
(
response
);
const
promiseFun
=
this
.
eventList
.
get
(
sessionId
);
if
(
!
promiseFun
)
return
;
const
[
resolve
,
reject
,
timer
]
=
promiseFun
;
code
===
0
?
resolve
(
data
)
:
reject
(
msg
);
clearTimeout
(
timer
);
this
.
eventList
.
delete
(
sessionId
);
}
catch
(
error
)
{
console
.
error
(
error
);
}
}
callHandler
(
methodName
,
params
=
""
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
sessionId
=
this
.
getSessionid
();
const
timer
=
setTimeout
(()
=>
{
reject
(
"timeout"
);
this
.
eventList
.
delete
(
sessionId
);
},
this
.
timeout
);
this
.
eventList
.
set
(
sessionId
,
[
resolve
,
reject
,
timer
]);
window
.
maxrocky
.
execute
(
sessionId
,
methodName
,
params
);
});
}
onSetLocalStroge
(
key
,
value
)
{
if
(
this
.
isNative
)
{
return
this
.
callHandler
(
"storageValue"
,
JSON
.
stringify
({
key
,
value
}));
}
return
new
Promise
((
resolve
)
=>
{
resolve
(
localStorage
.
setItem
(
key
,
value
));
});
}
onGetLocalStroge
(
key
)
{
if
(
this
.
isNative
)
{
return
this
.
callHandler
(
"acquireValue"
,
key
);
}
return
new
Promise
((
resolve
)
=>
{
resolve
(
localStorage
.
getItem
(
key
));
});
}
onRemoveLocalStroge
(
key
)
{
if
(
this
.
isNative
)
{
return
this
.
callHandler
(
"clearValue"
,
key
);
}
return
new
Promise
((
resolve
)
=>
{
resolve
(
localStorage
.
removeItem
(
key
));
});
}
onClearLocalStroge
()
{
if
(
this
.
isNative
)
{
return
new
Promise
((
_
,
reject
)
=>
{
reject
(
"TODO"
);
});
}
return
new
Promise
((
resolve
)
=>
{
resolve
(
localStorage
.
clear
());
});
}
onQRCodeClick
()
{
if
(
this
.
isNative
)
{
return
this
.
callHandler
(
"qrcode"
);
}
return
new
Promise
((
_
,
reject
)
=>
{
reject
(
""
);
});
}
pickerPhoto
()
{
if
(
this
.
isNative
)
{
return
this
.
callHandler
(
"selectPhoto"
);
}
return
new
Promise
((
_
,
reject
)
=>
{
reject
();
});
}
takePhotos
()
{
if
(
this
.
isNative
)
{
return
this
.
callHandler
(
"openCamera"
);
}
return
new
Promise
((
_
,
reject
)
=>
{
reject
();
});
}
startRecordAudio
()
{
if
(
this
.
isNative
)
{
return
this
.
callHandler
(
"recordAudio"
);
}
return
new
Promise
((
_
,
reject
)
=>
{
reject
();
});
}
getClientId
()
{
if
(
this
.
isNative
)
{
return
new
Promise
((
_
,
reject
)
=>
{
reject
(
"TODO"
);
});
}
return
new
Promise
((
_
,
reject
)
=>
{
reject
();
});
}
getDeviceInfo
()
{
if
(
this
.
isNative
)
{
return
new
Promise
((
_
,
reject
)
=>
{
reject
(
"TODO"
);
});
}
return
new
Promise
((
_
,
reject
)
=>
{
reject
();
});
}
getNetworkType
()
{
if
(
this
.
isNative
)
{
return
new
Promise
((
_
,
reject
)
=>
{
reject
(
"TODO"
);
});
}
return
new
Promise
((
resolve
)
=>
{
resolve
(
navigator
.
onLine
?
"wifi"
:
"unknown"
);
});
}
};
let
Jssdk
=
_Jssdk
;
Jssdk
.
sessionid
=
0
;
var
jssdk
=
new
Jssdk
({});
// export { jssdk as default };
//# sourceMappingURL=MRJsskd.es.js.map
app/src/main/assets/index.html
View file @
e2d37674
...
...
@@ -3,168 +3,74 @@
<head>
<meta
charset=
"utf-8"
>
<title>
Maxrocky
</title>
<script
src=
"./MRJssdk.es.js"
></script>
<script>
function
onMaxrockyReady
()
{
alert
(
'onReady'
);
}
function
cropPhoto
(
uri
){
window
.
cropPhotoSuccess
=
function
(
uri
,
base64
)
{
document
.
getElementById
(
'img'
).
src
=
base64
;
window
.
cropPhotoSuccess
=
null
}
window
.
cropPhotoFailed
=
function
()
{
alert
(
'crop photo failed'
);
window
.
cropPhotoFailed
=
null
}
window
.
cropPhotoComplete
=
function
()
{
alert
(
'crop photo complete'
);
window
.
cropPhotoComplete
=
null
}
maxrocky
.
cropPhoto
(
uri
);
}
function
selectFile
(){
window
.
selectFileSuccess
=
function
(
uri
)
{
document
.
getElementById
(
'text'
).
innerText
=
uri
;
window
.
selectFileSuccess
=
null
}
window
.
selectFileFailed
=
function
()
{
alert
(
'select file failed'
);
window
.
selectFileFailed
=
null
}
window
.
selectFileComplete
=
function
()
{
alert
(
'select file complete'
);
window
.
selectFileComplete
=
null
}
maxrocky
.
selectFile
(
'txt'
);
}
function
selectPhoto
(){
window
.
selectPhotoSuccess
=
function
(
uri
,
base64
)
{
cropPhoto
(
uri
)
window
.
selectPhotoSuccess
=
null
}
window
.
selectPhotoFailed
=
function
()
{
alert
(
'select photo failed'
);
window
.
selectPhotoFailed
=
null
}
window
.
selectPhotoComplete
=
function
()
{
alert
(
'select photo complete'
);
window
.
selectPhotoComplete
=
null
}
maxrocky
.
selectPhoto
();
document
.
onreadystatechange
=
function
()
{
maxrocky
.
link
();
}
function
recordAudio
(){
window
.
recordAudioSuccess
=
function
(
uri
,
base64
)
{
document
.
getElementById
(
'audio'
).
src
=
base64
;
window
.
recordAudioSuccess
=
null
async
function
pickerPhoto
()
{
try
{
const
res
=
await
jssdk
.
pickerPhoto
();
document
.
getElementById
(
'img'
).
src
=
res
.
base64
;
}
catch
(
error
)
{
console
.
error
(
error
);
}
window
.
recordAudioFailed
=
function
()
{
alert
(
'record audio failed'
);
window
.
recordAudioFailed
=
null
}
window
.
recordAudioComplete
=
function
()
{
alert
(
'record audio complete'
);
window
.
recordAudioComplete
=
null
}
maxrocky
.
recordAudio
(
30
);
}
function
captureVideo
(){
window
.
captureVideoSuccess
=
function
(
uri
,
base64
)
{
document
.
getElementById
(
'video'
).
src
=
base64
;
window
.
captureVideoSuccess
=
null
}
window
.
captureVideoFailed
=
function
()
{
alert
(
'capture video failed'
);
window
.
captureVideoFailed
=
null
}
window
.
captureVideoComplete
=
function
()
{
alert
(
'capture video complete'
);
window
.
captureVideoComplete
=
null
async
function
takePhotos
()
{
try
{
const
res
=
await
jssdk
.
takePhotos
();
document
.
getElementById
(
'img'
).
src
=
res
.
base64
;
}
catch
(
error
)
{
console
.
error
(
error
);
}
maxrocky
.
captureVideo
();
}
function
openCamera
(){
window
.
openCameraSuccess
=
function
(
uri
,
base64
)
{
document
.
getElementById
(
'img'
).
src
=
base64
;
window
.
openCameraSuccess
=
null
async
function
startRecordAudio
()
{
try
{
const
res
=
await
jssdk
.
startRecordAudio
(
30
);
alert
(
res
);
document
.
getElementById
(
'audio'
).
src
=
res
.
base64
;
}
catch
(
error
)
{
console
.
error
(
error
);
}
window
.
openCameraFailed
=
function
()
{
alert
(
'open camera failed'
);
window
.
openCameraFailed
=
null
}
window
.
openCameraComplete
=
function
()
{
alert
(
'open camera complete'
);
window
.
openCameraComplete
=
null
}
maxrocky
.
openCamera
();
}
function
qrcode
(){
window
.
qrcodeSuccess
=
function
(
content
)
{
document
.
getElementById
(
'text'
).
innerText
=
content
;
window
.
qrcodeSuccess
=
null
}
window
.
qrcodeFailed
=
function
()
{
alert
(
'qrcode failed'
);
window
.
qrcodeFailed
=
null
async
function
onQRCodeClick
()
{
try
{
const
res
=
await
jssdk
.
onQRCodeClick
();
document
.
getElementById
(
'text'
).
innerText
=
res
.
value
;
}
catch
(
error
)
{
console
.
error
(
error
);
}
window
.
qrcodeComplete
=
function
()
{
alert
(
'qrcode complete'
);
window
.
qrcodeComplete
=
null
}
maxrocky
.
qrcode
();
}
function
storageValue
(){
window
.
storageValueSuccess
=
function
(
key
,
value
)
{
async
function
onSetLocalStorage
()
{
try
{
const
res
=
await
jssdk
.
onSetLocalStorage
(
'maxrocky'
,
'测试'
);
document
.
getElementById
(
'text'
).
innerText
=
'保存成功'
;
window
.
storageValueSuccess
=
null
}
window
.
storageValueFailed
=
function
()
{
alert
(
'storage value failed'
);
window
.
storageValueFailed
=
null
}
catch
(
error
)
{
console
.
error
(
error
);
}
window
.
storageValueComplete
=
function
()
{
alert
(
'storage value complete'
);
window
.
storageValueComplete
=
null
}
maxrocky
.
storageValue
(
'maxrocky'
,
'测试'
);
}
function
acquireValue
(){
window
.
acquireValueSuccess
=
function
(
key
,
value
)
{
document
.
getElementById
(
'text'
).
innerText
=
`本地记录内容:
${
value
}
`
;
window
.
acquireValueSuccess
=
null
}
window
.
acquireValueFailed
=
function
()
{
alert
(
'acquire value failed'
);
window
.
acquireValueFailed
=
null
async
function
onGetLocalStorage
()
{
try
{
const
res
=
await
jssdk
.
onGetLocalStorage
(
'maxrocky'
);
document
.
getElementById
(
'text'
).
innerText
=
`本地记录内容:
${
res
.
value
}
`
;
}
catch
(
error
)
{
console
.
error
(
error
);
}
window
.
acquireValueComplete
=
function
()
{
alert
(
'acquire value complete'
);
window
.
acquireValueComplete
=
null
}
maxrocky
.
acquireValue
(
'maxrocky'
);
}
function
clearValue
(){
window
.
clearValueSuccess
=
function
(
key
,
value
)
{
document
.
getElementById
(
'text'
).
innerText
=
`已清理本地记录`
;
window
.
clearValueSuccess
=
null
}
window
.
clearValueFailed
=
function
()
{
alert
(
'clear value failed'
);
window
.
clearValueFailed
=
null
}
window
.
clearValueComplete
=
function
()
{
alert
(
'clear value complete'
);
window
.
clearValueComplete
=
null
async
function
onRemoveLocalStorage
()
{
try
{
const
res
=
await
jssdk
.
onRemoveLocalStorage
(
'maxrocky'
);
document
.
getElementById
(
'text'
).
innerText
=
'已清理本地记录'
;
}
catch
(
error
)
{
console
.
error
(
error
);
}
maxrocky
.
clearValue
(
'maxrocky'
);
}
</script>
</head>
...
...
@@ -178,13 +84,12 @@
<span
id=
"text"
></span>
</div>
<!-- <button type="button" id="selectFile" onclick="selectFile()">选择文件</button> -->
<button
type=
"button"
id=
"selectPhoto"
onclick=
"selectPhoto()"
>
选择并裁剪图片
</button>
<button
type=
"button"
id=
"openCamera"
onclick=
"openCamera()"
>
拍摄照片
</button>
<button
type=
"button"
id=
"recordAudio"
onclick=
"recordAudio()"
>
录制音频
</button>
<button
type=
"button"
id=
"captureVideo"
onclick=
"captureVideo()"
>
录像
</button>
<button
type=
"button"
id=
"qrcode"
onclick=
"qrcode()"
>
识别二维码
</button>
<button
type=
"button"
id=
"storage"
onclick=
"storageValue()"
>
保存"测试字符串"到本地
</button>
<button
type=
"button"
id=
"acquire"
onclick=
"acquireValue()"
>
获取本地记录字符串
</button>
<button
type=
"button"
id=
"clear"
onclick=
"clearValue()"
>
清除本地记录字符串
</button>
<button
type=
"button"
id=
"selectPhoto"
onclick=
"pickerPhoto()"
>
选择图片
</button>
<button
type=
"button"
id=
"openCamera"
onclick=
"takePhotos()"
>
拍摄照片
</button>
<button
type=
"button"
id=
"recordAudio"
onclick=
"startRecordAudio()"
>
录制音频
</button>
<button
type=
"button"
id=
"qrcode"
onclick=
"onQRCodeClick()"
>
识别二维码
</button>
<button
type=
"button"
id=
"storage"
onclick=
"onSetLocalStroge()"
>
保存"测试"到本地
</button>
<button
type=
"button"
id=
"acquire"
onclick=
"onGetLocalStroge()"
>
获取本地记录字符串
</button>
<button
type=
"button"
id=
"clear"
onclick=
"onRemoveLocalStroge()"
>
清除本地记录字符串
</button>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment