vue-amazing-ui
Version:
An Amazing Vue3 UI Components Library, Using TypeScript.
90 lines (89 loc) • 2.94 kB
JavaScript
import { defineComponent as m, 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__ */ m({
__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), a = c(""), y = u(() => ({
width: `${e.size}px`,
height: `${e.size}px`,
backgroundColor: `${e.bgColor}`,
borderColor: `${e.borderColor}`
})), g = u(() => ({
width: `${e.iconSize}px`,
height: `${e.iconSize}px`,
backgroundColor: `${e.bgColor}`
})), l = 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, l.value],
async () => {
e.value && (e.type === "svg" ? (a.value = await n.toString(e.value, l.value), d.value.innerHTML = a.value) : e.type === "canvas" ? (a.value = await n.toCanvas(e.value, l.value), i.value?.appendChild(a.value)) : a.value = await n.toDataURL(e.value, l.value));
},
{
immediate: !0,
deep: !0,
flush: "post"
}
), f({
getQRCodeImage: () => e.value && n.toDataURL(e.value, l.value)
}), (o, k) => (t(), r("div", {
class: q(["qrcode-wrap", { "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: a.value,
class: "qrcode-image",
alt: "QR Code"
}, null, 8, h)) : s("", !0),
o.icon ? (t(), r("img", {
key: 3,
src: o.icon,
style: v(g.value),
class: "qrcode-icon",
alt: "QR Code Icon"
}, null, 12, b)) : s("", !0)
], 6));
}
});
export {
z as default
};