Skip to content

群二维码 (xh-group-qrcode)

群二维码组件用于为群聊生成带有群头像和群名称的二维码,支持单个头像和多个头像组合。

基本用法

单个群头像

html
<xh-group-qrcode
  value="https://github.com/xiangheng08"
  groupName="技术交流群"
  groupAvatar="/images/avatars/2.jpg"
  tips="扫一扫二维码,加入群聊。"
  errorcorrectionlevel="H"
  shape="round"
  logo="/images/vite.svg"
/>

多个群头像

html
<xh-group-qrcode
  value="https://github.com/xiangheng08"
  groupName="技术交流群"
  groupAvatars='["/images/avatars/1.jpg", "/images/avatars/2.jpg", "/images/avatars/3.jpg", "/images/avatars/4.jpg", "/images/avatars/5.jpg", "/images/avatars/6.jpg", "/images/avatars/7.jpg", "/images/avatars/8.jpg", "/images/avatars/9.jpg"]'
  tips="扫一扫二维码,加入群聊。"
  errorcorrectionlevel="H"
  shape="round"
  logo="/images/vite.svg"
/>

属性 (Attributes)

除了基础二维码的所有属性外,还支持以下特有属性:

属性名类型默认值描述
widthnumber400群二维码宽度
paddingTopnumber0.146上内边距 (相对于宽度)
paddingBottomnumber0.125下内边距 (相对于宽度)
groupAvatarstringundefined群头像图片 URL
groupAvatarsstring[]undefined群头像数组 (会被 groupAvatar 覆盖)
groupAvatarSizenumber0.16群头像大小 (相对于宽度)
defaultGroupAvatarstringundefined默认群头像 (仅对 groupAvatars 生效)
groupAvatarBackgroundstring'#dddddd'群头像背景色 (仅对 groupAvatars 生效)
groupAvatarFitstring'cover'群头像适应方式 (仅对 groupAvatars 生效)
groupAvatarRadiusnumber0.072群头像圆角 (相对于头像大小)
groupAvatarGapnumber0.035群头像间隔 (相对于头像大小)
groupAvatarPaddingnumber0.04群头像内边距 (相对于头像大小)
groupNamestring''群名称
groupNameFontstring'{0.048}px ...'群名称字体
groupNameColorstring'#000000'群名称颜色
groupNameWidthnumber0.63群名称宽度 (相对于宽度)
tipsstring''提示语
tipsWidthnumber0.8提示语宽度 (相对于宽度)
tipsColorstring'#b4b4b4'提示语颜色
tipsFontstring'{0.03}px ...'提示语字体
qrcodeScalenumber0.725二维码所占比例 (相对于宽度)

示例

基本群二维码

html
<xh-group-qrcode
  value="https://github.com/xiangheng08"
  groupName="技术交流群"
  groupAvatar="/images/vite.svg"
  tips="扫一扫上面的二维码图案,加入群聊。"
/>

多头像群二维码

html
<xh-group-qrcode
  value="https://github.com/xiangheng08"
  groupName="技术交流群"
  .groupAvatars='["/images/avatars/1.jpg","/images/avatars/2.jpg","/images/avatars/3.jpg","/images/avatars/4.jpg"]'
  defaultGroupAvatar="/images/vite.svg"
  tips="扫一扫上面的二维码图案,加入群聊。"
/>

自定义样式

html
<xh-group-qrcode
  value="https://github.com/xiangheng08"
  groupName="技术交流群"
  groupAvatar="/images/vite.svg"
  tips="欢迎加入我们的技术交流群"
  width="375"
  groupNameColor="#333333"
  tipsColor="#999999"
  groupAvatarRadius="0.2"
  color="#1296db"
  errorcorrectionlevel="H"
/>

群头像组合规则

请查看 groupAvatars

注意事项

  1. 所有与宽度相关的属性都是相对值,实际像素值会根据 width 属性计算得出
  2. 字体属性中的 {数字} 会被替换为实际计算出的像素值
  3. 如果同时设置了 groupAvatargroupAvatarsgroupAvatar 优先级更高
  4. 在 React 中使用 groupAvatars 属性时,需要使用 .groupAvatars 语法传递数组