条形码在实际应用场景是经常可见的。
这里教大家如何集成uniapp条形码。条形码依赖类库JsBarcode.
下载JsBarcode源码,对CanvasRenderer进行了改进兼容uniapp。
import merge from "../help/merge.js";
import {calculateEncodingAttributes, getTotalWidthOfEncodings, getMaximumHeightOfEncodings} from "./shared.js";
class CanvasRenderer{
constructor(canvas, encodings, options){
this.canvas = canvas;
this.encodings = encodings;
this.options = options;
}
render(){
// Abort if the browser does not support HTML5 canvas
// if (!this.canvas.getContext) {
// throw new Error('The browser does not support canvas.');
// }
this.initSize()
setTimeout(() => {
this.prepareCanvas();
for(let i = 0; i < this.encodings.length; i++){
var encodingOptions = merge(this.options, this.encodings[i].options);
this.drawCanvasBarcode(encodingOptions, this.encodings[i]);
this.drawCanvasText(encodingOptions, this.encodings[i]);
this.moveCanvasDrawing(this.encodings[i]);
}

1546

被折叠的 条评论
为什么被折叠?



