UNPKG

tav-ui

Version:
83 lines (78 loc) 2.56 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var qrcode = require('qrcode'); var download = require('../../../utils/file/download2.js'); require('./qrcodePlus2.js'); var types = require('./types2.js'); var pluginVue_exportHelper = require('../../../../_virtual/plugin-vue_export-helper.js'); var toCanvas = require('./toCanvas2.js'); const _sfc_main = vue.defineComponent({ name: "TaQrCode", props: types.qrcodeProps, emits: { done: (data) => !!data, error: (error) => !!error }, setup(props, { emit }) { const wrapRef = vue.ref(null); async function createQrcode() { try { const { tag, value, options = {}, width, logo } = props; const renderValue = String(value); const wrapEl = vue.unref(wrapRef); if (!wrapEl) return; if (tag === "canvas") { const url = await toCanvas.toCanvas({ canvas: wrapEl, width, logo, content: renderValue, options: options || {} }); emit("done", { url, ctx: wrapEl.getContext("2d") }); return; } if (tag === "img") { const url = await qrcode.toDataURL(renderValue, { errorCorrectionLevel: "H", width, ...options }); vue.unref(wrapRef).src = url; emit("done", { url }); } } catch (error) { emit("error", error); } } function download$1(fileName) { let url = ""; const wrapEl = vue.unref(wrapRef); if (wrapEl instanceof HTMLCanvasElement) { url = wrapEl.toDataURL(); } else if (wrapEl instanceof HTMLImageElement) { url = wrapEl.src; } if (!url) return; download.downloadByUrl({ url, fileName }); } vue.onMounted(createQrcode); vue.watch(props, () => { createQrcode(); }, { deep: true }); return { wrapRef, download: download$1 }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return vue.openBlock(), vue.createElementBlock("div", null, [ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.tag), { ref: "wrapRef" }, null, 512)) ]); } var Qrcode = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/tav-ui/tav-ui/packages/components/qr-code/src/qr-code.vue"]]); exports["default"] = Qrcode; //# sourceMappingURL=qr-code2.js.map