tfp
Version:
A Web UI framework for TaskBuilder
89 lines (77 loc) • 2.1 kB
JavaScript
import { VisibleComponent } from "../controller.js";
/**
* 二维码组件
* @param {[type]} dataModel [description]
*/
export default class QrCode extends VisibleComponent {
constructor(__tfp, dataModel, parent) {
super(__tfp, "QrCode", dataModel, parent);
this.qrCode = null;
}
get text () { return this.dataModel.text }
set text (value) {
this.dataModel.text = value;
//
}
get width () { return this.dataModel.width }
set width (value) {
this.dataModel.width = value;
if (this._jqObj) {
this._jqObj.css("width", value + "px");
}
}
get height () { return this.dataModel.height }
set height (value) {
this.dataModel.height = value;
if (this._jqObj) {
this._jqObj.css("height", value + "px");
}
}
get colorDark () { return this.dataModel.colorDark }
set colorDark (value) {
this.dataModel.colorDark = value;
}
get colorLight () { return this.dataModel.colorLight }
set colorLight (value) {
this.dataModel.colorLight = value;
}
/**
* 初始化运行时
* @return {[type]} [description]
*/
initRuntime () {
let txt = this.dataModel.text;
if (!txt) txt = "http://www.taskbuilder.org";
this.qrCode = new QRCode(this.el, {
text: txt,
width: this.dataModel.width,
height: this.dataModel.height,
colorDark: this.dataModel.colorDark,
colorLight: this.dataModel.colorLight,
correctLevel: QRCode.CorrectLevel.H
});
var that = this;
this._jqObj.click(function () {
if (that.dataModel.onClick) {
eval(that.dataModel.onClick);
}
});
this._jqObj.mouseover(function () {
if (that.dataModel.onMouseOver) {
eval(that.dataModel.onMouseOver);
}
});
this._jqObj.mouseout(function () {
if (that.dataModel.onMouseOut) {
eval(that.dataModel.onMouseOut);
}
});
}
clear () {
this.qrCode.clear();
}
makeCode (e) {
console.log(e);
this.qrCode.makeCode(e);
}
}