QRCode_wev8.js 1.01 KB
define(['mUtil', "Component"],function(mUtil, Component) {
	var QRCode = function(options) {

		Component.super(this, options);

		this.type = "QRCode";
		this.tpl = this.type + "_html";
		this.css = this.type + "_css";

		var vm = this.viewModel = {
			content : "",
			width : 256,
			logo : "",
			logoWidth : 40,
			logoHeight : 40
		};

		this.mounted = function(){
			if (!vm.content) return;

			var $comp = this.$el.children(".wev-comp-" + this.type);

			require(["qrcode"], function () {
				$comp.html("").qrcode({
					render: "canvas",    //设置渲染方式,有table和canvas,使用canvas方式渲染性能相对来说比较好
					text: vm.content,
					width: vm.width,               //二维码的宽度
					height: vm.width,              //二维码的高度
					src: vm.logo,             //二维码中间的图片
					imgWidth: vm.logoWidth,       //二维码图片的宽度
					imgHeight: vm.logoHeight        //二维码图片的高度
				});
			});
	    };
    };

    return Component.init(QRCode);
});