- var QRC = (function (_super) {
- __extends(QRC, _super);
- function QRC() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- function utf16to8(str) {//函数目的编码转化函数使中文可以显示
- var out, i, len, c;
- out = "";
- len = str.length;
- for (i = 0; i < len; i++) {
- c = str.charCodeAt(i);
- if ((c >= 0x0001) && (c <= 0x007F)) {
- out += str.charAt(i);
- } else if (c > 0x07FF) {
- out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
- out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
- out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
- } else {
- out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
- out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
- }
- }
- return out;
- }
- QRC.prototype.text = "";//定义一个插件属性,全局变量随插件生成而生成随插件灭亡而灭亡
- QRC.prototype.createContent = function () {//在单元格对象上创建一个div
- var container = $("<div id='" + this.ID + "'></div>");
- return container;
- };
- QRC.prototype.setValueToElement = function (element, value) {
- this.text = value;//把单元格在设计器里填写的值赋给this.text//text是我在插件对象里定义的属性
- var cellTypeMetaData = this.CellElement.CellType;
- if (this.text !== "") {
- var id = '#' + this.ID;
- $(id).empty();
- var widthv = cellTypeMetaData.Widthv;//获取设置的高宽
- var heightv = cellTypeMetaData.Heightv;
- defaultValue = this.text.toString();//转成字符串
- jQuery(id).qrcode({ width: widthv, height: heightv, text: utf16to8(defaultValue) });//二维码绑定在元素上。也就是生成二维码
- }
- };
- QRC.prototype.disable = function () {
- _super.prototype.disable.call(this);
- };
- QRC.prototype.enable = function () {
- _super.prototype.enable.call(this);
- };
- return QRC;
- }(Forguncy.CellTypeBase));
- // Key format is "Namespace.ClassName, AssemblyName"
- Forguncy.Plugin.CellTypeHelper.registerCellType("QRC.QRC, QRC", QRC);
复制代码
这个我二维码插件的js代码,没有写onLoad,把逻辑都写到了 QRC.prototype.setValueToElement{}里了 |