vue-amazing-ui
Version:
An Amazing Vue3 UI Components Library, Using TypeScript.
91 lines (90 loc) • 2.97 kB
JavaScript
import { defineComponent as g, ref as c, computed as u, watch as C, createElementBlock as r, openBlock as t, normalizeStyle as v, normalizeClass as q, createCommentVNode as s } from "vue";
import n from "qrcode";
const h = ["src"], b = ["src"], z = /* @__PURE__ */ g({
__name: "QRCode",
props: {
value: { default: void 0 },
type: { default: "svg" },
icon: { default: void 0 },
size: { default: 160 },
iconSize: { default: 40 },
color: { default: "#000" },
bgColor: { default: "#FFF" },
bordered: { type: Boolean, default: !0 },
borderColor: { default: "rgba(5, 5, 5, 0.06)" },
scale: { default: 8 },
errorLevel: { default: "H" }
},
setup(p, { expose: f }) {
const e = p, d = c(null), i = c(null), l = c(""), y = u(() => ({
width: `${e.size}px`,
height: `${e.size}px`,
backgroundColor: `${e.bgColor}`,
borderColor: `${e.borderColor}`
})), m = u(() => ({
width: `${e.iconSize}px`,
height: `${e.iconSize}px`,
backgroundColor: `${e.bgColor}`
})), a = u(() => ({
quality: 1,
// number 默认 0.92, 0 <= quality <= 1 仅在 type 为 'image/jpeg' 或 'image/webp' 时有效
margin: 0,
// number 默认 4, 边距大小,单位 px
scale: e.scale,
// number,默认 4, 缩放因子,A value of 1 means 1px per modules (black dots).
color: {
dark: e.color,
// 像素点颜色
light: "#00000000"
// 背景色
},
errorCorrectionLevel: e.errorLevel
}));
return C(
() => [e.value, e.type, a.value],
async () => {
var o;
e.value && (e.type === "svg" ? (l.value = await n.toString(e.value, a.value), d.value.innerHTML = l.value) : e.type === "canvas" ? (l.value = await n.toCanvas(e.value, a.value), (o = i.value) == null || o.appendChild(l.value)) : l.value = await n.toDataURL(e.value, a.value));
},
{
immediate: !0,
deep: !0,
flush: "post"
}
), f({
getQRCodeImage: () => e.value && n.toDataURL(e.value, a.value)
}), (o, k) => (t(), r("div", {
class: q(["m-qrcode", { "qrcode-bordered": o.bordered }]),
style: v(y.value)
}, [
o.type === "svg" ? (t(), r("span", {
key: 0,
ref_key: "qrcodeSVGRef",
ref: d,
class: "qrcode-svg"
}, null, 512)) : s("", !0),
o.type === "canvas" ? (t(), r("span", {
key: 1,
ref_key: "qrcodeCanvasRef",
ref: i,
class: "qrcode-canvas"
}, null, 512)) : s("", !0),
o.type === "image" ? (t(), r("img", {
key: 2,
src: l.value,
class: "qrcode-image",
alt: "QR Code"
}, null, 8, h)) : s("", !0),
o.icon ? (t(), r("img", {
key: 3,
src: o.icon,
style: v(m.value),
class: "qrcode-icon",
alt: "QR Code Icon"
}, null, 12, b)) : s("", !0)
], 6));
}
});
export {
z as default
};