# Qrcode QR 코드

자체 개발 순수 JS QR 코드 인코딩(@lh-ui/share/core/qrcode, ISO/IEC 18004 전체 링크: UTF-8 바이트 모드 → Reed-Solomon 오류 정정 → 마스크 패널티 최적 선택 → 포맷 / 버전 정보 BCH), 행렬은 SVG <path>로 렌더링하며, viewBox에 quiet zone을 포함합니다; 루트 클래스는 lh-qrcode, 스타일은 share styles/qrcode에서 옵니다.

QR 코드 (오류 정정 레벨 / 크기 / 색상 / 빈 상태 폴백)
<template>
  <div class="demo-col" style="gap: 18px; max-width: 480px">
    <div class="demo-row" style="gap: 12px; flex-wrap: wrap; align-items: center">
      <LhInput v-model="text" placeholder="인코딩할 텍스트" style="width: 220px" />
      <LhButton size="small" @click="cycleLevel">오류 정정 레벨: {{ level }}</LhButton>
    </div>
    <div class="demo-row" style="gap: 24px; flex-wrap: wrap; align-items: flex-start">
      <div class="demo-col" style="align-items: center; gap: 8px">
        <LhQrcode :value="text" :level="level" label="기본 QR 코드" />
        <span class="demo-note">기본 (M 레벨 / size=120)</span>
      </div>
      <div class="demo-col" style="align-items: center; gap: 8px">
        <LhQrcode :value="text" :level="level" :size="160" :margin="2" color="#A63D40" />
        <span class="demo-note">size=160 margin=2 진홍 모듈</span>
      </div>
      <div class="demo-col" style="align-items: center; gap: 8px">
        <LhQrcode :value="text" :level="level" :version="5" bg-color="#F6F1EA" />
        <span class="demo-note">version=5 고정 + 배경 rect</span>
      </div>
    </div>
    <div class="demo-row" style="gap: 24px; flex-wrap: wrap; align-items: flex-start">
      <div class="demo-col" style="align-items: center; gap: 8px">
        <LhQrcode value="" />
        <span class="demo-note">value 빈 상태</span>
      </div>
      <div class="demo-col" style="align-items: center; gap: 8px">
        <LhQrcode :value="tooLong" />
        <span class="demo-note">용량 초과 텍스트 빈 상태로 폴백 (console.warn)</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data: () => ({
    text: 'lh-ui 패밀리 · 수묵과 단청',
    level: 'M',
    tooLong: 'lh-ui'.repeat(600),
  }),
  methods: {
    cycleLevel() {
      const order = ['L', 'M', 'Q', 'H']
      this.level = order[(order.indexOf(this.level) + 1) % order.length]
    },
  },
}
</script>

# 오류 정정 레벨과 버전

level은 L / M / Q / H 4단계입니다(기본 M), 레벨이 높을수록 중복이 커지고 수용할 수 있는 바이트 수는 줄어듭니다; version은 1-40입니다(기본 0 = 수용 가능한 최소 버전 자동 선택). version을 고정하면 해당 버전 용량을 초과하는 텍스트에서 오류를 던지는데, 컴포넌트 층에서 try/catch 보호로 빈 상태로 폴백하고 console.warn을 남깁니다:

<LhQrcode value="https://lhgb.top" level="H" :version="10" />

# 크기와 quiet zone

size는 svg 렌더링 너비/높이를 제어합니다(루트 CSS 변수 --lh-qrcode-size에 기록, 기본 120); margin은 quiet zone 모듈 수입니다(기본 4, spec 최솟값), viewBox에 포함되어 계산됩니다:

<LhQrcode value="수묵과 단청" :size="160" :margin="2" />

# 색상

color는 모듈 색상, bgColor는 배경색입니다(viewBox를 가득 채우는 <rect>로 렌더링); color 미전달 시 --lh-text-primary 토큰 폴백, bgColor 미전달 시 투명합니다(루트 컨테이너 배경이 비쳐 보임):

<LhQrcode value="진홍" color="#A63D40" bg-color="#F6F1EA" />

# Props

프로퍼티 설명 타입 기본값
value 인코딩할 텍스트 (UTF-8, 한자 지원) string ''
level 오류 정정 레벨 'L' \| 'M' \| 'Q' \| 'H' 'M'
version 버전 1-40 (0 = 수용 가능한 최소 버전 자동 선택) number 0
margin quiet zone 모듈 수 number 4
color 전경색 (모듈 색상, 미전달 시 lh-qrcode 토큰 사용) string —
bgColor 배경색 (미전달 시 lh-qrcode 토큰 사용) string —
size 크기 px (렌더링 캔버스 크기) number 120
label 접근성 접근 가능한 이름 (미전달 시 기본 'QR 코드' 텍스트 사용) string —

# 접근성

루트 요소 role="img" + aria-label(label이 기본 'QR 코드'를 덮어쓸 수 있음). 빈 value이거나 용량 초과로 폴백할 때 svg를 출력하지 않고, 루트 노드는 lh-qrcode--empty 수정자를 유지합니다.

최근 업데이트: 2026. 12. 4. 오전 12:49:57

Copyright © 2024-2026 FengMo WenXue