将IE拍照代码迁移到tsx
This commit is contained in:
@ -28,10 +28,11 @@
|
||||
pos += 4 * 320;
|
||||
//post>= 4 * 320(x轴像素) * 240(y轴像素) 表示读取图像数据完毕
|
||||
if (pos >= 4 * 320 * 240) {
|
||||
var url ='http://127.0.0.1:8081/outer/v1.0/stock/logicStock/rgbArray2Base64';
|
||||
$.post(url, {type: 'pixel', rgb: image.join('|')}, function(result){
|
||||
$('#base64image').attr('src', 'data:image/jpg;base64,' + result.data);
|
||||
});
|
||||
window.parent.postMessage({"image":image.join('|')}, '*');
|
||||
// var url ='http://127.0.0.1:8081/outer/v1.0/stock/logicStock/rgbArray2Base64';
|
||||
// $.post(url, {type: 'pixel', rgb: image.join('|')}, function(result){
|
||||
// $('#base64image').attr('src', 'data:image/jpg;base64,' + result.data);
|
||||
// });
|
||||
image = new Array();
|
||||
pos = 0;
|
||||
}
|
||||
@ -56,6 +57,13 @@
|
||||
$('#snapBtn').on('click', function() {
|
||||
webcam.capture();
|
||||
});
|
||||
|
||||
function receiveMessageFromParent ( event ) {
|
||||
console.log(event.data);
|
||||
$('#base64image').attr('src', 'data:image/jpg;base64,' + event.data.data);
|
||||
};
|
||||
|
||||
window.addEventListener('message', receiveMessageFromParent, false);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
@ -1,28 +1,36 @@
|
||||
import React from "react";
|
||||
import FrameLoader from "./FrameLoader";
|
||||
export default class FrameFaceLogin extends React.Component {
|
||||
constructor(props) {
|
||||
constructor(props:any) {
|
||||
super(props);
|
||||
console.log(props, "props数据");
|
||||
this.state = {
|
||||
transferData: {
|
||||
optimizationOrderFn: false,
|
||||
allocationFn: false,
|
||||
releaseFn: false,
|
||||
revocationFn: false,
|
||||
image: ''
|
||||
},
|
||||
};
|
||||
}
|
||||
componentDidMount() {
|
||||
// 接收Iframe 传递的数据
|
||||
// 接收Iframe传递的数据
|
||||
window.addEventListener("message", (e) => {
|
||||
const { allocationFn, releaseFn } = e.data || {}; //传递的数据
|
||||
if (allocationFn || releaseFn) {
|
||||
const { image} = e.data || {}; //传递的数据
|
||||
if (image) {
|
||||
this.setState({
|
||||
transferData: e.data,
|
||||
transferData: {
|
||||
image:e.data
|
||||
},
|
||||
});
|
||||
|
||||
console.log(this.state.transferData, "传数据");
|
||||
const url = 'http://127.0.0.1:8081/outer/v1.0/stock/logicStock/rgbArray2Base64';
|
||||
window.fetch(url,{
|
||||
method:'post',
|
||||
body : JSON.stringify({//post请求参数
|
||||
type: 'pixel',
|
||||
rgb: image
|
||||
})
|
||||
}).then(res => res.json()).then(res => {
|
||||
const childFrameObj = document.getElementById('faceLoginFrame');
|
||||
childFrameObj.contentWindow.postMessage(res, '*');
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import Iframe from "react-iframe";
|
||||
export default class FrameLoader extends React.Component {
|
||||
constructor(props) {
|
||||
constructor(props:any) {
|
||||
super(props);
|
||||
this.state = {
|
||||
iFrameHeight: this.props.height ? this.props.height : 0, // 设置iframe的高度
|
||||
@ -14,6 +14,7 @@ export default class FrameLoader extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<Iframe
|
||||
id="faceLoginFrame"
|
||||
onLoad={() => {
|
||||
const obj = ReactDOM.findDOMNode(this);
|
||||
this.setState({
|
||||
|
Reference in New Issue
Block a user