ukelli-ui
Version:
Base on React's UI lib. Make frontend's dev simpler and faster.
67 lines (66 loc) • 2.31 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import React, { PureComponent } from 'react';
var queryQRCodeData = function (getData, origin) {
console.log('请先通过 QRCode.setAPI() 设置获取数据接口');
};
var QRCode = /** @class */ (function (_super) {
__extends(QRCode, _super);
function QRCode(props) {
var _this = _super.call(this, props) || this;
_this.getCacha = function () {
var origin = _this.props.origin;
var cacha = localStorage.getItem(origin);
if (!cacha) {
_this.queryData();
}
else {
_this.setState({
qrbase64: cacha
});
}
};
_this.state = {
qrbase64: ''
};
return _this;
}
/**
* 接口说明
* 引用时需要定义对于的接口,详情请参考对于的调用方法
*/
QRCode.prototype.queryData = function () {
var _this = this;
var origin = this.props.origin;
queryQRCodeData(function (base64Res) {
_this.setState({
qrbase64: base64Res
});
localStorage.setItem(origin, base64Res);
}, origin);
};
QRCode.prototype.componentDidMount = function () {
this.getCacha();
};
QRCode.prototype.render = function () {
var qrbase64 = this.state.qrbase64;
if (!qrbase64)
return React.createElement("div", null);
return (React.createElement("div", { className: "qrcode" },
React.createElement("img", { src: qrbase64, alt: "" })));
};
QRCode.setAPI = function (api) { queryQRCodeData = api; };
return QRCode;
}(PureComponent));
export { QRCode };