更新记录
0.0.5(2025-08-20)
- fix: 修复多个组件的情况只最后一次生效
0.0.4(2025-05-24)
- feat: 兼容uniapp x 鸿蒙next
0.0.3(2025-01-17)
- feat: 兼容hbx4.45
平台兼容性
uni-app x(4.72)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| √ | √ | 5.0 | √ | √ | √ |
lime-barcodegen 条形码生成组件
一个功能强大的条形码生成组件,用于在应用中生成各种格式的条形码。支持多种条形码类型、自定义样式、文本位置等多种配置,可用于商品标识、库存管理、票据打印等多种场景。组件提供了丰富的自定义选项,可以满足各种复杂的条形码生成需求。
插件依赖:配合 lime-barcode uvue 组件使用
文档链接
📚 组件详细文档请访问以下站点:
安装方法
- 在uni-app插件市场中搜索并导入
lime-barcodegen - 导入后需要自定义基座才能运行
- 在页面中使用相关API生成条形码
代码演示
基础用法
最简单的条形码生成用法,只需要设置文本和基本配置即可。
<view ref="barcodeRef"></view>
import { renderer, type LBarcodeGenOptions } from '@/uni_modules/lime-barcodegen/utssdk';
export default {
data() {
return {
text: '123456789012'
}
},
mounted() {
const el = this.$refs['barcodeRef'] as UniElement
renderer(el, this.text, {
format: 'CODE128'
} as LBarcodeGenOptions)
}
}
自定义样式
可以自定义条形码的颜色、宽度、高度等样式。
<view ref="barcodeRef"></view>
import { renderer, type LBarcodeGenOptions } from '@/uni_modules/lime-barcodegen/utssdk';
export default {
data() {
return {
text: '123456789012'
}
},
mounted() {
const el = this.$refs['barcodeRef'] as UniElement
renderer(el, this.text, {
format: 'CODE128',
lineColor: '#1989fa',
width: 2,
height: 100,
background: '#f5f5f5'
} as LBarcodeGenOptions)
}
}
自定义文本位置
可以设置条形码下方文本的位置和样式。
<view ref="barcodeRef"></view>
import { renderer, LBarcodeGenOptions } from '@/uni_modules/lime-barcodegen/utssdk';
export default {
data() {
return {
text: '123456789012'
}
},
mounted() {
const el = this.$refs['barcodeRef'] as UniElement
renderer(el, this.text, {
format: 'CODE128',
textPosition: 'top', // 文本显示在条形码上方
textAlign: 'center',
fontSize: 16,
textMargin: 5
} as LBarcodeGenOptions)
}
}
不同条形码类型
支持多种条形码类型,如EAN13、CODE39、CODE128、codabar等。
<view ref="barcodeRef1"></view>
<view ref="barcodeRef2"></view>
import { renderer, LBarcodeGenOptions } from '@/uni_modules/lime-barcodegen/utssdk';
export default {
mounted() {
// EAN13条形码
const el1 = this.$refs['barcodeRef1'] as UniElement
renderer(el1, '5901234123457', {
format: 'EAN13'
} as LBarcodeGenOptions)
// CODE39条形码
const el2 = this.$refs['barcodeRef2'] as UniElement
renderer(el2, 'CODE39', {
format: 'CODE39'
} as LBarcodeGenOptions)
}
}
API文档
renderer 函数参数
| 参数名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| element | 用于渲染条形码的DOM元素 | UniElement | - |
| text | 要编码的文本内容 | string | - |
| options | 条形码配置选项 | LBarcodeGenOptions | - |
LBarcodeGenOptions 配置选项
| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| format | 条形码类型,支持EAN13、CODE39、CODE128、codabar等 | string | 'CODE128' |
| width | 条形码线条宽度 | number | 2 |
| height | 条形码高度 | number | 100 |
| displayValue | 是否显示文本 | boolean | true |
| text | 自定义显示文本,不设置则使用编码内容 | string | - |
| fontOptions | 字体选项 | string | - |
| font | 字体 | string | - |
| textAlign | 文本对齐方式,可选值:left、center、right | string | 'center' |
| textPosition | 文本位置,可选值:top、bottom | string | 'bottom' |
| textMargin | 文本与条形码之间的距离 | number | 2 |
| fontSize | 文本字体大小 | number | 20 |
| background | 背景颜色 | string | '#ffffff' |
| lineColor | 线条颜色 | string | '#000000' |
| margin | 四周边距 | number | 10 |
| marginTop | 上边距 | number | - |
| marginBottom | 下边距 | number | - |
| marginLeft | 左边距 | number | - |
| marginRight | 右边距 | number | - |
| flat | 是否使用平面样式 | boolean | false |
| ean128 | 是否使用EAN128格式 | boolean | false |
| mod43 | 是否使用MOD43校验 | boolean | false |
| lastChar | 最后一个字符 | string | - |
接口类型
export type LBarcodeGenOptions = {
format ?: string
width ?: number
height ?: number
/**
* 显示value
* @default true
*/
displayValue ?: boolean
text ?: string
fontOptions ?: string
font? : string
textAlign? : string
textPosition? : string
textMargin? : number
fontSize ?: number
background? : string
lineColor? : string
margin ?: number
marginTop ?: number
marginBottom ?: number
marginLeft ?: number
marginRight ?: number
flat ?: boolean
ean128 ?: boolean
mod43? : boolean
lastChar ?: string
}
export type Encode = {
data : string;
text ?: string;
}
export type EncodeResultOptions = {
textAlign ?: string
fontSize ?: number
height ?: number
}
export type EncodeResult = {
data : string;
text ?: string;
width ?: number
height ?: number
barcodePadding ?: number
options ?: LBarcodeGenOptions
}
export type LBarcodeRendererCallback = (result: EncodeResult) => void
支持的条形码类型
| 类型 | 说明 |
|---|---|
| CODE128 | 支持所有ASCII字符 |
| EAN13 | 欧洲商品编码,13位数字 |
| CODE39 | 支持数字、大写字母和特殊字符 |
| codabar | 支持数字和特定符号 |
注意事项
- 导入插件后需要自定义基座才能运行
- 不同条形码类型对输入文本有不同的要求,请确保输入符合对应条形码类型的规范
- 在使用前确保DOM元素已经渲染完成,建议在mounted或onReady生命周期中调用renderer函数
支持与赞赏
如果你觉得本插件解决了你的问题,可以考虑支持作者:
| 支付宝赞助 | 微信赞助 |
|---|---|
![]() |
![]() |

收藏人数:
购买源码授权版(
试用
赞赏(0)


下载 65024
赞赏 475
下载 11022910
赞赏 1800
赞赏
京公网安备:11010802035340号