This commit is contained in:
weipengfei 2024-02-01 18:01:18 +08:00
parent 382a9ebaa6
commit 17b9243bf3
59 changed files with 6240 additions and 254 deletions

View File

@ -28,3 +28,6 @@ export const farmAdd = (data) => syhttp.post('/farm/add', data);
//养殖基地列表 //养殖基地列表
export const fenceHouseData = (data) => syhttp.get('/fence_house/datas', data); export const fenceHouseData = (data) => syhttp.get('/fence_house/datas', data);
//溯源信息接口
export const suYuanData = (data) => syhttp.get('/index/suYuan', data);

View File

@ -0,0 +1,411 @@
<template>
<view :class="modal?'show-qrcode':'hide-qrcode'">
<view class="box-qrcode" :style="{'margin-left': marginLeft + 'px'}" @longtap="longtapCode">
<!-- style="width: 550rpx;height: 550rpx;" -->
<canvas class="canvas-qrcode" :style="style_w_h" :canvas-id="qrcode_id">
<!-- #ifndef MP -->
<view v-if="modal&&is_themeImg" :style="style_w_h" class="box-img-qrcode">
<image :style="style_w_h_img" mode="scaleToFill" :src="themeImg"></image>
</view>
<!-- #endif -->
</canvas>
<!-- <image mode="scaleToFill" :src="imagePath"></image> -->
</view>
</view>
</template>
<script>
var qr_we = require("./qrcode_wx.js");
const qrCode = require('./weapp-qrcode.js')
export default {
data() {
return {
isAndroid : false ,
show: true,
imagePath: '',
// qrcode_id: 'qrcode_id',
marginLeft: 0,
//app30
//appmargin-left
//app
add_num : 30 ,
add_num_key : 'rectify_code_key',
}
},
props: {
modal: {
type: Boolean,
default: false
},
url: {
type: String,
default: ''
},
height: {
type: Number,
default: 260
},
width: {
type: Number,
default: 260
},
themeColor: {
type: String,
default: '#333333',
},
qrcode_id: {
type: String,
default: 'qrcode_id',
},
is_themeImg: {
type: Boolean,
default: false,
},
themeImg: {
type: String,
default: 'https://cdn.pixabay.com/photo/2016/11/29/13/24/balloons-1869816__340.jpg',
},
h_w_img: {
type: Number,
default: 30
},
},
watch:{
},
computed: {
style_w_h() {
return this.set_style_w_h();
},
style_w_h_img() {
let that = this;
var height = parseInt(that.h_w_img);
var width = parseInt(that.h_w_img);
var style = '';
if (height > 0) {
style = `height:${height*2}rpx;`;
}
if (width > 0) {
style += `width:${width*2}rpx;z-index: 2;`;
}
return style;
},
},
created: function() {
let that = this;
try {
//app
//#ifndef MP
let isAndroid = false ;
const res = uni.getSystemInfoSync();
if(res.platform == 'android'){
isAndroid = true ;
}else{
isAndroid = false ;
}
if (!isAndroid) {
that.marginLeft = 46;
}
that.isAndroid = isAndroid ;
try {
const add_num = uni.getStorageSync(that.add_num_key);
if (add_num) {
that.add_num = add_num;
}
} catch (e) {
// error
}
// #endif
} catch (e) {
// error
}
//#ifdef MP
//that.marginLeft = 40;
// #endif
},
methods: {
set_style_w_h(){
let that = this;
var height = parseInt(that.height);
var width = parseInt(that.width);
var style = '';
var height = height*2 ;
var width = width*2 ;
//#ifndef MP
var add = that.add_num ;
height += add;
width += add;
// #endif
if (height > 0) {
style = `height:${height}rpx;`;
}
if (width > 0) {
style += `width:${width}rpx;`;
}
return style;
},
hideQrcode() {
this.$emit("hideQrcode")
},
//
crtQrCode() {
let that = this;
//#ifndef MP
new qrCode(that.qrcode_id, {
text: this.url,
width: that.width,
height: that.height,
colorDark: that.themeColor,//#333333
colorLight: "#FFFFFF",
correctLevel: qrCode.CorrectLevel.H,
})
// #endif
//#ifdef MP
that.createQrCode(this.url, that.qrcode_id, that.width, that.height,that.themeColor,that.is_themeImg,that.themeImg,that.h_w_img);
// #endif
//that.createQrCode(this.url, that.qrcode_id, that.width, that.height);
},
//#ifdef MP
createQrCode: function(url, canvasId, cavW, cavH,cavColor,haveImg,imgurl,imgsize) {
//draw
qr_we.api.draw(url, canvasId, cavW, cavH,cavColor,haveImg,imgurl,imgsize, this, this.canvasToTempImage);
// setTimeout(() => { this.canvasToTempImage();},100);
},
// #endif
//data
canvasToTempImage: function() {
var that = this;
},
saveImage: function() {
var that = this;
uni.canvasToTempFilePath({
canvasId: that.qrcode_id,
success: function(res) {
var tempFilePath = res.tempFilePath;
console.log(tempFilePath);
that.imagePath = tempFilePath;
//
// uni.saveFile({
// tempFilePath: tempFilePath,
// success: function (res2) {
// var savedFilePath = res2.savedFilePath;
// }
// });
uni.saveImageToPhotosAlbum({
filePath : tempFilePath ,
success: function (res3) {
uni.showModal({
title: '提示',
content: '保存成功',
confirmText: '确定',
showCancel: false,
confirmColor: '#33CCCC',
success(res4) {
}
})
},
});
},
fail: function(res) {
console.log(res);
}
}, that);
},
//
//APP
longtapCode(){
var that = this;
//#ifndef MP
uni.showModal({
title: '校正二维码',
content: '二维码是否异常',
confirmText: '确定',
confirmColor: '#33CCCC',
success(res) {
if (res.confirm) {
that.rectify_code();
}
}
})
// #endif
//#ifdef MP-WEIXIN
uni.showModal({
title: '提示',
content: '是否保存到相册',
confirmText: '确定',
confirmColor: '#33CCCC',
success(res) {
if (res.confirm) {
that.saveImage();
}
}
})
// #endif
},
//
rectify_code(){
var that = this;
let add_num = that.add_num ;
add_num += 30 ;
that.add_num = add_num;
that.crtQrCode();//
try {
//
uni.setStorage({
key: that.add_num_key,
data: add_num,
success: function() {
}
});
} catch (e) {
// error
}
},
},
mounted() {}
}
</script>
<style scoped lang="scss">
// .qrcode-box {
// position: fixed;
// left: 0;
// top: 0;
// right: 0;
// bottom: 0;
// height: 100vh;
// width: 100vw;
// background-color: rgba(59, 59, 59, 0.6);
// // opacity: 0.8;
// text-align: center;
// display: flex;
// align-items: center;
// display: none;
// .qrcode-item {
// flex: 1;
// position: relative;
// text-align: center;
// .item-box {
// width: 90%;
// margin: auto;
// display: inline-block;
// margin-top: 30%;
// padding-bottom: 30rpx;
// // animation: show 0.7s;
// .title {
// font-size: 46rpx;
// text-align: center;
// margin-bottom: 24rpx;
// }
// .canvas {
// margin: auto;
// display: inline-block;
// margin: auto;
// }
// background-color: #FFFFFF;
// }
// }
// }
.box-qrcode{
text-align: center;
position: relative;
.box-img-qrcode{
position: absolute;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 2;
}
}
image{
width: 60upx;
height: 60upx;
border-radius: 50%;
}
.canvas-qrcode {
margin: auto;
display: inline-block;
float: left;
}
.opacity-qrcode {
opacity: 0;
display: block;
}
.show-qrcode {
display: block;
animation: fade 0.7s;
// -moz-animation: fade 0.5s; /* Firefox */
// -webkit-animation: fade 0.5s; /* Safari Chrome */
// -o-animation: fade 0.5s;
}
.hide-qrcode {
animation: hide 0.7s;
}
@keyframes fade {
from {
opacity: 0.8;
}
to {
opacity: 1;
}
}
@keyframes hide {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
</style>

View File

@ -0,0 +1,872 @@
!(function() {
// alignment pattern
var adelta = [
0, 11, 15, 19, 23, 27, 31,
16, 18, 20, 22, 24, 26, 28, 20, 22, 24, 24, 26, 28, 28, 22, 24, 24,
26, 26, 28, 28, 24, 24, 26, 26, 26, 28, 28, 24, 26, 26, 26, 28, 28
];
// version block
var vpat = [
0xc94, 0x5bc, 0xa99, 0x4d3, 0xbf6, 0x762, 0x847, 0x60d,
0x928, 0xb78, 0x45d, 0xa17, 0x532, 0x9a6, 0x683, 0x8c9,
0x7ec, 0xec4, 0x1e1, 0xfab, 0x08e, 0xc1a, 0x33f, 0xd75,
0x250, 0x9d5, 0x6f0, 0x8ba, 0x79f, 0xb0b, 0x42e, 0xa64,
0x541, 0xc69
];
// final format bits with mask: level << 3 | mask
var fmtword = [
0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976, //L
0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0, //M
0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed, //Q
0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b //H
];
// 4 per version: number of blocks 1,2; data width; ecc width
var eccblocks = [
1, 0, 19, 7, 1, 0, 16, 10, 1, 0, 13, 13, 1, 0, 9, 17,
1, 0, 34, 10, 1, 0, 28, 16, 1, 0, 22, 22, 1, 0, 16, 28,
1, 0, 55, 15, 1, 0, 44, 26, 2, 0, 17, 18, 2, 0, 13, 22,
1, 0, 80, 20, 2, 0, 32, 18, 2, 0, 24, 26, 4, 0, 9, 16,
1, 0, 108, 26, 2, 0, 43, 24, 2, 2, 15, 18, 2, 2, 11, 22,
2, 0, 68, 18, 4, 0, 27, 16, 4, 0, 19, 24, 4, 0, 15, 28,
2, 0, 78, 20, 4, 0, 31, 18, 2, 4, 14, 18, 4, 1, 13, 26,
2, 0, 97, 24, 2, 2, 38, 22, 4, 2, 18, 22, 4, 2, 14, 26,
2, 0, 116, 30, 3, 2, 36, 22, 4, 4, 16, 20, 4, 4, 12, 24,
2, 2, 68, 18, 4, 1, 43, 26, 6, 2, 19, 24, 6, 2, 15, 28,
4, 0, 81, 20, 1, 4, 50, 30, 4, 4, 22, 28, 3, 8, 12, 24,
2, 2, 92, 24, 6, 2, 36, 22, 4, 6, 20, 26, 7, 4, 14, 28,
4, 0, 107, 26, 8, 1, 37, 22, 8, 4, 20, 24, 12, 4, 11, 22,
3, 1, 115, 30, 4, 5, 40, 24, 11, 5, 16, 20, 11, 5, 12, 24,
5, 1, 87, 22, 5, 5, 41, 24, 5, 7, 24, 30, 11, 7, 12, 24,
5, 1, 98, 24, 7, 3, 45, 28, 15, 2, 19, 24, 3, 13, 15, 30,
1, 5, 107, 28, 10, 1, 46, 28, 1, 15, 22, 28, 2, 17, 14, 28,
5, 1, 120, 30, 9, 4, 43, 26, 17, 1, 22, 28, 2, 19, 14, 28,
3, 4, 113, 28, 3, 11, 44, 26, 17, 4, 21, 26, 9, 16, 13, 26,
3, 5, 107, 28, 3, 13, 41, 26, 15, 5, 24, 30, 15, 10, 15, 28,
4, 4, 116, 28, 17, 0, 42, 26, 17, 6, 22, 28, 19, 6, 16, 30,
2, 7, 111, 28, 17, 0, 46, 28, 7, 16, 24, 30, 34, 0, 13, 24,
4, 5, 121, 30, 4, 14, 47, 28, 11, 14, 24, 30, 16, 14, 15, 30,
6, 4, 117, 30, 6, 14, 45, 28, 11, 16, 24, 30, 30, 2, 16, 30,
8, 4, 106, 26, 8, 13, 47, 28, 7, 22, 24, 30, 22, 13, 15, 30,
10, 2, 114, 28, 19, 4, 46, 28, 28, 6, 22, 28, 33, 4, 16, 30,
8, 4, 122, 30, 22, 3, 45, 28, 8, 26, 23, 30, 12, 28, 15, 30,
3, 10, 117, 30, 3, 23, 45, 28, 4, 31, 24, 30, 11, 31, 15, 30,
7, 7, 116, 30, 21, 7, 45, 28, 1, 37, 23, 30, 19, 26, 15, 30,
5, 10, 115, 30, 19, 10, 47, 28, 15, 25, 24, 30, 23, 25, 15, 30,
13, 3, 115, 30, 2, 29, 46, 28, 42, 1, 24, 30, 23, 28, 15, 30,
17, 0, 115, 30, 10, 23, 46, 28, 10, 35, 24, 30, 19, 35, 15, 30,
17, 1, 115, 30, 14, 21, 46, 28, 29, 19, 24, 30, 11, 46, 15, 30,
13, 6, 115, 30, 14, 23, 46, 28, 44, 7, 24, 30, 59, 1, 16, 30,
12, 7, 121, 30, 12, 26, 47, 28, 39, 14, 24, 30, 22, 41, 15, 30,
6, 14, 121, 30, 6, 34, 47, 28, 46, 10, 24, 30, 2, 64, 15, 30,
17, 4, 122, 30, 29, 14, 46, 28, 49, 10, 24, 30, 24, 46, 15, 30,
4, 18, 122, 30, 13, 32, 46, 28, 48, 14, 24, 30, 42, 32, 15, 30,
20, 4, 117, 30, 40, 7, 47, 28, 43, 22, 24, 30, 10, 67, 15, 30,
19, 6, 118, 30, 18, 31, 47, 28, 34, 34, 24, 30, 20, 61, 15, 30
];
// Galois field log table
var glog = [
0xff, 0x00, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6, 0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b,
0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81, 0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71,
0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21, 0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45,
0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9, 0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6,
0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd, 0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88,
0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd, 0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40,
0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e, 0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d,
0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b, 0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57,
0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d, 0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18,
0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c, 0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e,
0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd, 0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61,
0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e, 0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2,
0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76, 0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6,
0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa, 0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a,
0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51, 0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7,
0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8, 0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
];
// Galios field exponent table
var gexp = [
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26,
0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9, 0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0,
0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35, 0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23,
0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1,
0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc, 0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0,
0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f, 0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2,
0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88, 0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce,
0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93, 0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc,
0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9, 0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54,
0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa, 0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73,
0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e, 0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff,
0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4, 0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41,
0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6,
0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef, 0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09,
0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5, 0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16,
0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83, 0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x00
];
// Working buffers:
// data input and ecc append, image working buffer, fixed part of image, run lengths for badness
var strinbuf = [],
eccbuf = [],
qrframe = [],
framask = [],
rlens = [];
// Control values - width is based on version, last 4 are from table.
var version, width, neccblk1, neccblk2, datablkw, eccblkwid;
var ecclevel = 2;
// set bit to indicate cell in qrframe is immutable. symmetric around diagonal
function setmask(x, y) {
var bt;
if (x > y) {
bt = x;
x = y;
y = bt;
}
// y*y = 1+3+5...
bt = y;
bt *= y;
bt += y;
bt >>= 1;
bt += x;
framask[bt] = 1;
}
// enter alignment pattern - black to qrframe, white to mask (later black frame merged to mask)
function putalign(x, y) {
var j;
qrframe[x + width * y] = 1;
for (j = -2; j < 2; j++) {
qrframe[(x + j) + width * (y - 2)] = 1;
qrframe[(x - 2) + width * (y + j + 1)] = 1;
qrframe[(x + 2) + width * (y + j)] = 1;
qrframe[(x + j + 1) + width * (y + 2)] = 1;
}
for (j = 0; j < 2; j++) {
setmask(x - 1, y + j);
setmask(x + 1, y - j);
setmask(x - j, y - 1);
setmask(x + j, y + 1);
}
}
//========================================================================
// Reed Solomon error correction
// exponentiation mod N
function modnn(x) {
while (x >= 255) {
x -= 255;
x = (x >> 8) + (x & 255);
}
return x;
}
var genpoly = [];
// Calculate and append ECC data to data block. Block is in strinbuf, indexes to buffers given.
function appendrs(data, dlen, ecbuf, eclen) {
var i, j, fb;
for (i = 0; i < eclen; i++)
strinbuf[ecbuf + i] = 0;
for (i = 0; i < dlen; i++) {
fb = glog[strinbuf[data + i] ^ strinbuf[ecbuf]];
if (fb != 255) /* fb term is non-zero */
for (j = 1; j < eclen; j++)
strinbuf[ecbuf + j - 1] = strinbuf[ecbuf + j] ^ gexp[modnn(fb + genpoly[eclen - j])];
else
for (j = ecbuf; j < ecbuf + eclen; j++)
strinbuf[j] = strinbuf[j + 1];
strinbuf[ecbuf + eclen - 1] = fb == 255 ? 0 : gexp[modnn(fb + genpoly[0])];
}
}
//========================================================================
// Frame data insert following the path rules
// check mask - since symmetrical use half.
function ismasked(x, y) {
var bt;
if (x > y) {
bt = x;
x = y;
y = bt;
}
bt = y;
bt += y * y;
bt >>= 1;
bt += x;
return framask[bt];
}
//========================================================================
// Apply the selected mask out of the 8.
function applymask(m) {
var x, y, r3x, r3y;
switch (m) {
case 0:
for (y = 0; y < width; y++)
for (x = 0; x < width; x++)
if (!((x + y) & 1) && !ismasked(x, y))
qrframe[x + y * width] ^= 1;
break;
case 1:
for (y = 0; y < width; y++)
for (x = 0; x < width; x++)
if (!(y & 1) && !ismasked(x, y))
qrframe[x + y * width] ^= 1;
break;
case 2:
for (y = 0; y < width; y++)
for (r3x = 0, x = 0; x < width; x++, r3x++) {
if (r3x == 3)
r3x = 0;
if (!r3x && !ismasked(x, y))
qrframe[x + y * width] ^= 1;
}
break;
case 3:
for (r3y = 0, y = 0; y < width; y++, r3y++) {
if (r3y == 3)
r3y = 0;
for (r3x = r3y, x = 0; x < width; x++, r3x++) {
if (r3x == 3)
r3x = 0;
if (!r3x && !ismasked(x, y))
qrframe[x + y * width] ^= 1;
}
}
break;
case 4:
for (y = 0; y < width; y++)
for (r3x = 0, r3y = ((y >> 1) & 1), x = 0; x < width; x++, r3x++) {
if (r3x == 3) {
r3x = 0;
r3y = !r3y;
}
if (!r3y && !ismasked(x, y))
qrframe[x + y * width] ^= 1;
}
break;
case 5:
for (r3y = 0, y = 0; y < width; y++, r3y++) {
if (r3y == 3)
r3y = 0;
for (r3x = 0, x = 0; x < width; x++, r3x++) {
if (r3x == 3)
r3x = 0;
if (!((x & y & 1) + !(!r3x | !r3y)) && !ismasked(x, y))
qrframe[x + y * width] ^= 1;
}
}
break;
case 6:
for (r3y = 0, y = 0; y < width; y++, r3y++) {
if (r3y == 3)
r3y = 0;
for (r3x = 0, x = 0; x < width; x++, r3x++) {
if (r3x == 3)
r3x = 0;
if (!(((x & y & 1) + (r3x && (r3x == r3y))) & 1) && !ismasked(x, y))
qrframe[x + y * width] ^= 1;
}
}
break;
case 7:
for (r3y = 0, y = 0; y < width; y++, r3y++) {
if (r3y == 3)
r3y = 0;
for (r3x = 0, x = 0; x < width; x++, r3x++) {
if (r3x == 3)
r3x = 0;
if (!(((r3x && (r3x == r3y)) + ((x + y) & 1)) & 1) && !ismasked(x, y))
qrframe[x + y * width] ^= 1;
}
}
break;
}
return;
}
// Badness coefficients.
var N1 = 3,
N2 = 3,
N3 = 40,
N4 = 10;
// Using the table of the length of each run, calculate the amount of bad image
// - long runs or those that look like finders; called twice, once each for X and Y
function badruns(length) {
var i;
var runsbad = 0;
for (i = 0; i <= length; i++)
if (rlens[i] >= 5)
runsbad += N1 + rlens[i] - 5;
// BwBBBwB as in finder
for (i = 3; i < length - 1; i += 2)
if (rlens[i - 2] == rlens[i + 2] &&
rlens[i + 2] == rlens[i - 1] &&
rlens[i - 1] == rlens[i + 1] &&
rlens[i - 1] * 3 == rlens[i]
// white around the black pattern? Not part of spec
&&
(rlens[i - 3] == 0 // beginning
||
i + 3 > length // end
||
rlens[i - 3] * 3 >= rlens[i] * 4 || rlens[i + 3] * 3 >= rlens[i] * 4)
)
runsbad += N3;
return runsbad;
}
// Calculate how bad the masked image is - blocks, imbalance, runs, or finders.
function badcheck() {
var x, y, h, b, b1;
var thisbad = 0;
var bw = 0;
// blocks of same color.
for (y = 0; y < width - 1; y++)
for (x = 0; x < width - 1; x++)
if ((qrframe[x + width * y] && qrframe[(x + 1) + width * y] &&
qrframe[x + width * (y + 1)] && qrframe[(x + 1) + width * (y + 1)]) // all black
||
!(qrframe[x + width * y] || qrframe[(x + 1) + width * y] ||
qrframe[x + width * (y + 1)] || qrframe[(x + 1) + width * (y + 1)])) // all white
thisbad += N2;
// X runs
for (y = 0; y < width; y++) {
rlens[0] = 0;
for (h = b = x = 0; x < width; x++) {
if ((b1 = qrframe[x + width * y]) == b)
rlens[h]++;
else
rlens[++h] = 1;
b = b1;
bw += b ? 1 : -1;
}
thisbad += badruns(h);
}
// black/white imbalance
if (bw < 0)
bw = -bw;
var big = bw;
var count = 0;
big += big << 2;
big <<= 1;
while (big > width * width)
big -= width * width, count++;
thisbad += count * N4;
// Y runs
for (x = 0; x < width; x++) {
rlens[0] = 0;
for (h = b = y = 0; y < width; y++) {
if ((b1 = qrframe[x + width * y]) == b)
rlens[h]++;
else
rlens[++h] = 1;
b = b1;
}
thisbad += badruns(h);
}
return thisbad;
}
function genframe(instring) {
var x, y, k, t, v, i, j, m;
// find the smallest version that fits the string
t = instring.length;
version = 0;
do {
version++;
k = (ecclevel - 1) * 4 + (version - 1) * 16;
neccblk1 = eccblocks[k++];
neccblk2 = eccblocks[k++];
datablkw = eccblocks[k++];
eccblkwid = eccblocks[k];
k = datablkw * (neccblk1 + neccblk2) + neccblk2 - 3 + (version <= 9);
if (t <= k)
break;
} while (version < 40);
// FIXME - insure that it fits insted of being truncated
width = 17 + 4 * version;
// allocate, clear and setup data structures
v = datablkw + (datablkw + eccblkwid) * (neccblk1 + neccblk2) + neccblk2;
for (t = 0; t < v; t++)
eccbuf[t] = 0;
strinbuf = instring.slice(0);
for (t = 0; t < width * width; t++)
qrframe[t] = 0;
for (t = 0; t < (width * (width + 1) + 1) / 2; t++)
framask[t] = 0;
// insert finders - black to frame, white to mask
for (t = 0; t < 3; t++) {
k = 0;
y = 0;
if (t == 1)
k = (width - 7);
if (t == 2)
y = (width - 7);
qrframe[(y + 3) + width * (k + 3)] = 1;
for (x = 0; x < 6; x++) {
qrframe[(y + x) + width * k] = 1;
qrframe[y + width * (k + x + 1)] = 1;
qrframe[(y + 6) + width * (k + x)] = 1;
qrframe[(y + x + 1) + width * (k + 6)] = 1;
}
for (x = 1; x < 5; x++) {
setmask(y + x, k + 1);
setmask(y + 1, k + x + 1);
setmask(y + 5, k + x);
setmask(y + x + 1, k + 5);
}
for (x = 2; x < 4; x++) {
qrframe[(y + x) + width * (k + 2)] = 1;
qrframe[(y + 2) + width * (k + x + 1)] = 1;
qrframe[(y + 4) + width * (k + x)] = 1;
qrframe[(y + x + 1) + width * (k + 4)] = 1;
}
}
// alignment blocks
if (version > 1) {
t = adelta[version];
y = width - 7;
for (;;) {
x = width - 7;
while (x > t - 3) {
putalign(x, y);
if (x < t)
break;
x -= t;
}
if (y <= t + 9)
break;
y -= t;
putalign(6, y);
putalign(y, 6);
}
}
// single black
qrframe[8 + width * (width - 8)] = 1;
// timing gap - mask only
for (y = 0; y < 7; y++) {
setmask(7, y);
setmask(width - 8, y);
setmask(7, y + width - 7);
}
for (x = 0; x < 8; x++) {
setmask(x, 7);
setmask(x + width - 8, 7);
setmask(x, width - 8);
}
// reserve mask-format area
for (x = 0; x < 9; x++)
setmask(x, 8);
for (x = 0; x < 8; x++) {
setmask(x + width - 8, 8);
setmask(8, x);
}
for (y = 0; y < 7; y++)
setmask(8, y + width - 7);
// timing row/col
for (x = 0; x < width - 14; x++)
if (x & 1) {
setmask(8 + x, 6);
setmask(6, 8 + x);
}
else {
qrframe[(8 + x) + width * 6] = 1;
qrframe[6 + width * (8 + x)] = 1;
}
// version block
if (version > 6) {
t = vpat[version - 7];
k = 17;
for (x = 0; x < 6; x++)
for (y = 0; y < 3; y++, k--)
if (1 & (k > 11 ? version >> (k - 12) : t >> k)) {
qrframe[(5 - x) + width * (2 - y + width - 11)] = 1;
qrframe[(2 - y + width - 11) + width * (5 - x)] = 1;
}
else {
setmask(5 - x, 2 - y + width - 11);
setmask(2 - y + width - 11, 5 - x);
}
}
// sync mask bits - only set above for white spaces, so add in black bits
for (y = 0; y < width; y++)
for (x = 0; x <= y; x++)
if (qrframe[x + width * y])
setmask(x, y);
// convert string to bitstream
// 8 bit data to QR-coded 8 bit data (numeric or alphanum, or kanji not supported)
v = strinbuf.length;
// string to array
for (i = 0; i < v; i++)
eccbuf[i] = strinbuf.charCodeAt(i);
strinbuf = eccbuf.slice(0);
// calculate max string length
x = datablkw * (neccblk1 + neccblk2) + neccblk2;
if (v >= x - 2) {
v = x - 2;
if (version > 9)
v--;
}
// shift and repack to insert length prefix
i = v;
if (version > 9) {
strinbuf[i + 2] = 0;
strinbuf[i + 3] = 0;
while (i--) {
t = strinbuf[i];
strinbuf[i + 3] |= 255 & (t << 4);
strinbuf[i + 2] = t >> 4;
}
strinbuf[2] |= 255 & (v << 4);
strinbuf[1] = v >> 4;
strinbuf[0] = 0x40 | (v >> 12);
} else {
strinbuf[i + 1] = 0;
strinbuf[i + 2] = 0;
while (i--) {
t = strinbuf[i];
strinbuf[i + 2] |= 255 & (t << 4);
strinbuf[i + 1] = t >> 4;
}
strinbuf[1] |= 255 & (v << 4);
strinbuf[0] = 0x40 | (v >> 4);
}
// fill to end with pad pattern
i = v + 3 - (version < 10);
while (i < x) {
strinbuf[i++] = 0xec;
// buffer has room if (i == x) break;
strinbuf[i++] = 0x11;
}
// calculate and append ECC
// calculate generator polynomial
genpoly[0] = 1;
for (i = 0; i < eccblkwid; i++) {
genpoly[i + 1] = 1;
for (j = i; j > 0; j--)
genpoly[j] = genpoly[j] ?
genpoly[j - 1] ^ gexp[modnn(glog[genpoly[j]] + i)] : genpoly[j - 1];
genpoly[0] = gexp[modnn(glog[genpoly[0]] + i)];
}
for (i = 0; i <= eccblkwid; i++)
genpoly[i] = glog[genpoly[i]]; // use logs for genpoly[] to save calc step
// append ecc to data buffer
k = x;
y = 0;
for (i = 0; i < neccblk1; i++) {
appendrs(y, datablkw, k, eccblkwid);
y += datablkw;
k += eccblkwid;
}
for (i = 0; i < neccblk2; i++) {
appendrs(y, datablkw + 1, k, eccblkwid);
y += datablkw + 1;
k += eccblkwid;
}
// interleave blocks
y = 0;
for (i = 0; i < datablkw; i++) {
for (j = 0; j < neccblk1; j++)
eccbuf[y++] = strinbuf[i + j * datablkw];
for (j = 0; j < neccblk2; j++)
eccbuf[y++] = strinbuf[(neccblk1 * datablkw) + i + (j * (datablkw + 1))];
}
for (j = 0; j < neccblk2; j++)
eccbuf[y++] = strinbuf[(neccblk1 * datablkw) + i + (j * (datablkw + 1))];
for (i = 0; i < eccblkwid; i++)
for (j = 0; j < neccblk1 + neccblk2; j++)
eccbuf[y++] = strinbuf[x + i + j * eccblkwid];
strinbuf = eccbuf;
// pack bits into frame avoiding masked area.
x = y = width - 1;
k = v = 1; // up, minus
/* inteleaved data and ecc codes */
m = (datablkw + eccblkwid) * (neccblk1 + neccblk2) + neccblk2;
for (i = 0; i < m; i++) {
t = strinbuf[i];
for (j = 0; j < 8; j++, t <<= 1) {
if (0x80 & t)
qrframe[x + width * y] = 1;
do { // find next fill position
if (v)
x--;
else {
x++;
if (k) {
if (y != 0)
y--;
else {
x -= 2;
k = !k;
if (x == 6) {
x--;
y = 9;
}
}
} else {
if (y != width - 1)
y++;
else {
x -= 2;
k = !k;
if (x == 6) {
x--;
y -= 8;
}
}
}
}
v = !v;
} while (ismasked(x, y));
}
}
// save pre-mask copy of frame
strinbuf = qrframe.slice(0);
t = 0; // best
y = 30000; // demerit
// for instead of while since in original arduino code
// if an early mask was "good enough" it wouldn't try for a better one
// since they get more complex and take longer.
for (k = 0; k < 8; k++) {
applymask(k); // returns black-white imbalance
x = badcheck();
if (x < y) { // current mask better than previous best?
y = x;
t = k;
}
if (t == 7)
break; // don't increment i to a void redoing mask
qrframe = strinbuf.slice(0); // reset for next pass
}
if (t != k) // redo best mask - none good enough, last wasn't t
applymask(t);
// add in final mask/ecclevel bytes
y = fmtword[t + ((ecclevel - 1) << 3)];
// low byte
for (k = 0; k < 8; k++, y >>= 1)
if (y & 1) {
qrframe[(width - 1 - k) + width * 8] = 1;
if (k < 6)
qrframe[8 + width * k] = 1;
else
qrframe[8 + width * (k + 1)] = 1;
}
// high byte
for (k = 0; k < 7; k++, y >>= 1)
if (y & 1) {
qrframe[8 + width * (width - 7 + k)] = 1;
if (k)
qrframe[(6 - k) + width * 8] = 1;
else
qrframe[7 + width * 8] = 1;
}
return qrframe;
}
var _canvas = null;
var api = {
get ecclevel() {
return ecclevel;
},
set ecclevel(val) {
ecclevel = val;
},
get size() {
return _size;
},
set size(val) {
_size = val
},
get canvas() {
return _canvas;
},
set canvas(el) {
_canvas = el;
},
getFrame: function(string) {
return genframe(string);
},
//这里的utf16to8(str)是对Text中的字符串进行转码让其支持中文
utf16to8: function(str) {
var out, i, len, c;
out = "";
len = str.length;
for (i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
},
/**
* 新增$this参数传入组件的this,兼容在组件中生成
*/
draw: function(str, canvas, cavW, cavH, cavColor, haveImg, imageUrl, imageSize, $this, cb = function() {}, ecc) {
var that = this;
ecclevel = ecc || ecclevel;
canvas = canvas || _canvas;
if (!canvas) {
console.warn('No canvas provided to draw QR code in!')
return;
}
let pre_background = "#ffffff";
var size = Math.min(cavW, cavH);
str = that.utf16to8(str); //增加中文显示
var frame = that.getFrame(str);
// 组件中生成qrcode需要绑定this
var ctx = uni.createCanvasContext(canvas, $this);
var px = Math.round(size / (width ));
var roundedSize = px * (width);
// var px = 1 ;
// var roundedSize = px * (width + 8) ;
//var roundedSize = 0 ;
//var offset = Math.floor((size - roundedSize) / 2);
var offset = 0 ;
size = roundedSize;
//ctx.clearRect(0, 0, cavW, cavW);
ctx.setFillStyle(pre_background)
ctx.fillRect(0, 0, cavW, cavW);
ctx.setFillStyle(cavColor);
for (var i = 0; i < width; i++) {
for (var j = 0; j < width; j++) {
if (frame[j * width + i]) {
ctx.fillRect(px * ( i) + offset, px * ( j) + offset, px, px);
}
}
}
//画图片
if (haveImg) {
try {
var x = Number(((cavW - imageSize - 14) / 2).toFixed(2));
var y = Number(((cavH - imageSize -14) / 2).toFixed(2));
drawRoundedRect(ctx, x, y, imageSize, imageSize, imageSize / 2, 6, true, true)
let isNetImg = false;
isNetImg = imageUrl.substr(0, 4) == 'http' ? true : false;
if (isNetImg) {
//网络图片下载到本地
uni.getImageInfo({
src: imageUrl,
success: function(res) {
ctx.drawImage(res.path, x, y, imageSize, imageSize);
//--增加绘制完成回调
ctx.draw(false, function() {
cb();
})
}
})
} else {
ctx.drawImage(imageUrl, x, y, imageSize, imageSize);
//--增加绘制完成回调
ctx.draw(false, function() {
cb();
})
}
// 画圆角矩形
function drawRoundedRect(ctxi, x, y, width, height, r, lineWidth, fill, stroke) {
ctxi.setLineWidth(lineWidth);
ctxi.setFillStyle(pre_background);
ctxi.setStrokeStyle(pre_background);
ctxi.beginPath(); // draw top and top right corner
ctxi.moveTo(x + r, y);
ctxi.arcTo(x + width, y, x + width, y + r, r); // draw right side and bottom right corner
ctxi.arcTo(x + width, y + height, x + width - r, y + height, r); // draw bottom and bottom left corner
ctxi.arcTo(x, y + height, x, y + height - r, r); // draw left and top left corner
ctxi.arcTo(x, y, x + r, y, r);
ctxi.closePath();
if (fill) {
ctxi.fill();
}
if (stroke) {
ctxi.stroke();
}
}
} catch (e) {
//TODO handle the exception
}
} else {
//--增加绘制完成回调
ctx.draw(false, function() {
cb();
})
}
}
}
module.exports = {
api
}
})();

View File

@ -0,0 +1,424 @@
//Core code comes from https://github.com/davidshimjs/qrcodejs
var QRCode;
(function () {
/**
* Get the type by string length
*
* @private
* @param {String} sText
* @param {Number} nCorrectLevel
* @return {Number} type
*/
function _getTypeNumber(sText, nCorrectLevel) {
var nType = 1;
var length = _getUTF8Length(sText);
for (var i = 0, len = QRCodeLimitLength.length; i <= len; i++) {
var nLimit = 0;
switch (nCorrectLevel) {
case QRErrorCorrectLevel.L:
nLimit = QRCodeLimitLength[i][0];
break;
case QRErrorCorrectLevel.M:
nLimit = QRCodeLimitLength[i][1];
break;
case QRErrorCorrectLevel.Q:
nLimit = QRCodeLimitLength[i][2];
break;
case QRErrorCorrectLevel.H:
nLimit = QRCodeLimitLength[i][3];
break;
}
if (length <= nLimit) {
break;
} else {
nType++;
}
}
if (nType > QRCodeLimitLength.length) {
throw new Error("Too long data");
}
return nType;
}
function _getUTF8Length(sText) {
var replacedText = encodeURI(sText).toString().replace(/\%[0-9a-fA-F]{2}/g, 'a');
return replacedText.length + (replacedText.length != sText ? 3 : 0);
}
function QR8bitByte(data) {
this.mode = QRMode.MODE_8BIT_BYTE;
this.data = data;
this.parsedData = [];
// Added to support UTF-8 Characters
for (var i = 0, l = this.data.length; i < l; i++) {
var byteArray = [];
var code = this.data.charCodeAt(i);
if (code > 0x10000) {
byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18);
byteArray[1] = 0x80 | ((code & 0x3F000) >>> 12);
byteArray[2] = 0x80 | ((code & 0xFC0) >>> 6);
byteArray[3] = 0x80 | (code & 0x3F);
} else if (code > 0x800) {
byteArray[0] = 0xE0 | ((code & 0xF000) >>> 12);
byteArray[1] = 0x80 | ((code & 0xFC0) >>> 6);
byteArray[2] = 0x80 | (code & 0x3F);
} else if (code > 0x80) {
byteArray[0] = 0xC0 | ((code & 0x7C0) >>> 6);
byteArray[1] = 0x80 | (code & 0x3F);
} else {
byteArray[0] = code;
}
this.parsedData.push(byteArray);
}
this.parsedData = Array.prototype.concat.apply([], this.parsedData);
if (this.parsedData.length != this.data.length) {
this.parsedData.unshift(191);
this.parsedData.unshift(187);
this.parsedData.unshift(239);
}
}
QR8bitByte.prototype = {
getLength: function (buffer) {
return this.parsedData.length;
},
write: function (buffer) {
for (var i = 0, l = this.parsedData.length; i < l; i++) {
buffer.put(this.parsedData[i], 8);
}
}
};
// QRCodeModel
function QRCodeModel(typeNumber, errorCorrectLevel) {
this.typeNumber = typeNumber;
this.errorCorrectLevel = errorCorrectLevel;
this.modules = null;
this.moduleCount = 0;
this.dataCache = null;
this.dataList = [];
}
QRCodeModel.prototype = {
addData: function (data) { var newData = new QR8bitByte(data); this.dataList.push(newData); this.dataCache = null; }, isDark: function (row, col) {
if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) { throw new Error(row + "," + col); }
return this.modules[row][col];
}, getModuleCount: function () { return this.moduleCount; }, make: function () { this.makeImpl(false, this.getBestMaskPattern()); }, makeImpl: function (test, maskPattern) {
this.moduleCount = this.typeNumber * 4 + 17; this.modules = new Array(this.moduleCount); for (var row = 0; row < this.moduleCount; row++) { this.modules[row] = new Array(this.moduleCount); for (var col = 0; col < this.moduleCount; col++) { this.modules[row][col] = null; } }
this.setupPositionProbePattern(0, 0); this.setupPositionProbePattern(this.moduleCount - 7, 0); this.setupPositionProbePattern(0, this.moduleCount - 7); this.setupPositionAdjustPattern(); this.setupTimingPattern(); this.setupTypeInfo(test, maskPattern); if (this.typeNumber >= 7) { this.setupTypeNumber(test); }
if (this.dataCache == null) { this.dataCache = QRCodeModel.createData(this.typeNumber, this.errorCorrectLevel, this.dataList); }
this.mapData(this.dataCache, maskPattern);
}, setupPositionProbePattern: function (row, col) { for (var r = -1; r <= 7; r++) { if (row + r <= -1 || this.moduleCount <= row + r) continue; for (var c = -1; c <= 7; c++) { if (col + c <= -1 || this.moduleCount <= col + c) continue; if ((0 <= r && r <= 6 && (c == 0 || c == 6)) || (0 <= c && c <= 6 && (r == 0 || r == 6)) || (2 <= r && r <= 4 && 2 <= c && c <= 4)) { this.modules[row + r][col + c] = true; } else { this.modules[row + r][col + c] = false; } } } }, getBestMaskPattern: function () {
var minLostPoint = 0; var pattern = 0; for (var i = 0; i < 8; i++) { this.makeImpl(true, i); var lostPoint = QRUtil.getLostPoint(this); if (i == 0 || minLostPoint > lostPoint) { minLostPoint = lostPoint; pattern = i; } }
return pattern;
}, createMovieClip: function (target_mc, instance_name, depth) {
var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth); var cs = 1; this.make(); for (var row = 0; row < this.modules.length; row++) { var y = row * cs; for (var col = 0; col < this.modules[row].length; col++) { var x = col * cs; var dark = this.modules[row][col]; if (dark) { qr_mc.beginFill(0, 100); qr_mc.moveTo(x, y); qr_mc.lineTo(x + cs, y); qr_mc.lineTo(x + cs, y + cs); qr_mc.lineTo(x, y + cs); qr_mc.endFill(); } } }
return qr_mc;
}, setupTimingPattern: function () {
for (var r = 8; r < this.moduleCount - 8; r++) {
if (this.modules[r][6] != null) { continue; }
this.modules[r][6] = (r % 2 == 0);
}
for (var c = 8; c < this.moduleCount - 8; c++) {
if (this.modules[6][c] != null) { continue; }
this.modules[6][c] = (c % 2 == 0);
}
}, setupPositionAdjustPattern: function () {
var pos = QRUtil.getPatternPosition(this.typeNumber); for (var i = 0; i < pos.length; i++) {
for (var j = 0; j < pos.length; j++) {
var row = pos[i]; var col = pos[j]; if (this.modules[row][col] != null) { continue; }
for (var r = -2; r <= 2; r++) { for (var c = -2; c <= 2; c++) { if (r == -2 || r == 2 || c == -2 || c == 2 || (r == 0 && c == 0)) { this.modules[row + r][col + c] = true; } else { this.modules[row + r][col + c] = false; } } }
}
}
}, setupTypeNumber: function (test) {
var bits = QRUtil.getBCHTypeNumber(this.typeNumber); for (var i = 0; i < 18; i++) { var mod = (!test && ((bits >> i) & 1) == 1); this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod; }
for (var i = 0; i < 18; i++) { var mod = (!test && ((bits >> i) & 1) == 1); this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod; }
}, setupTypeInfo: function (test, maskPattern) {
var data = (this.errorCorrectLevel << 3) | maskPattern; var bits = QRUtil.getBCHTypeInfo(data); for (var i = 0; i < 15; i++) { var mod = (!test && ((bits >> i) & 1) == 1); if (i < 6) { this.modules[i][8] = mod; } else if (i < 8) { this.modules[i + 1][8] = mod; } else { this.modules[this.moduleCount - 15 + i][8] = mod; } }
for (var i = 0; i < 15; i++) { var mod = (!test && ((bits >> i) & 1) == 1); if (i < 8) { this.modules[8][this.moduleCount - i - 1] = mod; } else if (i < 9) { this.modules[8][15 - i - 1 + 1] = mod; } else { this.modules[8][15 - i - 1] = mod; } }
this.modules[this.moduleCount - 8][8] = (!test);
}, mapData: function (data, maskPattern) {
var inc = -1; var row = this.moduleCount - 1; var bitIndex = 7; var byteIndex = 0; for (var col = this.moduleCount - 1; col > 0; col -= 2) {
if (col == 6) col--; while (true) {
for (var c = 0; c < 2; c++) {
if (this.modules[row][col - c] == null) {
var dark = false; if (byteIndex < data.length) { dark = (((data[byteIndex] >>> bitIndex) & 1) == 1); }
var mask = QRUtil.getMask(maskPattern, row, col - c); if (mask) { dark = !dark; }
this.modules[row][col - c] = dark; bitIndex--; if (bitIndex == -1) { byteIndex++; bitIndex = 7; }
}
}
row += inc; if (row < 0 || this.moduleCount <= row) { row -= inc; inc = -inc; break; }
}
}
}
};
QRCodeModel.PAD0 = 0xEC;
QRCodeModel.PAD1 = 0x11;
QRCodeModel.createData = function (typeNumber, errorCorrectLevel, dataList) {
var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel); var buffer = new QRBitBuffer(); for (var i = 0; i < dataList.length; i++) { var data = dataList[i]; buffer.put(data.mode, 4); buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber)); data.write(buffer); }
var totalDataCount = 0; for (var i = 0; i < rsBlocks.length; i++) { totalDataCount += rsBlocks[i].dataCount; }
if (buffer.getLengthInBits() > totalDataCount * 8) {
throw new Error("code length overflow. ("
+ buffer.getLengthInBits()
+ ">"
+ totalDataCount * 8
+ ")");
}
if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { buffer.put(0, 4); }
while (buffer.getLengthInBits() % 8 != 0) { buffer.putBit(false); }
while (true) {
if (buffer.getLengthInBits() >= totalDataCount * 8) { break; }
buffer.put(QRCodeModel.PAD0, 8); if (buffer.getLengthInBits() >= totalDataCount * 8) { break; }
buffer.put(QRCodeModel.PAD1, 8);
}
return QRCodeModel.createBytes(buffer, rsBlocks);
};
QRCodeModel.createBytes = function (buffer, rsBlocks) {
var offset = 0; var maxDcCount = 0; var maxEcCount = 0; var dcdata = new Array(rsBlocks.length); var ecdata = new Array(rsBlocks.length); for (var r = 0; r < rsBlocks.length; r++) {
var dcCount = rsBlocks[r].dataCount; var ecCount = rsBlocks[r].totalCount - dcCount; maxDcCount = Math.max(maxDcCount, dcCount); maxEcCount = Math.max(maxEcCount, ecCount); dcdata[r] = new Array(dcCount); for (var i = 0; i < dcdata[r].length; i++) { dcdata[r][i] = 0xff & buffer.buffer[i + offset]; }
offset += dcCount; var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1); var modPoly = rawPoly.mod(rsPoly); ecdata[r] = new Array(rsPoly.getLength() - 1); for (var i = 0; i < ecdata[r].length; i++) { var modIndex = i + modPoly.getLength() - ecdata[r].length; ecdata[r][i] = (modIndex >= 0) ? modPoly.get(modIndex) : 0; }
}
var totalCodeCount = 0; for (var i = 0; i < rsBlocks.length; i++) { totalCodeCount += rsBlocks[i].totalCount; }
var data = new Array(totalCodeCount); var index = 0; for (var i = 0; i < maxDcCount; i++) { for (var r = 0; r < rsBlocks.length; r++) { if (i < dcdata[r].length) { data[index++] = dcdata[r][i]; } } }
for (var i = 0; i < maxEcCount; i++) { for (var r = 0; r < rsBlocks.length; r++) { if (i < ecdata[r].length) { data[index++] = ecdata[r][i]; } } }
return data;
};
var QRMode = { MODE_NUMBER: 1 << 0, MODE_ALPHA_NUM: 1 << 1, MODE_8BIT_BYTE: 1 << 2, MODE_KANJI: 1 << 3 };
var QRErrorCorrectLevel = { L: 1, M: 0, Q: 3, H: 2 };
var QRMaskPattern = { PATTERN000: 0, PATTERN001: 1, PATTERN010: 2, PATTERN011: 3, PATTERN100: 4, PATTERN101: 5, PATTERN110: 6, PATTERN111: 7 };
var QRUtil = {
PATTERN_POSITION_TABLE: [[], [6, 18], [6, 22], [6, 26], [6, 30], [6, 34], [6, 22, 38], [6, 24, 42], [6, 26, 46], [6, 28, 50], [6, 30, 54], [6, 32, 58], [6, 34, 62], [6, 26, 46, 66], [6, 26, 48, 70], [6, 26, 50, 74], [6, 30, 54, 78], [6, 30, 56, 82], [6, 30, 58, 86], [6, 34, 62, 90], [6, 28, 50, 72, 94], [6, 26, 50, 74, 98], [6, 30, 54, 78, 102], [6, 28, 54, 80, 106], [6, 32, 58, 84, 110], [6, 30, 58, 86, 114], [6, 34, 62, 90, 118], [6, 26, 50, 74, 98, 122], [6, 30, 54, 78, 102, 126], [6, 26, 52, 78, 104, 130], [6, 30, 56, 82, 108, 134], [6, 34, 60, 86, 112, 138], [6, 30, 58, 86, 114, 142], [6, 34, 62, 90, 118, 146], [6, 30, 54, 78, 102, 126, 150], [6, 24, 50, 76, 102, 128, 154], [6, 28, 54, 80, 106, 132, 158], [6, 32, 58, 84, 110, 136, 162], [6, 26, 54, 82, 110, 138, 166], [6, 30, 58, 86, 114, 142, 170]], G15: (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0), G18: (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0), G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), getBCHTypeInfo: function (data) {
var d = data << 10; while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15))); }
return ((data << 10) | d) ^ QRUtil.G15_MASK;
}, getBCHTypeNumber: function (data) {
var d = data << 12; while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18))); }
return (data << 12) | d;
}, getBCHDigit: function (data) {
var digit = 0; while (data != 0) { digit++; data >>>= 1; }
return digit;
}, getPatternPosition: function (typeNumber) { return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; }, getMask: function (maskPattern, i, j) { switch (maskPattern) { case QRMaskPattern.PATTERN000: return (i + j) % 2 == 0; case QRMaskPattern.PATTERN001: return i % 2 == 0; case QRMaskPattern.PATTERN010: return j % 3 == 0; case QRMaskPattern.PATTERN011: return (i + j) % 3 == 0; case QRMaskPattern.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0; case QRMaskPattern.PATTERN101: return (i * j) % 2 + (i * j) % 3 == 0; case QRMaskPattern.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 == 0; case QRMaskPattern.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 == 0; default: throw new Error("bad maskPattern:" + maskPattern); } }, getErrorCorrectPolynomial: function (errorCorrectLength) {
var a = new QRPolynomial([1], 0); for (var i = 0; i < errorCorrectLength; i++) { a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0)); }
return a;
}, getLengthInBits: function (mode, type) { if (1 <= type && type < 10) { switch (mode) { case QRMode.MODE_NUMBER: return 10; case QRMode.MODE_ALPHA_NUM: return 9; case QRMode.MODE_8BIT_BYTE: return 8; case QRMode.MODE_KANJI: return 8; default: throw new Error("mode:" + mode); } } else if (type < 27) { switch (mode) { case QRMode.MODE_NUMBER: return 12; case QRMode.MODE_ALPHA_NUM: return 11; case QRMode.MODE_8BIT_BYTE: return 16; case QRMode.MODE_KANJI: return 10; default: throw new Error("mode:" + mode); } } else if (type < 41) { switch (mode) { case QRMode.MODE_NUMBER: return 14; case QRMode.MODE_ALPHA_NUM: return 13; case QRMode.MODE_8BIT_BYTE: return 16; case QRMode.MODE_KANJI: return 12; default: throw new Error("mode:" + mode); } } else { throw new Error("type:" + type); } }, getLostPoint: function (qrCode) {
var moduleCount = qrCode.getModuleCount(); var lostPoint = 0; for (var row = 0; row < moduleCount; row++) {
for (var col = 0; col < moduleCount; col++) {
var sameCount = 0; var dark = qrCode.isDark(row, col); for (var r = -1; r <= 1; r++) {
if (row + r < 0 || moduleCount <= row + r) { continue; }
for (var c = -1; c <= 1; c++) {
if (col + c < 0 || moduleCount <= col + c) { continue; }
if (r == 0 && c == 0) { continue; }
if (dark == qrCode.isDark(row + r, col + c)) { sameCount++; }
}
}
if (sameCount > 5) { lostPoint += (3 + sameCount - 5); }
}
}
for (var row = 0; row < moduleCount - 1; row++) { for (var col = 0; col < moduleCount - 1; col++) { var count = 0; if (qrCode.isDark(row, col)) count++; if (qrCode.isDark(row + 1, col)) count++; if (qrCode.isDark(row, col + 1)) count++; if (qrCode.isDark(row + 1, col + 1)) count++; if (count == 0 || count == 4) { lostPoint += 3; } } }
for (var row = 0; row < moduleCount; row++) { for (var col = 0; col < moduleCount - 6; col++) { if (qrCode.isDark(row, col) && !qrCode.isDark(row, col + 1) && qrCode.isDark(row, col + 2) && qrCode.isDark(row, col + 3) && qrCode.isDark(row, col + 4) && !qrCode.isDark(row, col + 5) && qrCode.isDark(row, col + 6)) { lostPoint += 40; } } }
for (var col = 0; col < moduleCount; col++) { for (var row = 0; row < moduleCount - 6; row++) { if (qrCode.isDark(row, col) && !qrCode.isDark(row + 1, col) && qrCode.isDark(row + 2, col) && qrCode.isDark(row + 3, col) && qrCode.isDark(row + 4, col) && !qrCode.isDark(row + 5, col) && qrCode.isDark(row + 6, col)) { lostPoint += 40; } } }
var darkCount = 0; for (var col = 0; col < moduleCount; col++) { for (var row = 0; row < moduleCount; row++) { if (qrCode.isDark(row, col)) { darkCount++; } } }
var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; lostPoint += ratio * 10; return lostPoint;
}
};
var QRMath = {
glog: function (n) {
if (n < 1) { throw new Error("glog(" + n + ")"); }
return QRMath.LOG_TABLE[n];
}, gexp: function (n) {
while (n < 0) { n += 255; }
while (n >= 256) { n -= 255; }
return QRMath.EXP_TABLE[n];
}, EXP_TABLE: new Array(256), LOG_TABLE: new Array(256)
}; for (var i = 0; i < 8; i++) { QRMath.EXP_TABLE[i] = 1 << i; }
for (var i = 8; i < 256; i++) { QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8]; }
for (var i = 0; i < 255; i++) { QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i; }
function QRPolynomial(num, shift) {
if (num.length == undefined) { throw new Error(num.length + "/" + shift); }
var offset = 0; while (offset < num.length && num[offset] == 0) { offset++; }
this.num = new Array(num.length - offset + shift); for (var i = 0; i < num.length - offset; i++) { this.num[i] = num[i + offset]; }
}
QRPolynomial.prototype = {
get: function (index) { return this.num[index]; }, getLength: function () { return this.num.length; }, multiply: function (e) {
var num = new Array(this.getLength() + e.getLength() - 1); for (var i = 0; i < this.getLength(); i++) { for (var j = 0; j < e.getLength(); j++) { num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j))); } }
return new QRPolynomial(num, 0);
}, mod: function (e) {
if (this.getLength() - e.getLength() < 0) { return this; }
var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0)); var num = new Array(this.getLength()); for (var i = 0; i < this.getLength(); i++) { num[i] = this.get(i); }
for (var i = 0; i < e.getLength(); i++) { num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio); }
return new QRPolynomial(num, 0).mod(e);
}
};
function QRRSBlock(totalCount, dataCount) { this.totalCount = totalCount; this.dataCount = dataCount; }
QRRSBlock.RS_BLOCK_TABLE = [[1, 26, 19], [1, 26, 16], [1, 26, 13], [1, 26, 9], [1, 44, 34], [1, 44, 28], [1, 44, 22], [1, 44, 16], [1, 70, 55], [1, 70, 44], [2, 35, 17], [2, 35, 13], [1, 100, 80], [2, 50, 32], [2, 50, 24], [4, 25, 9], [1, 134, 108], [2, 67, 43], [2, 33, 15, 2, 34, 16], [2, 33, 11, 2, 34, 12], [2, 86, 68], [4, 43, 27], [4, 43, 19], [4, 43, 15], [2, 98, 78], [4, 49, 31], [2, 32, 14, 4, 33, 15], [4, 39, 13, 1, 40, 14], [2, 121, 97], [2, 60, 38, 2, 61, 39], [4, 40, 18, 2, 41, 19], [4, 40, 14, 2, 41, 15], [2, 146, 116], [3, 58, 36, 2, 59, 37], [4, 36, 16, 4, 37, 17], [4, 36, 12, 4, 37, 13], [2, 86, 68, 2, 87, 69], [4, 69, 43, 1, 70, 44], [6, 43, 19, 2, 44, 20], [6, 43, 15, 2, 44, 16], [4, 101, 81], [1, 80, 50, 4, 81, 51], [4, 50, 22, 4, 51, 23], [3, 36, 12, 8, 37, 13], [2, 116, 92, 2, 117, 93], [6, 58, 36, 2, 59, 37], [4, 46, 20, 6, 47, 21], [7, 42, 14, 4, 43, 15], [4, 133, 107], [8, 59, 37, 1, 60, 38], [8, 44, 20, 4, 45, 21], [12, 33, 11, 4, 34, 12], [3, 145, 115, 1, 146, 116], [4, 64, 40, 5, 65, 41], [11, 36, 16, 5, 37, 17], [11, 36, 12, 5, 37, 13], [5, 109, 87, 1, 110, 88], [5, 65, 41, 5, 66, 42], [5, 54, 24, 7, 55, 25], [11, 36, 12], [5, 122, 98, 1, 123, 99], [7, 73, 45, 3, 74, 46], [15, 43, 19, 2, 44, 20], [3, 45, 15, 13, 46, 16], [1, 135, 107, 5, 136, 108], [10, 74, 46, 1, 75, 47], [1, 50, 22, 15, 51, 23], [2, 42, 14, 17, 43, 15], [5, 150, 120, 1, 151, 121], [9, 69, 43, 4, 70, 44], [17, 50, 22, 1, 51, 23], [2, 42, 14, 19, 43, 15], [3, 141, 113, 4, 142, 114], [3, 70, 44, 11, 71, 45], [17, 47, 21, 4, 48, 22], [9, 39, 13, 16, 40, 14], [3, 135, 107, 5, 136, 108], [3, 67, 41, 13, 68, 42], [15, 54, 24, 5, 55, 25], [15, 43, 15, 10, 44, 16], [4, 144, 116, 4, 145, 117], [17, 68, 42], [17, 50, 22, 6, 51, 23], [19, 46, 16, 6, 47, 17], [2, 139, 111, 7, 140, 112], [17, 74, 46], [7, 54, 24, 16, 55, 25], [34, 37, 13], [4, 151, 121, 5, 152, 122], [4, 75, 47, 14, 76, 48], [11, 54, 24, 14, 55, 25], [16, 45, 15, 14, 46, 16], [6, 147, 117, 4, 148, 118], [6, 73, 45, 14, 74, 46], [11, 54, 24, 16, 55, 25], [30, 46, 16, 2, 47, 17], [8, 132, 106, 4, 133, 107], [8, 75, 47, 13, 76, 48], [7, 54, 24, 22, 55, 25], [22, 45, 15, 13, 46, 16], [10, 142, 114, 2, 143, 115], [19, 74, 46, 4, 75, 47], [28, 50, 22, 6, 51, 23], [33, 46, 16, 4, 47, 17], [8, 152, 122, 4, 153, 123], [22, 73, 45, 3, 74, 46], [8, 53, 23, 26, 54, 24], [12, 45, 15, 28, 46, 16], [3, 147, 117, 10, 148, 118], [3, 73, 45, 23, 74, 46], [4, 54, 24, 31, 55, 25], [11, 45, 15, 31, 46, 16], [7, 146, 116, 7, 147, 117], [21, 73, 45, 7, 74, 46], [1, 53, 23, 37, 54, 24], [19, 45, 15, 26, 46, 16], [5, 145, 115, 10, 146, 116], [19, 75, 47, 10, 76, 48], [15, 54, 24, 25, 55, 25], [23, 45, 15, 25, 46, 16], [13, 145, 115, 3, 146, 116], [2, 74, 46, 29, 75, 47], [42, 54, 24, 1, 55, 25], [23, 45, 15, 28, 46, 16], [17, 145, 115], [10, 74, 46, 23, 75, 47], [10, 54, 24, 35, 55, 25], [19, 45, 15, 35, 46, 16], [17, 145, 115, 1, 146, 116], [14, 74, 46, 21, 75, 47], [29, 54, 24, 19, 55, 25], [11, 45, 15, 46, 46, 16], [13, 145, 115, 6, 146, 116], [14, 74, 46, 23, 75, 47], [44, 54, 24, 7, 55, 25], [59, 46, 16, 1, 47, 17], [12, 151, 121, 7, 152, 122], [12, 75, 47, 26, 76, 48], [39, 54, 24, 14, 55, 25], [22, 45, 15, 41, 46, 16], [6, 151, 121, 14, 152, 122], [6, 75, 47, 34, 76, 48], [46, 54, 24, 10, 55, 25], [2, 45, 15, 64, 46, 16], [17, 152, 122, 4, 153, 123], [29, 74, 46, 14, 75, 47], [49, 54, 24, 10, 55, 25], [24, 45, 15, 46, 46, 16], [4, 152, 122, 18, 153, 123], [13, 74, 46, 32, 75, 47], [48, 54, 24, 14, 55, 25], [42, 45, 15, 32, 46, 16], [20, 147, 117, 4, 148, 118], [40, 75, 47, 7, 76, 48], [43, 54, 24, 22, 55, 25], [10, 45, 15, 67, 46, 16], [19, 148, 118, 6, 149, 119], [18, 75, 47, 31, 76, 48], [34, 54, 24, 34, 55, 25], [20, 45, 15, 61, 46, 16]];
QRRSBlock.getRSBlocks = function (typeNumber, errorCorrectLevel) {
var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel); if (rsBlock == undefined) { throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel); }
var length = rsBlock.length / 3; var list = []; for (var i = 0; i < length; i++) { var count = rsBlock[i * 3 + 0]; var totalCount = rsBlock[i * 3 + 1]; var dataCount = rsBlock[i * 3 + 2]; for (var j = 0; j < count; j++) { list.push(new QRRSBlock(totalCount, dataCount)); } }
return list;
};
QRRSBlock.getRsBlockTable = function (typeNumber, errorCorrectLevel) { switch (errorCorrectLevel) { case QRErrorCorrectLevel.L: return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]; case QRErrorCorrectLevel.M: return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]; case QRErrorCorrectLevel.Q: return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]; case QRErrorCorrectLevel.H: return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]; default: return undefined; } };
function QRBitBuffer() { this.buffer = []; this.length = 0; }
QRBitBuffer.prototype = {
get: function (index) { var bufIndex = Math.floor(index / 8); return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) == 1; }, put: function (num, length) { for (var i = 0; i < length; i++) { this.putBit(((num >>> (length - i - 1)) & 1) == 1); } }, getLengthInBits: function () { return this.length; }, putBit: function (bit) {
var bufIndex = Math.floor(this.length / 8); if (this.buffer.length <= bufIndex) { this.buffer.push(0); }
if (bit) { this.buffer[bufIndex] |= (0x80 >>> (this.length % 8)); }
this.length++;
}
};
var QRCodeLimitLength = [[17, 14, 11, 7], [32, 26, 20, 14], [53, 42, 32, 24], [78, 62, 46, 34], [106, 84, 60, 44], [134, 106, 74, 58], [154, 122, 86, 64], [192, 152, 108, 84], [230, 180, 130, 98], [271, 213, 151, 119], [321, 251, 177, 137], [367, 287, 203, 155], [425, 331, 241, 177], [458, 362, 258, 194], [520, 412, 292, 220], [586, 450, 322, 250], [644, 504, 364, 280], [718, 560, 394, 310], [792, 624, 442, 338], [858, 666, 482, 382], [929, 711, 509, 403], [1003, 779, 565, 439], [1091, 857, 611, 461], [1171, 911, 661, 511], [1273, 997, 715, 535], [1367, 1059, 751, 593], [1465, 1125, 805, 625], [1528, 1190, 868, 658], [1628, 1264, 908, 698], [1732, 1370, 982, 742], [1840, 1452, 1030, 790], [1952, 1538, 1112, 842], [2068, 1628, 1168, 898], [2188, 1722, 1228, 958], [2303, 1809, 1283, 983], [2431, 1911, 1351, 1051], [2563, 1989, 1423, 1093], [2699, 2099, 1499, 1139], [2809, 2213, 1579, 1219], [2953, 2331, 1663, 1273]];
// QRCode object
QRCode = function (canvasId, vOption) {
this._htOption = {
width: 256,
height: 256,
typeNumber: 4,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRErrorCorrectLevel.H
};
if (typeof vOption === 'string') {
vOption = {
text: vOption
};
}
// Overwrites options
if (vOption) {
for (var i in vOption) {
this._htOption[i] = vOption[i];
}
}
this._oQRCode = null;
this.canvasId = canvasId
if (this._htOption.text && this.canvasId) {
this.makeCode(this._htOption.text);
}
};
QRCode.prototype.makeCode = function (sText) {
this._oQRCode = new QRCodeModel(_getTypeNumber(sText, this._htOption.correctLevel), this._htOption.correctLevel);
this._oQRCode.addData(sText);
this._oQRCode.make();
this.makeImage();
};
QRCode.prototype.makeImage = function () {
var _oContext
if (this._htOption.usingIn) {
_oContext = wx.createCanvasContext(this.canvasId, this._htOption.usingIn)
}
else {
_oContext = wx.createCanvasContext(this.canvasId)
}
var _htOption = this._htOption;
var oQRCode = this._oQRCode
var nCount = oQRCode.getModuleCount();
var nWidth = _htOption.width / nCount;
var nHeight = _htOption.height / nCount;
var nRoundedWidth = Math.round(nWidth);
var nRoundedHeight = Math.round(nHeight);
if (_htOption.image && _htOption.image != '') {
_oContext.drawImage(_htOption.image, 0, 0, _htOption.width, _htOption.height)
}
for (var row = 0; row < nCount; row++) {
for (var col = 0; col < nCount; col++) {
var bIsDark = oQRCode.isDark(row, col);
var nLeft = col * nWidth;
var nTop = row * nHeight;
_oContext.setStrokeStyle(bIsDark ? _htOption.colorDark : _htOption.colorLight)
// _oContext.setStrokeStyle('yellow')
_oContext.setLineWidth(1)
_oContext.setFillStyle(bIsDark ? _htOption.colorDark : _htOption.colorLight)
// _oContext.setFillStyle('red')
// if (bIsDark) {
_oContext.fillRect(nLeft, nTop, nWidth, nHeight);
// }
// 안티 앨리어싱 방지 처리
// if (bIsDark) {
_oContext.strokeRect(
Math.floor(nLeft) + 0.5,
Math.floor(nTop) + 0.5,
nRoundedWidth,
nRoundedHeight
);
_oContext.strokeRect(
Math.ceil(nLeft) - 0.5,
Math.ceil(nTop) - 0.5,
nRoundedWidth,
nRoundedHeight
);
// }
// _oContext.fillRect(
// Math.floor(nLeft) + 0.5,
// Math.floor(nTop) + 0.5,
// nRoundedWidth,
// nRoundedHeight
// );
// _oContext.fillRect(
// Math.ceil(nLeft) - 0.5,
// Math.ceil(nTop) - 0.5,
// nRoundedWidth,
// nRoundedHeight
// );
// _oContext.clearRect(
// Math.floor(nLeft) + 0.5,
// Math.floor(nTop) + 0.5,
// nRoundedWidth,
// nRoundedHeight
// );
// _oContext.clearRect(
// Math.ceil(nLeft) - 0.5,
// Math.ceil(nTop) - 0.5,
// nRoundedWidth,
// nRoundedHeight
// );
}
}
_oContext.draw()
};
// 保存为图片,将临时路径传给回调
QRCode.prototype.exportImage = function (callback) {
if (!callback) {
return
}
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: this._htOption.width,
height: this._htOption.height,
destWidth: this._htOption.width,
destHeight: this._htOption.height,
canvasId: this.canvasId,
success: function (res) {
console.log(res.tempFilePath)
callback(res.tempFilePath)
}
})
}
QRCode.CorrectLevel = QRErrorCorrectLevel;
})();
module.exports = QRCode

View File

@ -0,0 +1,191 @@
// const barcodes = require('./barcodes/index.js')['default'];
import * as barcodes from './barcodes/index.js';
let barcode = {};
(function () {
// 初始化
barcode = function (cont, ctxid, options, ctxsize, result) {
let ops = {}, newOptions, encodings, globaContext, ctx, globaCtxid, cbCanvasSize, cbResult;
globaCtxid = ctxid
cbCanvasSize = ctxsize
cbResult = result
newOptions = Object.assign(ops, options);
// 修成margin
fixMargin(newOptions)
// 处理options 数据
if (newOptions.text == '' || cont == '') {
return false
}
// 获取ctx
globaContext = cont
ctx = uni.createCanvasContext(globaCtxid, globaContext)
// 获取编码数据
encodings = new barcodes[newOptions.format.toUpperCase()](newOptions.text, newOptions).encode()
let fixencodings = fixEncodings(encodings, newOptions)
// 返回canvas实际大小
cbCanvasSize({ width: fixencodings.width, height: fixencodings.height })
// 绘制canvas
setTimeout(() => {
drawCanvas.render(newOptions, fixencodings)
}, 50);
// 绘制canvas
let drawCanvas = {
render(options, encoding) {
this.prepare(options, encoding)
encoding.encodings.forEach((v, i) => {
this.barcode(options, v)
this.text(options, v)
this.move(v)
});
this.draw(options, encoding)
},
barcode(options, encoding) {
let binary = encoding.data;
let yFrom;
if (options.textPosition == "top") {
yFrom = options.marginTop + options.fontSize + options.textMargin;
} else {
yFrom = options.marginTop;
}
// 绘制条码
ctx.fillStyle = options.lineColor;
for (let b = 0; b < binary.length; b++) {
let x = b * options.width + encoding.barcodePadding;
let height = options.height
if (encoding.options) {
if (encoding.options.height != undefined) {
height = encoding.options.height
}
}
if (binary[b] === "1") {
ctx.fillRect(x, yFrom, options.width, height);
} else if (binary[b]) {
ctx.fillRect(x, yFrom, options.width, height * binary[b]);
}
}
},
text(options, encoding) {
if (options.displayValue) {
let x, y, align, size;
if (options.textPosition == "top") {
y = options.marginTop + options.fontSize;
} else {
y = options.height + options.textMargin + options.marginTop + options.fontSize;
}
if (encoding.options) {
if (encoding.options.textAlign != undefined) {
align = encoding.options.textAlign
}
if (encoding.options.fontSize != undefined) {
size = encoding.options.fontSize
}
} else {
align = options.textAlign
size = options.fontSize
}
ctx.setFontSize(size)
if (align == "left" || encoding.barcodePadding > 0) {
x = 0;
ctx.setTextAlign('left')
} else if (align == "right") {
x = encoding.width - 1;
ctx.setTextAlign('right')
}
else {
x = encoding.width / 2;
ctx.setTextAlign('center');
}
ctx.fillStyle = options.fontColor;
if (encoding.text != undefined) {
ctx.fillText(encoding.text, x, y);
}
}
},
move(encoding) {
ctx.translate(encoding.width, 0);
},
prepare(options, encoding) {
// 绘制背景
if (options.background) {
ctx.fillStyle = options.background;
ctx.fillRect(0, 0, encoding.width, encoding.height);
}
ctx.translate(options.marginLeft, 0);
},
draw(options, encoding) {
ctx.draw(false, () => {
this.toImgs(options, encoding)
})
},
toImgs(options, encoding) {
setTimeout(() => {
uni.canvasToTempFilePath({
width: encoding.width,
height: encoding.height,
destWidth: encoding.width,
destHeight: encoding.height,
canvasId: globaCtxid,
fileType: 'png',
success: function (res) {
cbResult(res.tempFilePath)
},
fail: function (res) {
cbResult(res)
},
complete: function () {
// uni.hideLoading();
},
}, globaContext);
}, options.text.length + 100);
}
}
// 混入canvas数据
function fixEncodings(encoding, options) {
let encodingArr = [], width = options.marginLeft + options.marginRight, height;
if (!Array.isArray(encoding)) {
encodingArr[0] = JSON.parse(JSON.stringify(encoding))
} else {
encodingArr = [...encoding]
}
encodingArr.forEach((v, i) => {
// 获取文本宽度
let textWidth = ctx.measureText(encodingArr[i].text ? encodingArr[i].text : '').width;
// 获取条形码宽度
let barcodeWidth = encodingArr[i].data.length * options.width;
// 获取内边距
let barcodePadding = 0;
if (options.displayValue && barcodeWidth < textWidth) {
if (options.textAlign == "center") {
barcodePadding = Math.floor((textWidth - barcodeWidth) / 2);
} else if (options.textAlign == "left") {
barcodePadding = 0;
} else if (options.textAlign == "right") {
barcodePadding = Math.floor(textWidth - barcodeWidth);
}
}
// 混入encodingArr[i]
encodingArr[i].barcodePadding = barcodePadding
encodingArr[i].width = Math.ceil(Math.max(textWidth, barcodeWidth))
width += encodingArr[i].width
if (encodingArr[i].options) {
if (encodingArr[i].options.height != undefined) {
encodingArr[i].height = encodingArr[i].options.height + (options.displayValue && (encodingArr[i].text ? encodingArr[i].text : '').length > 0 ? options.fontSize + options.textMargin : 0) + options.marginTop + options.marginBottom;
} else {
encodingArr[i].height = height = options.height + (options.displayValue && (encodingArr[i].text ? encodingArr[i].text : '').length > 0 ? options.fontSize + options.textMargin : 0) + options.marginTop + options.marginBottom;
}
} else {
encodingArr[i].height = height = options.height + (options.displayValue && (encodingArr[i].text ? encodingArr[i].text : '').length > 0 ? options.fontSize + options.textMargin : 0) + options.marginTop + options.marginBottom;
}
});
return { encodings: encodingArr, width, height };
}
// 修正Margin
function fixMargin(options) {
options.marginTop = options.marginTop == undefined ? options.margin : options.marginTop;
options.marginBottom = options.marginBottom == undefined ? options.margin : options.marginBottom;
options.marginRight = options.marginRight == undefined ? options.margin : options.marginRight;
options.marginLeft = options.marginLeft == undefined ? options.margin : options.marginLeft;
}
};
})()
export default barcode

View File

@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Barcode = function Barcode(data, options) {
_classCallCheck(this, Barcode);
this.data = data;
this.text = options.text || data;
this.options = options;
};
exports.default = Barcode;

View File

@ -0,0 +1,167 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Barcode2 = require('../Barcode.js');
var _Barcode3 = _interopRequireDefault(_Barcode2);
var _constants = require('./constants');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// This is the master class,
// it does require the start code to be included in the string
var CODE128 = function (_Barcode) {
_inherits(CODE128, _Barcode);
function CODE128(data, options) {
_classCallCheck(this, CODE128);
// Get array of ascii codes from data
var _this = _possibleConstructorReturn(this, (CODE128.__proto__ || Object.getPrototypeOf(CODE128)).call(this, data.substring(1), options));
_this.bytes = data.split('').map(function (char) {
return char.charCodeAt(0);
});
return _this;
}
_createClass(CODE128, [{
key: 'valid',
value: function valid() {
// ASCII value ranges 0-127, 200-211
return (/^[\x00-\x7F\xC8-\xD3]+$/.test(this.data)
);
}
// The public encoding function
}, {
key: 'encode',
value: function encode() {
var bytes = this.bytes;
// Remove the start code from the bytes and set its index
var startIndex = bytes.shift() - 105;
// Get start set by index
var startSet = _constants.SET_BY_CODE[startIndex];
if (startSet === undefined) {
throw new RangeError('The encoding does not start with a start character.');
}
if (this.shouldEncodeAsEan128() === true) {
bytes.unshift(_constants.FNC1);
}
// Start encode with the right type
var encodingResult = CODE128.next(bytes, 1, startSet);
return {
text: this.text === this.data ? this.text.replace(/[^\x20-\x7E]/g, '') : this.text,
data:
// Add the start bits
CODE128.getBar(startIndex) +
// Add the encoded bits
encodingResult.result +
// Add the checksum
CODE128.getBar((encodingResult.checksum + startIndex) % _constants.MODULO) +
// Add the end bits
CODE128.getBar(_constants.STOP)
};
}
// GS1-128/EAN-128
}, {
key: 'shouldEncodeAsEan128',
value: function shouldEncodeAsEan128() {
var isEAN128 = this.options.ean128 || false;
if (typeof isEAN128 === 'string') {
isEAN128 = isEAN128.toLowerCase() === 'true';
}
return isEAN128;
}
// Get a bar symbol by index
}], [{
key: 'getBar',
value: function getBar(index) {
return _constants.BARS[index] ? _constants.BARS[index].toString() : '';
}
// Correct an index by a set and shift it from the bytes array
}, {
key: 'correctIndex',
value: function correctIndex(bytes, set) {
if (set === _constants.SET_A) {
var charCode = bytes.shift();
return charCode < 32 ? charCode + 64 : charCode - 32;
} else if (set === _constants.SET_B) {
return bytes.shift() - 32;
} else {
return (bytes.shift() - 48) * 10 + bytes.shift() - 48;
}
}
}, {
key: 'next',
value: function next(bytes, pos, set) {
if (!bytes.length) {
return { result: '', checksum: 0 };
}
var nextCode = void 0,
index = void 0;
// Special characters
if (bytes[0] >= 200) {
index = bytes.shift() - 105;
var nextSet = _constants.SWAP[index];
// Swap to other set
if (nextSet !== undefined) {
nextCode = CODE128.next(bytes, pos + 1, nextSet);
}
// Continue on current set but encode a special character
else {
// Shift
if ((set === _constants.SET_A || set === _constants.SET_B) && index === _constants.SHIFT) {
// Convert the next character so that is encoded correctly
bytes[0] = set === _constants.SET_A ? bytes[0] > 95 ? bytes[0] - 96 : bytes[0] : bytes[0] < 32 ? bytes[0] + 96 : bytes[0];
}
nextCode = CODE128.next(bytes, pos + 1, set);
}
}
// Continue encoding
else {
index = CODE128.correctIndex(bytes, set);
nextCode = CODE128.next(bytes, pos + 1, set);
}
// Get the correct binary encoding and calculate the weight
var enc = CODE128.getBar(index);
var weight = index * pos;
return {
result: enc + nextCode.result,
checksum: weight + nextCode.checksum
};
}
}]);
return CODE128;
}(_Barcode3.default);
exports.default = CODE128;

View File

@ -0,0 +1,42 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _CODE2 = require('./CODE128.js');
var _CODE3 = _interopRequireDefault(_CODE2);
var _constants = require('./constants');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CODE128A = function (_CODE) {
_inherits(CODE128A, _CODE);
function CODE128A(string, options) {
_classCallCheck(this, CODE128A);
return _possibleConstructorReturn(this, (CODE128A.__proto__ || Object.getPrototypeOf(CODE128A)).call(this, _constants.A_START_CHAR + string, options));
}
_createClass(CODE128A, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants.A_CHARS + '+$').test(this.data);
}
}]);
return CODE128A;
}(_CODE3.default);
exports.default = CODE128A;

View File

@ -0,0 +1,42 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _CODE2 = require('./CODE128.js');
var _CODE3 = _interopRequireDefault(_CODE2);
var _constants = require('./constants');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CODE128B = function (_CODE) {
_inherits(CODE128B, _CODE);
function CODE128B(string, options) {
_classCallCheck(this, CODE128B);
return _possibleConstructorReturn(this, (CODE128B.__proto__ || Object.getPrototypeOf(CODE128B)).call(this, _constants.B_START_CHAR + string, options));
}
_createClass(CODE128B, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants.B_CHARS + '+$').test(this.data);
}
}]);
return CODE128B;
}(_CODE3.default);
exports.default = CODE128B;

View File

@ -0,0 +1,42 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _CODE2 = require('./CODE128.js');
var _CODE3 = _interopRequireDefault(_CODE2);
var _constants = require('./constants');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CODE128C = function (_CODE) {
_inherits(CODE128C, _CODE);
function CODE128C(string, options) {
_classCallCheck(this, CODE128C);
return _possibleConstructorReturn(this, (CODE128C.__proto__ || Object.getPrototypeOf(CODE128C)).call(this, _constants.C_START_CHAR + string, options));
}
_createClass(CODE128C, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants.C_CHARS + '+$').test(this.data);
}
}]);
return CODE128C;
}(_CODE3.default);
exports.default = CODE128C;

View File

@ -0,0 +1,41 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _CODE2 = require('./CODE128');
var _CODE3 = _interopRequireDefault(_CODE2);
var _auto = require('./auto');
var _auto2 = _interopRequireDefault(_auto);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CODE128AUTO = function (_CODE) {
_inherits(CODE128AUTO, _CODE);
function CODE128AUTO(data, options) {
_classCallCheck(this, CODE128AUTO);
// ASCII value ranges 0-127, 200-211
if (/^[\x00-\x7F\xC8-\xD3]+$/.test(data)) {
var _this = _possibleConstructorReturn(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, (0, _auto2.default)(data), options));
} else {
var _this = _possibleConstructorReturn(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, data, options));
}
return _possibleConstructorReturn(_this);
}
return CODE128AUTO;
}(_CODE3.default);
exports.default = CODE128AUTO;

View File

@ -0,0 +1,73 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _constants = require('./constants');
// Match Set functions
var matchSetALength = function matchSetALength(string) {
return string.match(new RegExp('^' + _constants.A_CHARS + '*'))[0].length;
};
var matchSetBLength = function matchSetBLength(string) {
return string.match(new RegExp('^' + _constants.B_CHARS + '*'))[0].length;
};
var matchSetC = function matchSetC(string) {
return string.match(new RegExp('^' + _constants.C_CHARS + '*'))[0];
};
// CODE128A or CODE128B
function autoSelectFromAB(string, isA) {
var ranges = isA ? _constants.A_CHARS : _constants.B_CHARS;
var untilC = string.match(new RegExp('^(' + ranges + '+?)(([0-9]{2}){2,})([^0-9]|$)'));
if (untilC) {
return untilC[1] + String.fromCharCode(204) + autoSelectFromC(string.substring(untilC[1].length));
}
var chars = string.match(new RegExp('^' + ranges + '+'))[0];
if (chars.length === string.length) {
return string;
}
return chars + String.fromCharCode(isA ? 205 : 206) + autoSelectFromAB(string.substring(chars.length), !isA);
}
// CODE128C
function autoSelectFromC(string) {
var cMatch = matchSetC(string);
var length = cMatch.length;
if (length === string.length) {
return string;
}
string = string.substring(length);
// Select A/B depending on the longest match
var isA = matchSetALength(string) >= matchSetBLength(string);
return cMatch + String.fromCharCode(isA ? 206 : 205) + autoSelectFromAB(string, isA);
}
// Detect Code Set (A, B or C) and format the string
exports.default = function (string) {
var newString = void 0;
var cLength = matchSetC(string).length;
// Select 128C if the string start with enough digits
if (cLength >= 2) {
newString = _constants.C_START_CHAR + autoSelectFromC(string);
} else {
// Select A/B depending on the longest match
var isA = matchSetALength(string) > matchSetBLength(string);
newString = (isA ? _constants.A_START_CHAR : _constants.B_START_CHAR) + autoSelectFromAB(string, isA);
}
return newString.replace(/[\xCD\xCE]([^])[\xCD\xCE]/, // Any sequence between 205 and 206 characters
function (match, char) {
return String.fromCharCode(203) + char;
});
};

View File

@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _SET_BY_CODE;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// constants for internal usage
var SET_A = exports.SET_A = 0;
var SET_B = exports.SET_B = 1;
var SET_C = exports.SET_C = 2;
// Special characters
var SHIFT = exports.SHIFT = 98;
var START_A = exports.START_A = 103;
var START_B = exports.START_B = 104;
var START_C = exports.START_C = 105;
var MODULO = exports.MODULO = 103;
var STOP = exports.STOP = 106;
var FNC1 = exports.FNC1 = 207;
// Get set by start code
var SET_BY_CODE = exports.SET_BY_CODE = (_SET_BY_CODE = {}, _defineProperty(_SET_BY_CODE, START_A, SET_A), _defineProperty(_SET_BY_CODE, START_B, SET_B), _defineProperty(_SET_BY_CODE, START_C, SET_C), _SET_BY_CODE);
// Get next set by code
var SWAP = exports.SWAP = {
101: SET_A,
100: SET_B,
99: SET_C
};
var A_START_CHAR = exports.A_START_CHAR = String.fromCharCode(208); // START_A + 105
var B_START_CHAR = exports.B_START_CHAR = String.fromCharCode(209); // START_B + 105
var C_START_CHAR = exports.C_START_CHAR = String.fromCharCode(210); // START_C + 105
// 128A (Code Set A)
// ASCII characters 00 to 95 (09, AZ and control codes), special characters, and FNC 14
var A_CHARS = exports.A_CHARS = "[\x00-\x5F\xC8-\xCF]";
// 128B (Code Set B)
// ASCII characters 32 to 127 (09, AZ, az), special characters, and FNC 14
var B_CHARS = exports.B_CHARS = "[\x20-\x7F\xC8-\xCF]";
// 128C (Code Set C)
// 0099 (encodes two digits with a single code point) and FNC1
var C_CHARS = exports.C_CHARS = "(\xCF*[0-9]{2}\xCF*)";
// CODE128 includes 107 symbols:
// 103 data symbols, 3 start symbols (A, B and C), and 1 stop symbol (the last one)
// Each symbol consist of three black bars (1) and three white spaces (0).
var BARS = exports.BARS = [11011001100, 11001101100, 11001100110, 10010011000, 10010001100, 10001001100, 10011001000, 10011000100, 10001100100, 11001001000, 11001000100, 11000100100, 10110011100, 10011011100, 10011001110, 10111001100, 10011101100, 10011100110, 11001110010, 11001011100, 11001001110, 11011100100, 11001110100, 11101101110, 11101001100, 11100101100, 11100100110, 11101100100, 11100110100, 11100110010, 11011011000, 11011000110, 11000110110, 10100011000, 10001011000, 10001000110, 10110001000, 10001101000, 10001100010, 11010001000, 11000101000, 11000100010, 10110111000, 10110001110, 10001101110, 10111011000, 10111000110, 10001110110, 11101110110, 11010001110, 11000101110, 11011101000, 11011100010, 11011101110, 11101011000, 11101000110, 11100010110, 11101101000, 11101100010, 11100011010, 11101111010, 11001000010, 11110001010, 10100110000, 10100001100, 10010110000, 10010000110, 10000101100, 10000100110, 10110010000, 10110000100, 10011010000, 10011000010, 10000110100, 10000110010, 11000010010, 11001010000, 11110111010, 11000010100, 10001111010, 10100111100, 10010111100, 10010011110, 10111100100, 10011110100, 10011110010, 11110100100, 11110010100, 11110010010, 11011011110, 11011110110, 11110110110, 10101111000, 10100011110, 10001011110, 10111101000, 10111100010, 11110101000, 11110100010, 10111011110, 10111101110, 11101011110, 11110101110, 11010000100, 11010010000, 11010011100, 1100011101011];

View File

@ -0,0 +1,29 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CODE128C = exports.CODE128B = exports.CODE128A = exports.CODE128 = undefined;
var _CODE128_AUTO = require('./CODE128_AUTO.js');
var _CODE128_AUTO2 = _interopRequireDefault(_CODE128_AUTO);
var _CODE128A = require('./CODE128A.js');
var _CODE128A2 = _interopRequireDefault(_CODE128A);
var _CODE128B = require('./CODE128B.js');
var _CODE128B2 = _interopRequireDefault(_CODE128B);
var _CODE128C = require('./CODE128C.js');
var _CODE128C2 = _interopRequireDefault(_CODE128C);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.CODE128 = _CODE128_AUTO2.default;
exports.CODE128A = _CODE128A2.default;
exports.CODE128B = _CODE128B2.default;
exports.CODE128C = _CODE128C2.default;

View File

@ -0,0 +1,104 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CODE39 = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Barcode2 = require("../Barcode.js");
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/Code_39#Encoding
var CODE39 = function (_Barcode) {
_inherits(CODE39, _Barcode);
function CODE39(data, options) {
_classCallCheck(this, CODE39);
data = data.toUpperCase();
// Calculate mod43 checksum if enabled
if (options.mod43) {
data += getCharacter(mod43checksum(data));
}
return _possibleConstructorReturn(this, (CODE39.__proto__ || Object.getPrototypeOf(CODE39)).call(this, data, options));
}
_createClass(CODE39, [{
key: "encode",
value: function encode() {
// First character is always a *
var result = getEncoding("*");
// Take every character and add the binary representation to the result
for (var i = 0; i < this.data.length; i++) {
result += getEncoding(this.data[i]) + "0";
}
// Last character is always a *
result += getEncoding("*");
return {
data: result,
text: this.text
};
}
}, {
key: "valid",
value: function valid() {
return this.data.search(/^[0-9A-Z\-\.\ \$\/\+\%]+$/) !== -1;
}
}]);
return CODE39;
}(_Barcode3.default);
// All characters. The position in the array is the (checksum) value
var characters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%", "*"];
// The decimal representation of the characters, is converted to the
// corresponding binary with the getEncoding function
var encodings = [20957, 29783, 23639, 30485, 20951, 29813, 23669, 20855, 29789, 23645, 29975, 23831, 30533, 22295, 30149, 24005, 21623, 29981, 23837, 22301, 30023, 23879, 30545, 22343, 30161, 24017, 21959, 30065, 23921, 22385, 29015, 18263, 29141, 17879, 29045, 18293, 17783, 29021, 18269, 17477, 17489, 17681, 20753, 35770];
// Get the binary representation of a character by converting the encodings
// from decimal to binary
function getEncoding(character) {
return getBinary(characterValue(character));
}
function getBinary(characterValue) {
return encodings[characterValue].toString(2);
}
function getCharacter(characterValue) {
return characters[characterValue];
}
function characterValue(character) {
return characters.indexOf(character);
}
function mod43checksum(data) {
var checksum = 0;
for (var i = 0; i < data.length; i++) {
checksum += characterValue(data[i]);
}
checksum = checksum % 43;
return checksum;
}
exports.CODE39 = CODE39;

View File

@ -0,0 +1,92 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants = require('./constants');
var _encoder = require('./encoder');
var _encoder2 = _interopRequireDefault(_encoder);
var _Barcode2 = require('../Barcode');
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// Base class for EAN8 & EAN13
var EAN = function (_Barcode) {
_inherits(EAN, _Barcode);
function EAN(data, options) {
_classCallCheck(this, EAN);
// Make sure the font is not bigger than the space between the guard bars
var _this = _possibleConstructorReturn(this, (EAN.__proto__ || Object.getPrototypeOf(EAN)).call(this, data, options));
_this.fontSize = !options.flat && options.fontSize > options.width * 10 ? options.width * 10 : options.fontSize;
// Make the guard bars go down half the way of the text
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
return _this;
}
_createClass(EAN, [{
key: 'encode',
value: function encode() {
return this.options.flat ? this.encodeFlat() : this.encodeGuarded();
}
}, {
key: 'leftText',
value: function leftText(from, to) {
return this.text.substr(from, to);
}
}, {
key: 'leftEncode',
value: function leftEncode(data, structure) {
return (0, _encoder2.default)(data, structure);
}
}, {
key: 'rightText',
value: function rightText(from, to) {
return this.text.substr(from, to);
}
}, {
key: 'rightEncode',
value: function rightEncode(data, structure) {
return (0, _encoder2.default)(data, structure);
}
}, {
key: 'encodeGuarded',
value: function encodeGuarded() {
var textOptions = { fontSize: this.fontSize };
var guardOptions = { height: this.guardHeight };
return [{ data: _constants.SIDE_BIN, options: guardOptions }, { data: this.leftEncode(), text: this.leftText(), options: textOptions }, { data: _constants.MIDDLE_BIN, options: guardOptions }, { data: this.rightEncode(), text: this.rightText(), options: textOptions }, { data: _constants.SIDE_BIN, options: guardOptions }];
}
}, {
key: 'encodeFlat',
value: function encodeFlat() {
var data = [_constants.SIDE_BIN, this.leftEncode(), _constants.MIDDLE_BIN, this.rightEncode(), _constants.SIDE_BIN];
return {
data: data.join(''),
text: this.text
};
}
}]);
return EAN;
}(_Barcode3.default);
exports.default = EAN;

View File

@ -0,0 +1,119 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _constants = require('./constants');
var _EAN2 = require('./EAN');
var _EAN3 = _interopRequireDefault(_EAN2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Binary_encoding_of_data_digits_into_EAN-13_barcode
// Calculate the checksum digit
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
var checksum = function checksum(number) {
var res = number.substr(0, 12).split('').map(function (n) {
return +n;
}).reduce(function (sum, a, idx) {
return idx % 2 ? sum + a * 3 : sum + a;
}, 0);
return (10 - res % 10) % 10;
};
var EAN13 = function (_EAN) {
_inherits(EAN13, _EAN);
function EAN13(data, options) {
_classCallCheck(this, EAN13);
// Add checksum if it does not exist
if (data.search(/^[0-9]{12}$/) !== -1) {
data += checksum(data);
}
// Adds a last character to the end of the barcode
var _this = _possibleConstructorReturn(this, (EAN13.__proto__ || Object.getPrototypeOf(EAN13)).call(this, data, options));
_this.lastChar = options.lastChar;
return _this;
}
_createClass(EAN13, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{13}$/) !== -1 && +this.data[12] === checksum(this.data);
}
}, {
key: 'leftText',
value: function leftText() {
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'leftText', this).call(this, 1, 6);
}
}, {
key: 'leftEncode',
value: function leftEncode() {
var data = this.data.substr(1, 6);
var structure = _constants.EAN13_STRUCTURE[this.data[0]];
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'leftEncode', this).call(this, data, structure);
}
}, {
key: 'rightText',
value: function rightText() {
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'rightText', this).call(this, 7, 6);
}
}, {
key: 'rightEncode',
value: function rightEncode() {
var data = this.data.substr(7, 6);
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'rightEncode', this).call(this, data, 'RRRRRR');
}
// The "standard" way of printing EAN13 barcodes with guard bars
}, {
key: 'encodeGuarded',
value: function encodeGuarded() {
var data = _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'encodeGuarded', this).call(this);
// Extend data with left digit & last character
if (this.options.displayValue) {
data.unshift({
data: '000000000000',
text: this.text.substr(0, 1),
options: { textAlign: 'left', fontSize: this.fontSize }
});
if (this.options.lastChar) {
data.push({
data: '00'
});
data.push({
data: '00000',
text: this.options.lastChar,
options: { fontSize: this.fontSize }
});
}
}
return data;
}
}]);
return EAN13;
}(_EAN3.default);
exports.default = EAN13;

View File

@ -0,0 +1,58 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants = require('./constants');
var _encoder = require('./encoder');
var _encoder2 = _interopRequireDefault(_encoder);
var _Barcode2 = require('../Barcode');
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/EAN_2#Encoding
var EAN2 = function (_Barcode) {
_inherits(EAN2, _Barcode);
function EAN2(data, options) {
_classCallCheck(this, EAN2);
return _possibleConstructorReturn(this, (EAN2.__proto__ || Object.getPrototypeOf(EAN2)).call(this, data, options));
}
_createClass(EAN2, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{2}$/) !== -1;
}
}, {
key: 'encode',
value: function encode() {
// Choose the structure based on the number mod 4
var structure = _constants.EAN2_STRUCTURE[parseInt(this.data) % 4];
return {
// Start bits + Encode the two digits with 01 in between
data: '1011' + (0, _encoder2.default)(this.data, structure, '01'),
text: this.text
};
}
}]);
return EAN2;
}(_Barcode3.default);
exports.default = EAN2;

View File

@ -0,0 +1,65 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants = require('./constants');
var _encoder = require('./encoder');
var _encoder2 = _interopRequireDefault(_encoder);
var _Barcode2 = require('../Barcode');
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/EAN_5#Encoding
var checksum = function checksum(data) {
var result = data.split('').map(function (n) {
return +n;
}).reduce(function (sum, a, idx) {
return idx % 2 ? sum + a * 9 : sum + a * 3;
}, 0);
return result % 10;
};
var EAN5 = function (_Barcode) {
_inherits(EAN5, _Barcode);
function EAN5(data, options) {
_classCallCheck(this, EAN5);
return _possibleConstructorReturn(this, (EAN5.__proto__ || Object.getPrototypeOf(EAN5)).call(this, data, options));
}
_createClass(EAN5, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{5}$/) !== -1;
}
}, {
key: 'encode',
value: function encode() {
var structure = _constants.EAN5_STRUCTURE[checksum(this.data)];
return {
data: '1011' + (0, _encoder2.default)(this.data, structure, '01'),
text: this.text
};
}
}]);
return EAN5;
}(_Barcode3.default);
exports.default = EAN5;

View File

@ -0,0 +1,81 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _EAN2 = require('./EAN');
var _EAN3 = _interopRequireDefault(_EAN2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// http://www.barcodeisland.com/ean8.phtml
// Calculate the checksum digit
var checksum = function checksum(number) {
var res = number.substr(0, 7).split('').map(function (n) {
return +n;
}).reduce(function (sum, a, idx) {
return idx % 2 ? sum + a : sum + a * 3;
}, 0);
return (10 - res % 10) % 10;
};
var EAN8 = function (_EAN) {
_inherits(EAN8, _EAN);
function EAN8(data, options) {
_classCallCheck(this, EAN8);
// Add checksum if it does not exist
if (data.search(/^[0-9]{7}$/) !== -1) {
data += checksum(data);
}
return _possibleConstructorReturn(this, (EAN8.__proto__ || Object.getPrototypeOf(EAN8)).call(this, data, options));
}
_createClass(EAN8, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{8}$/) !== -1 && +this.data[7] === checksum(this.data);
}
}, {
key: 'leftText',
value: function leftText() {
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'leftText', this).call(this, 0, 4);
}
}, {
key: 'leftEncode',
value: function leftEncode() {
var data = this.data.substr(0, 4);
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'leftEncode', this).call(this, data, 'LLLL');
}
}, {
key: 'rightText',
value: function rightText() {
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'rightText', this).call(this, 4, 4);
}
}, {
key: 'rightEncode',
value: function rightEncode() {
var data = this.data.substr(4, 4);
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'rightEncode', this).call(this, data, 'RRRR');
}
}]);
return EAN8;
}(_EAN3.default);
exports.default = EAN8;

View File

@ -0,0 +1,165 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.checksum = checksum;
var _encoder = require("./encoder");
var _encoder2 = _interopRequireDefault(_encoder);
var _Barcode2 = require("../Barcode.js");
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
var UPC = function (_Barcode) {
_inherits(UPC, _Barcode);
function UPC(data, options) {
_classCallCheck(this, UPC);
// Add checksum if it does not exist
if (data.search(/^[0-9]{11}$/) !== -1) {
data += checksum(data);
}
var _this = _possibleConstructorReturn(this, (UPC.__proto__ || Object.getPrototypeOf(UPC)).call(this, data, options));
_this.displayValue = options.displayValue;
// Make sure the font is not bigger than the space between the guard bars
if (options.fontSize > options.width * 10) {
_this.fontSize = options.width * 10;
} else {
_this.fontSize = options.fontSize;
}
// Make the guard bars go down half the way of the text
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
return _this;
}
_createClass(UPC, [{
key: "valid",
value: function valid() {
return this.data.search(/^[0-9]{12}$/) !== -1 && this.data[11] == checksum(this.data);
}
}, {
key: "encode",
value: function encode() {
if (this.options.flat) {
return this.flatEncoding();
} else {
return this.guardedEncoding();
}
}
}, {
key: "flatEncoding",
value: function flatEncoding() {
var result = "";
result += "101";
result += (0, _encoder2.default)(this.data.substr(0, 6), "LLLLLL");
result += "01010";
result += (0, _encoder2.default)(this.data.substr(6, 6), "RRRRRR");
result += "101";
return {
data: result,
text: this.text
};
}
}, {
key: "guardedEncoding",
value: function guardedEncoding() {
var result = [];
// Add the first digit
if (this.displayValue) {
result.push({
data: "00000000",
text: this.text.substr(0, 1),
options: { textAlign: "left", fontSize: this.fontSize }
});
}
// Add the guard bars
result.push({
data: "101" + (0, _encoder2.default)(this.data[0], "L"),
options: { height: this.guardHeight }
});
// Add the left side
result.push({
data: (0, _encoder2.default)(this.data.substr(1, 5), "LLLLL"),
text: this.text.substr(1, 5),
options: { fontSize: this.fontSize }
});
// Add the middle bits
result.push({
data: "01010",
options: { height: this.guardHeight }
});
// Add the right side
result.push({
data: (0, _encoder2.default)(this.data.substr(6, 5), "RRRRR"),
text: this.text.substr(6, 5),
options: { fontSize: this.fontSize }
});
// Add the end bits
result.push({
data: (0, _encoder2.default)(this.data[11], "R") + "101",
options: { height: this.guardHeight }
});
// Add the last digit
if (this.displayValue) {
result.push({
data: "00000000",
text: this.text.substr(11, 1),
options: { textAlign: "right", fontSize: this.fontSize }
});
}
return result;
}
}]);
return UPC;
}(_Barcode3.default);
// Calulate the checksum digit
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
function checksum(number) {
var result = 0;
var i;
for (i = 1; i < 11; i += 2) {
result += parseInt(number[i]);
}
for (i = 0; i < 11; i += 2) {
result += parseInt(number[i]) * 3;
}
return (10 - result % 10) % 10;
}
exports.default = UPC;

View File

@ -0,0 +1,185 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _encoder = require('./encoder');
var _encoder2 = _interopRequireDefault(_encoder);
var _Barcode2 = require('../Barcode.js');
var _Barcode3 = _interopRequireDefault(_Barcode2);
var _UPC = require('./UPC.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
//
// UPC-E documentation:
// https://en.wikipedia.org/wiki/Universal_Product_Code#UPC-E
var EXPANSIONS = ["XX00000XXX", "XX10000XXX", "XX20000XXX", "XXX00000XX", "XXXX00000X", "XXXXX00005", "XXXXX00006", "XXXXX00007", "XXXXX00008", "XXXXX00009"];
var PARITIES = [["EEEOOO", "OOOEEE"], ["EEOEOO", "OOEOEE"], ["EEOOEO", "OOEEOE"], ["EEOOOE", "OOEEEO"], ["EOEEOO", "OEOOEE"], ["EOOEEO", "OEEOOE"], ["EOOOEE", "OEEEOO"], ["EOEOEO", "OEOEOE"], ["EOEOOE", "OEOEEO"], ["EOOEOE", "OEEOEO"]];
var UPCE = function (_Barcode) {
_inherits(UPCE, _Barcode);
function UPCE(data, options) {
_classCallCheck(this, UPCE);
var _this = _possibleConstructorReturn(this, (UPCE.__proto__ || Object.getPrototypeOf(UPCE)).call(this, data, options));
// Code may be 6 or 8 digits;
// A 7 digit code is ambiguous as to whether the extra digit
// is a UPC-A check or number system digit.
_this.isValid = false;
if (data.search(/^[0-9]{6}$/) !== -1) {
_this.middleDigits = data;
_this.upcA = expandToUPCA(data, "0");
_this.text = options.text || '' + _this.upcA[0] + data + _this.upcA[_this.upcA.length - 1];
_this.isValid = true;
} else if (data.search(/^[01][0-9]{7}$/) !== -1) {
_this.middleDigits = data.substring(1, data.length - 1);
_this.upcA = expandToUPCA(_this.middleDigits, data[0]);
if (_this.upcA[_this.upcA.length - 1] === data[data.length - 1]) {
_this.isValid = true;
} else {
// checksum mismatch
return _possibleConstructorReturn(_this);
}
} else {
return _possibleConstructorReturn(_this);
}
_this.displayValue = options.displayValue;
// Make sure the font is not bigger than the space between the guard bars
if (options.fontSize > options.width * 10) {
_this.fontSize = options.width * 10;
} else {
_this.fontSize = options.fontSize;
}
// Make the guard bars go down half the way of the text
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
return _this;
}
_createClass(UPCE, [{
key: 'valid',
value: function valid() {
return this.isValid;
}
}, {
key: 'encode',
value: function encode() {
if (this.options.flat) {
return this.flatEncoding();
} else {
return this.guardedEncoding();
}
}
}, {
key: 'flatEncoding',
value: function flatEncoding() {
var result = "";
result += "101";
result += this.encodeMiddleDigits();
result += "010101";
return {
data: result,
text: this.text
};
}
}, {
key: 'guardedEncoding',
value: function guardedEncoding() {
var result = [];
// Add the UPC-A number system digit beneath the quiet zone
if (this.displayValue) {
result.push({
data: "00000000",
text: this.text[0],
options: { textAlign: "left", fontSize: this.fontSize }
});
}
// Add the guard bars
result.push({
data: "101",
options: { height: this.guardHeight }
});
// Add the 6 UPC-E digits
result.push({
data: this.encodeMiddleDigits(),
text: this.text.substring(1, 7),
options: { fontSize: this.fontSize }
});
// Add the end bits
result.push({
data: "010101",
options: { height: this.guardHeight }
});
// Add the UPC-A check digit beneath the quiet zone
if (this.displayValue) {
result.push({
data: "00000000",
text: this.text[7],
options: { textAlign: "right", fontSize: this.fontSize }
});
}
return result;
}
}, {
key: 'encodeMiddleDigits',
value: function encodeMiddleDigits() {
var numberSystem = this.upcA[0];
var checkDigit = this.upcA[this.upcA.length - 1];
var parity = PARITIES[parseInt(checkDigit)][parseInt(numberSystem)];
return (0, _encoder2.default)(this.middleDigits, parity);
}
}]);
return UPCE;
}(_Barcode3.default);
function expandToUPCA(middleDigits, numberSystem) {
var lastUpcE = parseInt(middleDigits[middleDigits.length - 1]);
var expansion = EXPANSIONS[lastUpcE];
var result = "";
var digitIndex = 0;
for (var i = 0; i < expansion.length; i++) {
var c = expansion[i];
if (c === 'X') {
result += middleDigits[digitIndex++];
} else {
result += c;
}
}
result = '' + numberSystem + result;
return '' + result + (0, _UPC.checksum)(result);
}
exports.default = UPCE;

View File

@ -0,0 +1,30 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
// Standard start end and middle bits
var SIDE_BIN = exports.SIDE_BIN = '101';
var MIDDLE_BIN = exports.MIDDLE_BIN = '01010';
var BINARIES = exports.BINARIES = {
'L': [// The L (left) type of encoding
'0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'],
'G': [// The G type of encoding
'0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111'],
'R': [// The R (right) type of encoding
'1110010', '1100110', '1101100', '1000010', '1011100', '1001110', '1010000', '1000100', '1001000', '1110100'],
'O': [// The O (odd) encoding for UPC-E
'0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'],
'E': [// The E (even) encoding for UPC-E
'0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111']
};
// Define the EAN-2 structure
var EAN2_STRUCTURE = exports.EAN2_STRUCTURE = ['LL', 'LG', 'GL', 'GG'];
// Define the EAN-5 structure
var EAN5_STRUCTURE = exports.EAN5_STRUCTURE = ['GGLLL', 'GLGLL', 'GLLGL', 'GLLLG', 'LGGLL', 'LLGGL', 'LLLGG', 'LGLGL', 'LGLLG', 'LLGLG'];
// Define the EAN-13 structure
var EAN13_STRUCTURE = exports.EAN13_STRUCTURE = ['LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG', 'LGGLLG', 'LGGGLL', 'LGLGLG', 'LGLGGL', 'LGGLGL'];

View File

@ -0,0 +1,27 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _constants = require('./constants');
// Encode data string
var encode = function encode(data, structure, separator) {
var encoded = data.split('').map(function (val, idx) {
return _constants.BINARIES[structure[idx]];
}).map(function (val, idx) {
return val ? val[data[idx]] : '';
});
if (separator) {
var last = data.length - 1;
encoded = encoded.map(function (val, idx) {
return idx < last ? val + separator : val;
});
}
return encoded.join('');
};
exports.default = encode;

View File

@ -0,0 +1,39 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UPCE = exports.UPC = exports.EAN2 = exports.EAN5 = exports.EAN8 = exports.EAN13 = undefined;
var _EAN = require('./EAN13.js');
var _EAN2 = _interopRequireDefault(_EAN);
var _EAN3 = require('./EAN8.js');
var _EAN4 = _interopRequireDefault(_EAN3);
var _EAN5 = require('./EAN5.js');
var _EAN6 = _interopRequireDefault(_EAN5);
var _EAN7 = require('./EAN2.js');
var _EAN8 = _interopRequireDefault(_EAN7);
var _UPC = require('./UPC.js');
var _UPC2 = _interopRequireDefault(_UPC);
var _UPCE = require('./UPCE.js');
var _UPCE2 = _interopRequireDefault(_UPCE);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.EAN13 = _EAN2.default;
exports.EAN8 = _EAN4.default;
exports.EAN5 = _EAN6.default;
exports.EAN2 = _EAN8.default;
exports.UPC = _UPC2.default;
exports.UPCE = _UPCE2.default;

View File

@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GenericBarcode = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Barcode2 = require("../Barcode.js");
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var GenericBarcode = function (_Barcode) {
_inherits(GenericBarcode, _Barcode);
function GenericBarcode(data, options) {
_classCallCheck(this, GenericBarcode);
return _possibleConstructorReturn(this, (GenericBarcode.__proto__ || Object.getPrototypeOf(GenericBarcode)).call(this, data, options)); // Sets this.data and this.text
}
// Return the corresponding binary numbers for the data provided
_createClass(GenericBarcode, [{
key: "encode",
value: function encode() {
return {
data: "10101010101010101010101010101010101010101",
text: this.text
};
}
// Resturn true/false if the string provided is valid for this encoder
}, {
key: "valid",
value: function valid() {
return true;
}
}]);
return GenericBarcode;
}(_Barcode3.default);
exports.GenericBarcode = GenericBarcode;

View File

@ -0,0 +1,69 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants = require('./constants');
var _Barcode2 = require('../Barcode');
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ITF = function (_Barcode) {
_inherits(ITF, _Barcode);
function ITF() {
_classCallCheck(this, ITF);
return _possibleConstructorReturn(this, (ITF.__proto__ || Object.getPrototypeOf(ITF)).apply(this, arguments));
}
_createClass(ITF, [{
key: 'valid',
value: function valid() {
return this.data.search(/^([0-9]{2})+$/) !== -1;
}
}, {
key: 'encode',
value: function encode() {
var _this2 = this;
// Calculate all the digit pairs
var encoded = this.data.match(/.{2}/g).map(function (pair) {
return _this2.encodePair(pair);
}).join('');
return {
data: _constants.START_BIN + encoded + _constants.END_BIN,
text: this.text
};
}
// Calculate the data of a number pair
}, {
key: 'encodePair',
value: function encodePair(pair) {
var second = _constants.BINARIES[pair[1]];
return _constants.BINARIES[pair[0]].split('').map(function (first, idx) {
return (first === '1' ? '111' : '1') + (second[idx] === '1' ? '000' : '0');
}).join('');
}
}]);
return ITF;
}(_Barcode3.default);
exports.default = ITF;

View File

@ -0,0 +1,55 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _ITF2 = require('./ITF');
var _ITF3 = _interopRequireDefault(_ITF2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// Calculate the checksum digit
var checksum = function checksum(data) {
var res = data.substr(0, 13).split('').map(function (num) {
return parseInt(num, 10);
}).reduce(function (sum, n, idx) {
return sum + n * (3 - idx % 2 * 2);
}, 0);
return Math.ceil(res / 10) * 10 - res;
};
var ITF14 = function (_ITF) {
_inherits(ITF14, _ITF);
function ITF14(data, options) {
_classCallCheck(this, ITF14);
// Add checksum if it does not exist
if (data.search(/^[0-9]{13}$/) !== -1) {
data += checksum(data);
}
return _possibleConstructorReturn(this, (ITF14.__proto__ || Object.getPrototypeOf(ITF14)).call(this, data, options));
}
_createClass(ITF14, [{
key: 'valid',
value: function valid() {
return this.data.search(/^[0-9]{14}$/) !== -1 && +this.data[13] === checksum(this.data);
}
}]);
return ITF14;
}(_ITF3.default);
exports.default = ITF14;

View File

@ -0,0 +1,9 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var START_BIN = exports.START_BIN = '1010';
var END_BIN = exports.END_BIN = '11101';
var BINARIES = exports.BINARIES = ['00110', '10001', '01001', '11000', '00101', '10100', '01100', '00011', '10010', '01010'];

View File

@ -0,0 +1,19 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ITF14 = exports.ITF = undefined;
var _ITF = require('./ITF');
var _ITF2 = _interopRequireDefault(_ITF);
var _ITF3 = require('./ITF14');
var _ITF4 = _interopRequireDefault(_ITF3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.ITF = _ITF2.default;
exports.ITF14 = _ITF4.default;

View File

@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Barcode2 = require("../Barcode.js");
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation
// https://en.wikipedia.org/wiki/MSI_Barcode#Character_set_and_binary_lookup
var MSI = function (_Barcode) {
_inherits(MSI, _Barcode);
function MSI(data, options) {
_classCallCheck(this, MSI);
return _possibleConstructorReturn(this, (MSI.__proto__ || Object.getPrototypeOf(MSI)).call(this, data, options));
}
_createClass(MSI, [{
key: "encode",
value: function encode() {
// Start bits
var ret = "110";
for (var i = 0; i < this.data.length; i++) {
// Convert the character to binary (always 4 binary digits)
var digit = parseInt(this.data[i]);
var bin = digit.toString(2);
bin = addZeroes(bin, 4 - bin.length);
// Add 100 for every zero and 110 for every 1
for (var b = 0; b < bin.length; b++) {
ret += bin[b] == "0" ? "100" : "110";
}
}
// End bits
ret += "1001";
return {
data: ret,
text: this.text
};
}
}, {
key: "valid",
value: function valid() {
return this.data.search(/^[0-9]+$/) !== -1;
}
}]);
return MSI;
}(_Barcode3.default);
function addZeroes(number, n) {
for (var i = 0; i < n; i++) {
number = "0" + number;
}
return number;
}
exports.default = MSI;

View File

@ -0,0 +1,33 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _MSI2 = require('./MSI.js');
var _MSI3 = _interopRequireDefault(_MSI2);
var _checksums = require('./checksums.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var MSI10 = function (_MSI) {
_inherits(MSI10, _MSI);
function MSI10(data, options) {
_classCallCheck(this, MSI10);
return _possibleConstructorReturn(this, (MSI10.__proto__ || Object.getPrototypeOf(MSI10)).call(this, data + (0, _checksums.mod10)(data), options));
}
return MSI10;
}(_MSI3.default);
exports.default = MSI10;

View File

@ -0,0 +1,35 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _MSI2 = require('./MSI.js');
var _MSI3 = _interopRequireDefault(_MSI2);
var _checksums = require('./checksums.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var MSI1010 = function (_MSI) {
_inherits(MSI1010, _MSI);
function MSI1010(data, options) {
_classCallCheck(this, MSI1010);
data += (0, _checksums.mod10)(data);
data += (0, _checksums.mod10)(data);
return _possibleConstructorReturn(this, (MSI1010.__proto__ || Object.getPrototypeOf(MSI1010)).call(this, data, options));
}
return MSI1010;
}(_MSI3.default);
exports.default = MSI1010;

View File

@ -0,0 +1,33 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _MSI2 = require('./MSI.js');
var _MSI3 = _interopRequireDefault(_MSI2);
var _checksums = require('./checksums.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var MSI11 = function (_MSI) {
_inherits(MSI11, _MSI);
function MSI11(data, options) {
_classCallCheck(this, MSI11);
return _possibleConstructorReturn(this, (MSI11.__proto__ || Object.getPrototypeOf(MSI11)).call(this, data + (0, _checksums.mod11)(data), options));
}
return MSI11;
}(_MSI3.default);
exports.default = MSI11;

View File

@ -0,0 +1,35 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _MSI2 = require('./MSI.js');
var _MSI3 = _interopRequireDefault(_MSI2);
var _checksums = require('./checksums.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var MSI1110 = function (_MSI) {
_inherits(MSI1110, _MSI);
function MSI1110(data, options) {
_classCallCheck(this, MSI1110);
data += (0, _checksums.mod11)(data);
data += (0, _checksums.mod10)(data);
return _possibleConstructorReturn(this, (MSI1110.__proto__ || Object.getPrototypeOf(MSI1110)).call(this, data, options));
}
return MSI1110;
}(_MSI3.default);
exports.default = MSI1110;

View File

@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mod10 = mod10;
exports.mod11 = mod11;
function mod10(number) {
var sum = 0;
for (var i = 0; i < number.length; i++) {
var n = parseInt(number[i]);
if ((i + number.length) % 2 === 0) {
sum += n;
} else {
sum += n * 2 % 10 + Math.floor(n * 2 / 10);
}
}
return (10 - sum % 10) % 10;
}
function mod11(number) {
var sum = 0;
var weights = [2, 3, 4, 5, 6, 7];
for (var i = 0; i < number.length; i++) {
var n = parseInt(number[number.length - 1 - i]);
sum += weights[i % weights.length] * n;
}
return (11 - sum % 11) % 11;
}

View File

@ -0,0 +1,34 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MSI1110 = exports.MSI1010 = exports.MSI11 = exports.MSI10 = exports.MSI = undefined;
var _MSI = require('./MSI.js');
var _MSI2 = _interopRequireDefault(_MSI);
var _MSI3 = require('./MSI10.js');
var _MSI4 = _interopRequireDefault(_MSI3);
var _MSI5 = require('./MSI11.js');
var _MSI6 = _interopRequireDefault(_MSI5);
var _MSI7 = require('./MSI1010.js');
var _MSI8 = _interopRequireDefault(_MSI7);
var _MSI9 = require('./MSI1110.js');
var _MSI10 = _interopRequireDefault(_MSI9);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.MSI = _MSI2.default;
exports.MSI10 = _MSI4.default;
exports.MSI11 = _MSI6.default;
exports.MSI1010 = _MSI8.default;
exports.MSI1110 = _MSI10.default;

View File

@ -0,0 +1,92 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.codabar = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Barcode2 = require("../Barcode.js");
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding specification:
// http://www.barcodeisland.com/codabar.phtml
var codabar = function (_Barcode) {
_inherits(codabar, _Barcode);
function codabar(data, options) {
_classCallCheck(this, codabar);
if (data.search(/^[0-9\-\$\:\.\+\/]+$/) === 0) {
data = "A" + data + "A";
}
var _this = _possibleConstructorReturn(this, (codabar.__proto__ || Object.getPrototypeOf(codabar)).call(this, data.toUpperCase(), options));
_this.text = _this.options.text || _this.text.replace(/[A-D]/g, '');
return _this;
}
_createClass(codabar, [{
key: "valid",
value: function valid() {
return this.data.search(/^[A-D][0-9\-\$\:\.\+\/]+[A-D]$/) !== -1;
}
}, {
key: "encode",
value: function encode() {
var result = [];
var encodings = this.getEncodings();
for (var i = 0; i < this.data.length; i++) {
result.push(encodings[this.data.charAt(i)]);
// for all characters except the last, append a narrow-space ("0")
if (i !== this.data.length - 1) {
result.push("0");
}
}
return {
text: this.text,
data: result.join('')
};
}
}, {
key: "getEncodings",
value: function getEncodings() {
return {
"0": "101010011",
"1": "101011001",
"2": "101001011",
"3": "110010101",
"4": "101101001",
"5": "110101001",
"6": "100101011",
"7": "100101101",
"8": "100110101",
"9": "110100101",
"-": "101001101",
"$": "101100101",
":": "1101011011",
"/": "1101101011",
".": "1101101101",
"+": "101100110011",
"A": "1011001001",
"B": "1001001011",
"C": "1010010011",
"D": "1010011001"
};
}
}]);
return codabar;
}(_Barcode3.default);
exports.codabar = codabar;

View File

@ -0,0 +1,34 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _CODE = require('./CODE39/');
var _CODE2 = require('./CODE128/');
var _EAN_UPC = require('./EAN_UPC/');
var _ITF = require('./ITF/');
var _MSI = require('./MSI/');
var _pharmacode = require('./pharmacode/');
var _codabar = require('./codabar');
var _GenericBarcode = require('./GenericBarcode/');
exports.default = {
CODE39: _CODE.CODE39,
CODE128: _CODE2.CODE128, CODE128A: _CODE2.CODE128A, CODE128B: _CODE2.CODE128B, CODE128C: _CODE2.CODE128C,
EAN13: _EAN_UPC.EAN13, EAN8: _EAN_UPC.EAN8, EAN5: _EAN_UPC.EAN5, EAN2: _EAN_UPC.EAN2,
UPC: _EAN_UPC.UPC, UPCE: _EAN_UPC.UPCE,
ITF14: _ITF.ITF14,
ITF: _ITF.ITF,
MSI: _MSI.MSI, MSI10: _MSI.MSI10, MSI11: _MSI.MSI11, MSI1010: _MSI.MSI1010, MSI1110: _MSI.MSI1110,
PHARMACODE: _pharmacode.pharmacode,
CODABAR: _codabar.codabar,
GENERICBARCODE: _GenericBarcode.GenericBarcode
};

View File

@ -0,0 +1,73 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pharmacode = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Barcode2 = require("../Barcode.js");
var _Barcode3 = _interopRequireDefault(_Barcode2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation
// http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf
var pharmacode = function (_Barcode) {
_inherits(pharmacode, _Barcode);
function pharmacode(data, options) {
_classCallCheck(this, pharmacode);
var _this = _possibleConstructorReturn(this, (pharmacode.__proto__ || Object.getPrototypeOf(pharmacode)).call(this, data, options));
_this.number = parseInt(data, 10);
return _this;
}
_createClass(pharmacode, [{
key: "encode",
value: function encode() {
var z = this.number;
var result = "";
// http://i.imgur.com/RMm4UDJ.png
// (source: http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf, page: 34)
while (!isNaN(z) && z != 0) {
if (z % 2 === 0) {
// Even
result = "11100" + result;
z = (z - 2) / 2;
} else {
// Odd
result = "100" + result;
z = (z - 1) / 2;
}
}
// Remove the two last zeroes
result = result.slice(0, -2);
return {
data: result,
text: this.text
};
}
}, {
key: "valid",
value: function valid() {
return this.number >= 3 && this.number <= 131070;
}
}]);
return pharmacode;
}(_Barcode3.default);
exports.pharmacode = pharmacode;

View File

@ -0,0 +1,201 @@
<template xlang="wxml" minapp="mpvue">
<view class="tki-barcode">
<!-- #ifndef MP-ALIPAY -->
<canvas class="tki-barcode-canvas" :canvas-id="cid" :style="{width:canvasWidth+'px',height:canvasHeight+'px'}" />
<!-- #endif -->
<!-- #ifdef MP-ALIPAY -->
<canvas v-if="val === '' || defaultOpations.text === val" :id="cid" :width="canvasWidth" :height="canvasHeight" class="tki-barcode-canvas" />
<!-- #endif -->
<image v-show="show" :src="result" :style="{width:canvasWidth+'px',height:canvasHeight+'px', maxWidth: '100%'}" />
</view>
</template>
<script>
// const barcode = require('./barcode.js');
import barCode from "./barcode.js"
const opations = {
// format: "CODE128",//使 code128\code39\ena13\ean8\upc\itf14\
width: 4,//
height: 120,//
displayValue: true,//
// text: "1234567890",//
textAlign: "center",//
textPosition: "bottom",//
textMargin: 0,//
fontSize: 24,//
fontColor: "#000000",//
lineColor: "#000000",//
background: "#FFFFFF",//
margin: 0,//
marginTop: undefined,//
marginBottom: undefined,//
marginLeft: undefined,//
marginRight: undefined,//
}
export default {
name: "tkiBarcode",
props: {
show: {
type: Boolean,
default: true
},
cid: {
type: String,
default: 'tki-barcode-canvas'
},
unit: {
type: String,
default: 'upx'
},
val: {
type: String,
default: ''
},
format: {
type: String,
default: 'CODE128'
},
opations: {
type: Object,
default: function () {
return {}
}
},
onval: {
type: Boolean,
default: false
},
loadMake: {
type: Boolean,
default: true
},
},
data() {
return {
result: '',
canvasWidth: 0,
canvasHeight: 0,
defaultOpations: Object.assign({}, opations)
}
},
onUnload: function () {
},
methods: {
_makeCode() {
let that = this
//
Object.assign(this.defaultOpations, this.opations)
if (that.unit == "upx") {
/* if (that.defaultOpations.width) {
that.defaultOpations.width = uni.upx2px(that.defaultOpations.width)
} */
if (that.defaultOpations.height) {
that.defaultOpations.height = uni.upx2px(that.defaultOpations.height)
}
if (that.defaultOpations.fontSize) {
that.defaultOpations.fontSize = uni.upx2px(that.defaultOpations.fontSize)
}
}
if (that._empty(that.defaultOpations.text)) {
that.defaultOpations.text = that.val
}
if (that._empty(that.defaultOpations.format)) {
that.defaultOpations.format = that.format
}
// console.log(JSON.stringify(that.defaultOpations))
this.$nextTick(() => {
setTimeout(() => {
new barCode(that, that.cid, that.defaultOpations,
function (res) { //
that.canvasWidth = res.width
that.canvasHeight = res.height
},
function (res) { //
//
that._result(res)
//
that.defaultOpations = opations
},
);
}, 100)
})
},
_clearCode() {
this._result('')
},
_saveCode() {
let that = this;
if (this.result != "") {
uni.saveImageToPhotosAlbum({
filePath: that.result,
success: function () {
uni.showToast({
title: '条形码保存成功',
icon: 'success',
duration: 2000
});
}
});
}
},
_result(res) {
this.result = res;
this.$emit('result', res)
},
_empty(v) {
let tp = typeof v,
rt = false;
if (tp == "number" && String(v) == "") {
rt = true
} else if (tp == "undefined") {
rt = true
} else if (tp == "object") {
if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) rt = true
} else if (tp == "string") {
if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") rt = true
} else if (tp == "function") {
rt = false
}
return rt
}
},
watch: {
val(n, o) {
this.defaultOpations.text = n
if (this.onval) {
if (n != o && !this._empty(n)) {
this._makeCode()
}
}
},
opations: {
handler(n,o){
if (this.onval) {
if (!this._empty(n)) {
this._makeCode()
}
}
},
deep: true
}
},
mounted () {
if (this.loadMake) {
if (!this._empty(this.val)) {
this._makeCode()
}
}
},
}
</script>
<style>
.tki-barcode {
position: relative;
}
.tki-barcode-canvas {
position: fixed!important;
top: -99999upx;
left: -99999upx;
z-index: -99999;
}
</style>

View File

@ -5,7 +5,8 @@
"^u--(.*)": "uview-plus/components/u-$1/u-$1.vue", "^u--(.*)": "uview-plus/components/u-$1/u-$1.vue",
"^up-(.*)": "uview-plus/components/u-$1/u-$1.vue", "^up-(.*)": "uview-plus/components/u-$1/u-$1.vue",
"^u-([^-].*)": "uview-plus/components/u-$1/u-$1.vue" "^u-([^-].*)": "uview-plus/components/u-$1/u-$1.vue"
} },
"^w-(.*)": "@uni-ui/code-ui/components/w-$1/index.vue"//
}, },
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages "pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages
{ {
@ -442,6 +443,16 @@
"navigationBarTextStyle": "white", "navigationBarTextStyle": "white",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
},
{
"path" : "pages/plant/plant",
"style" :
{
"navigationBarTitleText": "基地详情",
"navigationBarBackgroundColor": "#feb048",
"navigationBarTextStyle": "white",
"enablePullDownRefresh": false
}
} }

View File

@ -56,7 +56,7 @@
</view> </view>
<view class="land-info"> <view class="land-info" @click="navToPlant">
<view class="land-area"> <view class="land-area">
<view class="land-title">养殖基地规模</view> <view class="land-title">养殖基地规模</view>
<view class=""> <view class="">
@ -304,9 +304,9 @@
uni.scanCode({ uni.scanCode({
success: function(res) { success: function(res) {
// console.log('' + res.scanType); // console.log('' + res.scanType);
console.log('条码内容:' + res.result.split('=')); console.log('条码内容:' + res.result.split('d_')[1]);
uni.navigateTo({ uni.navigateTo({
url: '/pages/landDetail/results?id=' + res.result.split('=')[1] url: '/pages/landDetail/results?sn=' + res.result.split('d_')[1]
}) })
} }
}); });
@ -516,6 +516,14 @@
const u = (name) => { const u = (name) => {
return `/static/main/index/${name}.png` return `/static/main/index/${name}.png`
} }
const navToPlant = ()=>{
uni.navigateTo({
url: '/pages/plant/plant',
success: (res) => {
res.eventChannel.emit('setDatasItem', dataobj.value);
}
})
}
</script> </script>
<style lang="scss"> <style lang="scss">
page { page {

View File

@ -7,255 +7,190 @@
<view class="content-con-a" v-if="Object.keys(dataobj).length>0"> <view class="content-con-a" v-if="Object.keys(dataobj).length>0">
<view class="shop_detail"> <view class="shop_detail">
<view class="tit"> <view class="tit">
品类信息 动物信息
</view> </view>
<view class="shop_detail-botm"> <view class="shop_detail-botm">
<view class="detail"> <view class="detail">
<view class="detaila"> <view class="detaila">
商品名称 耳号
</view> </view>
<view class="detailb"> <view class="detailb">
{{dataobj.kind}} {{dataobj.sn}}
</view> </view>
</view> </view>
<view class="detail"> <view class="detail">
<view class="detaila"> <view class="detaila">
植日期
</view> </view>
<view class="detailb"> <view class="detailb">
{{dataobj.plant_date}} {{dataobj.brand}}
</view> </view>
</view> </view>
<view class="detail"> <view class="detail">
<view class="detaila"> <view class="detaila">
收获日期 性别
</view> </view>
<view class="detailb"> <view class="detailb">
{{dataobj.harvest_date}} {{dataobj.gender==1?'公':'母'}}
</view> </view>
</view> </view>
<view class="detail">
<view class="detaila">
生长期
</view>
<view class="detailb">
<!-- {{dataobj.plant_date}} -->
<!-- {{dataobj.actions[dataobj.actions.length-1].create_time.split(' ')[0]}} -->
{{ dataobj.group_day }}
</view>
</view>
<view class="detail">
<view class="detaila">
负责人
</view>
<view class="detailb">
<!-- {{dataobj.plant_date}} -->
<!-- {{dataobj.actions[dataobj.actions.length-1].create_time.split(' ')[0]}} -->
{{ dataobj.user}}
</view>
</view>
<view class="detail">
<view class="detaila">
生产地址
</view>
<view class="detailb">
{{dataobj.land_address}}
</view>
</view>
</view> </view>
</view> </view>
<view class="shop_action"> <view class="shop_action">
<view class="" v-for="(item,i) in dataobj.actions">
<view class="tit">
{{item.type_text}}
</view>
<view class="shop_action-detail" v-if="item.type!=3&&item.type!=5">
<view class="action-detail">
<view class="title">
{{item.type_text.slice(0, -2)}}<text class=""
v-if="item.type==2||item.type==4"></text>品种
</view>
<view class="detail">
{{item.detail.kind}}
</view>
</view>
<view class="action-detail" v-if="item.detail.breed">
<view class="title">
{{item.type_text.slice(0, -2)}}<text class=""
v-if="item.type==2||item.type==4"></text>品牌
</view>
<view class="detail">
{{item.detail.breed}}
</view>
</view>
<view class="action-detail">
<view class="title">
{{item.type_text.slice(0, -2)}}<text class=""
v-if="item.type==2||item.type==4"></text>用量
</view>
<view class="detail">
{{item.detail.dosage}}<text v-if='item.type==4'></text>
<text v-if='item.type!=4&&item.type!=5'></text>
</view>
</view>
<view class="action-detail">
<view class="title">
参与人
</view>
<view class="detail">
{{item.detail.user}}
</view>
</view>
<view class="action-detail-img">
<view class="title">
{{item.type_text.slice(0, -2)}}图片
</view>
<view class="detail-img" v-if="item.detail&&item.detail.pic&&item.detail.pic.length>0">
<!-- <image @click="perviewFn(item.detail.pic)" :src="item.detail.pic[0]" mode="aspectFit">
</image> -->
<u-swiper :list="item.detail.pic" @click="hdClick" indicator indicatorMode="dot"
circular></u-swiper>
</view>
</view>
</view>
<view class="shop_action-detail" v-if="item.type==3">
<view class="action-detail">
<view class="title">
灌溉方式
</view>
<view class="detail">
{{item.detail.type==1?"喷灌":item.detail.type==2?"滴灌":"沟灌"}}
</view>
</view>
<view class="action-detail">
<view class="title">
灌溉面积
</view>
<view class="detail">
{{item.detail.area}}
</view>
</view>
<view class="action-detail">
<view class="title">
参与人
</view>
<view class="detail">
{{item.detail.user}}
</view>
</view>
<view class="action-detail-img">
<view class="title">
灌溉图片
</view>
<view class="detail-img" v-if="item.detail&&item.detail.pic&&item.detail.pic.length>0">
<!-- <image @click="perviewFn(item.detail.pic)" :src="item.detail.pic[0]" mode="aspectFit">
</image> -->
<u-swiper :list="item.detail.pic" @click="hdClick" indicator indicatorMode="dot"
circular></u-swiper>
</view>
</view>
</view>
<view class="shop_action-detail" v-if="item.type==5">
<view class="action-detail">
<view class="title">
收获时间
</view>
<view class="detail">
{{dataobj.harvest_date}}
</view>
</view>
<view class="action-detail">
<view class="title">
参与人
</view>
<view class="detail">
{{item.detail.user}}
</view>
</view>
<view class="action-detail-img">
<view class="title">
收获图片
</view>
<view class="detail-img" v-if="item.detail&&item.detail.pic&&item.detail.pic.length>0">
<!-- <image @click="perviewFn(item.detail.pic)" :src="item.detail.pic[0]" mode="aspectFit">
</image> -->
<u-swiper :list="item.detail.pic" @click="hdClick" indicator indicatorMode="dot"
circular></u-swiper>
</view>
</view>
</view>
</view>
</view> </view>
</view> </view>
<view class="card-d" v-for="(item, index) in dataList" :key="index">
<u--form labelWidth='130' :model="item" ref="form" v-if="item.type==2">
<view class="c-title">驱虫信息</view>
<view class="c-box">
<u-form-item label="驱虫药名称" borderBottom>
<up-input readonly type="txt"
border="none" v-model="item.vermifuge_name"></up-input>
</u-form-item>
<u-form-item label="驱虫方式" borderBottom>
<up-input readonly
border="none" v-model="item.deworming_method"></up-input>
</u-form-item>
<u-form-item label="驱虫时间" borderBottom >
<up-input readonly
border="none" v-model="item.create_time"></up-input>
</u-form-item>
<swiper class="swiper" autoplay indicator-dots indicator-active-color="#ffb049" indicator-color="rgba(255,255,255,0.4)">
<swiper-item class="swiper-item" v-for="(t, index) in item.pic" :key="index">
<image class="img" :src="t"></image>
</swiper-item>
</swiper>
<u-form-item label="备注" borderBottom >
<view class="">
{{item.remark}}
</view>
</u-form-item>
</view>
</u--form>
<u--form labelWidth='130' :model="item" ref="form" v-if="item.type==3">
<view class="c-title">喂食信息</view>
<view class="c-box">
<u-form-item label="饲料种类" borderBottom>
<view style="font-weight: 600;">{{getFeedType(item.feed_type)}}</view>
</u-form-item>
<u-form-item label="饲料品牌" borderBottom>
<up-input readonly
border="none" v-model="item.feed_brand"></up-input>
</u-form-item>
<u-form-item label="饲料消耗量(kg)" borderBottom >
<up-input readonly type="number"
border="none" v-model="item.feed_consumption"></up-input>
</u-form-item>
<u-form-item label="喂食时间" borderBottom >
<up-input readonly
border="none" v-model="item.create_time"></up-input>
</u-form-item>
<swiper class="swiper" autoplay indicator-dots indicator-active-color="#ffb049" indicator-color="rgba(255,255,255,0.4)">
<swiper-item class="swiper-item" v-for="(t, index) in item.pic" :key="index">
<image class="img" :src="t"></image>
</swiper-item>
</swiper>
<u-form-item label="备注" borderBottom >
<view class="">
{{item.remark}}
</view>
</u-form-item>
</view>
</u--form>
</view>
</view> </view>
</template> </template>
<script setup> <script setup>
import {
suYuan
} from '@/api/api.js'
import { import {
ref, ref,
reactive reactive
} from "vue" } from "vue"
import {
feedingTypeLists
} from "@/api/dict.js"
import { import {
onLoad, onLoad,
onReady onReady
} from "@dcloudio/uni-app" } from "@dcloudio/uni-app"
import {
fenceHouseDetail,
animalInfoList,
operationLogIndex,
animalInfoDetail
} from "@/api/manage.js"
import {
suYuanData
} from "@/api/index.js"
const task_id = ref(''); const task_id = ref('');
const sn = ref('');
const dataobj = reactive({}) const dataobj = reactive({})
const daysDiff = ref(''); const daysDiff = ref('');
onLoad((options) => { onLoad((options) => {
task_id.value = options.id // sn.value = options.sn;
// if (options.task_id) { sn.value = 8;
// mode.value = "detail" getFenceHouseDetail();
// } getSuYuanData();
getlist1(options.id)
}) })
// //
const getlist1 = (id) => { const getFenceHouseDetail = () => {
suYuan({ animalInfoDetail({
plant_id: id id: sn.value,
}).then((res) => { }).then((res) => {
if (res.code == 1) {
if (res.code == 1) { res.data.pic = JSON.parse(res.data.pic||'[]');
Object.assign(dataobj, res.data); Object.assign(dataobj, res.data);
getday(res.data) }
} });
});
}; };
//
const feedType = ref([]);
const getday = (data) => { const initFeedingTypeLists = ()=>{
const start = new Date(data.plant_date); feedingTypeLists().then(res=>{
const end = new Date(data.actions[data.actions.length - 1].create_time.split(' ')[0]); feedType.value = res.data;
const diffTime = Math.abs(end - start); })
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); }
daysDiff.value = diffDays const getFeedType = (value)=>{
return feedType.value.find(item=>item.value==value)?.name||'';
} }
initFeedingTypeLists();
const where = ref({
animal_sn: '6655',
page_no: 1,
page_size: 10
})
const dataList = ref([]);
//
const getSuYuanData = ()=>{
suYuanData(where.value).then(res=>{
if(res.data.lists.length<=0) return ;
res.data.lists = res.data.lists.map(item=>{
item = {
...item,
...item.detail,
};
if(item.pic) item.pic = JSON.parse(item.pic);
return item;
})
dataList.value = [...dataList.value, ...res.data.lists];
})
}
// //
const perviewFn = (url) => { const perviewFn = (url) => {
console.log(url) console.log(url)
uni.previewImage({ uni.previewImage({
urls: url urls: url
}) })
} }
</script> </script>
@ -278,6 +213,25 @@
.content-con-a { .content-con-a {
padding: 0 32rpx; padding: 0 32rpx;
margin-top: 30rpx; margin-top: 30rpx;
.tit {
position: relative;
padding-left: 20rpx;
font-weight: bold;
margin-bottom: 20rpx;
}
.tit::before {
content: "";
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 0;
width: 3px;
/* 左边框的宽度 */
height: 30rpx;
background-color: #FFB049;
}
.shop_detail { .shop_detail {
.shop_detail-top { .shop_detail-top {
@ -366,22 +320,65 @@
} }
} }
.tit {
position: relative;
padding-left: 20rpx; .card-d {
font-weight: bold; background-color: #fffcf5;
margin-bottom: 20rpx;
} .c-title {
font-weight: bold;
display: flex;
align-items: center;
padding: 30rpx;
padding-bottom: 15rpx;
&:before {
content: '';
display: inline-block;
height: 0.8rem;
width: 6rpx;
margin-top: 0.2rem;
margin-right: 10rpx;
background-color: #feb048;
border-radius: 6rpx;
}
}
.c-box {
background-color: #fff;
padding: 20rpx;
margin: 28rpx;
margin-top: 0;
border-radius: 14rpx;
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1);
}
.c-box-p {
padding: 20rpx;
}
.btn {
margin: 20rpx auto;
width: 694rpx;
height: 80rpx;
border-radius: 80rpx;
background-color: #feb048;
color: #fff;
}
}
.swiper{
width: 654rpx;
height: 400rpx;
margin: 20rpx 0;
border-radius: 14rpx;
overflow: hidden;
.img{
width: 100%;
height: 100%;
}
}
.tit::before { :deep(.u-form-item__body){
content: ""; padding: 5rpx 0 !important;
position: absolute; }
top: 50%;
transform: translateY(-50%);
left: 0;
width: 3px;
/* 左边框的宽度 */
height: 30rpx;
background-color: #FFB049;
}
</style> </style>

783
pages/plant/plant.vue Normal file
View File

@ -0,0 +1,783 @@
<template>
<view class="content">
<view class="card">
<up-form labelWidth='130' :model="data.formData" ref="form1">
<view class="c-title">养殖基地信息</view>
<view class="c-box">
<up-form-item label="养殖基地名称" prop="farm_name" borderBottom required>
<up-input input-align="right" placeholder="请输入养殖基地名称" border="none"
v-model="data.formData.farm_name" :readonly="readonly"></up-input>
</up-form-item>
<!-- <up-form-item label="养殖基地类型" prop="farm_type" borderBottom required>
<up-input input-align="right" placeholder="请输入养殖基地类型" border="none"
v-model="data.formData.farm_type"></up-input>
</up-form-item> -->
<up-form-item label="养殖基地类型" prop="farm_type" borderBottom required @click="isshowFarm">
<up-input input-align="right" placeholder="请选择养殖基地类型" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="farm_type_name" readonly
style="pointer-events: none;"></up-input>
</up-form-item>
<!-- <up-form-item label="养殖种类" prop="breed_type" borderBottom required>
<up-input input-align="right" placeholder="请输入养殖种类" border="none"
v-model="data.formData.breed_type"></up-input>
</up-form-item> -->
<up-form-item label="养殖种类" prop="farm_type" borderBottom required @click="isshowBreed">
<up-input input-align="right" placeholder="请选择养殖种类" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="breed_type_name" readonly
style="pointer-events: none;"></up-input>
</up-form-item>
<up-form-item label="养殖基地规模(亩)" prop="form_scale" borderBottom required>
<up-input input-align="right" placeholder="请输入养殖基地规模" type="number" border="none"
v-model="data.formData.form_scale" :readonly="readonly"></up-input>
</up-form-item>
<up-form-item label="负责人" prop="master" borderBottom required>
<up-input input-align="right" placeholder="请输入负责人姓名" border="none"
v-model="data.formData.master" :readonly="readonly"></up-input>
</up-form-item>
<up-form-item label="负责人电话" prop="master_contact" borderBottom required>
<up-input input-align="right" placeholder="请输入负责人电话" type="number" border="none"
v-model="data.formData.master_contact" :readonly="readonly"></up-input>
</up-form-item>
</view>
<view class="c-title">地址信息</view>
<view class="c-box">
<up-form-item label="所在省份" prop="province" borderBottom required @click="isshow">
<up-input input-align="right" placeholder="请选择所在省份" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="province_name" readonly
style="pointer-events: none;"></up-input>
</up-form-item>
<up-form-item label="所在城市" prop="city" borderBottom required @click="isshow1">
<up-input input-align="right" placeholder="请选择所在城市" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="city_name" readonly
style="pointer-events: none;"></up-input>
</up-form-item>
<up-form-item label="所在区县" prop="area" borderBottom required @click="isshow2">
<up-input input-align="right" placeholder="请选择所在区县" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="area_name" readonly
style="pointer-events: none;"></up-input>
</up-form-item>
<up-form-item label="所在镇街" prop="formData.street" borderBottom required @click="isshow3">
<up-input input-align="right" placeholder="请选择所在镇街" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="street_name"></up-input>
</up-form-item>
<up-form-item label="所在乡村" prop="formData.village" borderBottom required @click="isshow4">
<up-input input-align="right" placeholder="请选择所在乡村" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="village_name"></up-input>
</up-form-item>
<up-form-item label="所在小队" prop="formData.bridge" borderBottom required @click="isshow5">
<up-input input-align="right" placeholder="请选择所在小队" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="bridge_name"></up-input>
</up-form-item>
<up-form-item label="养殖基地详细地址" prop="address" style="position: relative;" borderBottom required>
<up-input input-align="right" placeholder="请输入养殖基地详细地址" suffixIcon="map"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="data.formData.address">
</up-input>
<view style="position: absolute;right: 0;width: 50rpx; height: 100%; " @click="location">
</view>
</up-form-item>
</view>
<view class="card-li">
<view class="c-title">养殖基地图片</view>
<view class="c-box c-box-p">
<view class="code-img1">
<view class="" v-if="pic.length>0"
style="display: flex;flex-direction: row;flex-wrap: wrap;margin-bottom: 30rpx;">
<view class="" v-for="(item,i) in pic" style="margin-right: 30rpx;">
<view class="">
<u-icon v-if="!readonly" name="close" size="15" style="margin-left:120.85rpx;"
@click="delimg(i)"></u-icon>
<u-image :src="item" width="150.85rpx" height="150.85rpx"></u-image>
</view>
</view>
</view>
</view>
<view class="code-img" v-if="!readonly">
<view class="" @click="updateImgFn">
<view class="carime-icon">
<u-image src="/static/img/DJSC.png" width="91.12rpx" height="91.12rpx"></u-image>
<view class="">
点击上传图片
</view>
</view>
</view>
</view>
</view>
</view>
</up-form>
<u-action-sheet :show="show" keyName="name" closeOnClickOverlay :actions="columns" title="请选择"
@close="show = false" @select="leavaType">
</u-action-sheet>
<u-action-sheet :show="show1" keyName="name" :actions="columns1" title="请选择" @close="show1 = false"
@select="leavaType1">
</u-action-sheet>
<u-action-sheet :show="show2" keyName="name" :actions="columns2" title="请选择" @close="show2 = false"
@select="leavaType2">
</u-action-sheet>
<u-action-sheet :show="show3" keyName="name" :actions="columns3" title="请选择" @close="show3 = false"
@select="leavaType3">
</u-action-sheet>
<u-action-sheet :show="show4" keyName="name" :actions="columns4" title="请选择" @close="show4 = false"
@select="leavaType4">
</u-action-sheet>
<u-action-sheet :show="show5" keyName="name" :actions="columns5" title="请选择" @close="show5 = false"
@select="leavaType5">
</u-action-sheet>
<u-action-sheet :show="showFarm" keyName="name" :actions="farm_tpye_list" title="请选择" @close="showFarm = false"
@select="selectFarmType">
</u-action-sheet>
<u-action-sheet :show="showBreed" keyName="name" :actions="breed_tpye_list" title="请选择" @close="showBreed = false"
@select="selectBreedType">
</u-action-sheet>
<u-button class="btn" @click="submit" v-if="!readonly">提交</u-button>
</view>
</view>
</template>
<script setup>
import {
ref,
reactive,
onMounted,
unref,
computed,
getCurrentInstance,
watch
} from 'vue';
import {
onLoad,
onReady
} from '@dcloudio/uni-app';
import {
Uploads
} from "@/api/upload.js"
import {
province,
city,
county,
towns,
villages,
groups
} from '@/api/api.js';
import {
farmAdd
} from '@/api/index.js';
import {
breedTypeLists,
farmTypeLists
} from '@/api/dict.js';
const form1 = ref(null);
const data = reactive({
formData: {
farm_name: '',
farm_type: '',
breed_type: '',
form_scale: '',
master: '',
master_contact: '',
province: '',
city: '',
area: '',
street: '',
village: '',
bridge: '',
address: '',
lat: "",
lon: "",
master_name: '',
image: []
},
rules: {
farm_name: [{
type: 'string',
required: true,
message: '请填写养殖基地名称',
trigger: ['blur', 'change']
}],
farm_type: [{
type: 'string',
required: true,
message: '请填写养殖基地类型',
trigger: ['blur', 'change']
}],
breed_type: [{
type: 'string',
required: true,
message: '请填写养殖基地种类',
trigger: ['blur', 'change']
}],
form_scale: [{
type: 'string',
required: true,
message: '请填写养殖基地规模',
trigger: ['blur', 'change']
}],
province: [{
type: 'string',
required: true,
message: '请请选择所在省份',
trigger: 'change'
}],
city: [{
type: 'string',
required: true,
message: '请选择所在城市',
trigger: 'change'
}],
area: [{
type: 'string',
required: true,
message: '请选择所在区县',
trigger: 'change'
}],
street: {
type: 'string',
required: true,
message: '请选择所在镇街',
trigger: ['blur', 'change']
},
village: {
type: 'string',
required: true,
message: '请选择所在乡村',
trigger: ['blur', 'change']
},
bridge: {
type: 'string',
required: true,
message: '请选择小队',
trigger: ['blur', 'change']
},
address: [{
type: 'string',
required: true,
message: '请输入养殖基地详细地址',
trigger: ['blur', 'change']
}],
master: [{
type: 'string',
required: true,
message: '请输入养殖基地负责人姓名',
trigger: ['blur', 'change']
}],
master_contact: [{
required: true,
message: '请输入手机号',
trigger: ['change', 'blur'],
},
{
validator: (rule, value, callback) => {
// truefalse
// uni.$u.test.mobile()truefalse
return uni.$u.test.mobile(value);
},
message: '手机号码不正确',
// blurchange
trigger: ['change', 'blur'],
}
],
}
});
const pic = reactive([]);
const province_name = ref(null)
const city_name = ref(null)
const area_name = ref(null)
const street_name = ref(null)
const village_name = ref(null)
const bridge_name = ref(null)
const farm_type_name = ref(null)
const breed_type_name = ref(null)
const show = ref(false)
const show1 = ref(false)
const show2 = ref(false)
const show3 = ref(false)
const show4 = ref(false)
const show5 = ref(false)
const showFarm = ref(false)
const showBreed = ref(false)
const columns = reactive([])
const columns1 = reactive([])
const columns2 = reactive([])
const columns3 = reactive([])
const columns4 = reactive([])
const columns5 = reactive([])
const farm_tpye_list = reactive([])
const breed_tpye_list = reactive([])
const provincen = () => {
province().then((res) => {
columns.splice(0, columns.length, ...res.data.map((step, index) => {
return {
name: step.province_name,
id: step.province_code,
};
}));
if(data.formData.province){
let obj = columns.find(item=>item.id==data.formData.province);
if(!obj) return ;
province_name.value = obj?.name||'';
cityn(obj.id);
}
});
}
const cityn = (id) => {
city({
province_code: id
}).then((res) => {
columns1.splice(0, columns1.length, ...res.data.map((step, index) => {
return {
name: step.city_name,
id: step.city_code,
};
}));
if(data.formData.city){
let obj = columns1.find(item=>item.id==data.formData.city);
if(!obj) return ;
city_name.value = obj?.name||'';
countyn(obj.id);
}
});
}
const countyn = (id) => {
county({
city_code: id
}).then((res) => {
columns2.splice(0, columns2.length, ...res.data.map((step, index) => {
return {
name: step.county_name,
id: step.county_code,
};
}));
if(data.formData.area){
let obj = columns2.find(item=>item.id==data.formData.area);
if(!obj) return ;
area_name.value = obj?.name||'';
townsn(obj.id);
}
});
}
const townsn = (id) => {
towns({
county_code: id
}).then((res) => {
columns3.splice(0, columns.length, ...res.data.map((step, index) => {
return {
name: step.town_name,
id: step.town_code,
};
}));
if(data.formData.street){
let obj = columns3.find(item=>item.id==data.formData.street);
if(!obj) return ;
street_name.value = obj?.name||'';
villagesn(obj.id);
}
});
}
const villagesn = (id) => {
villages({
town_code: id
}).then((res) => {
columns4.splice(0, columns.length, ...res.data.map((step, index) => {
return {
name: step.village_name,
id: step.village_code,
};
}));
if(data.formData.village){
let obj = columns4.find(item=>item.id==data.formData.village);
if(!obj) return ;
village_name.value = obj?.name||'';
groupsn();
}
});
}
const groupsn = () => {
groups().then((res) => {
columns5.splice(0, columns.length, ...res.data.map((step, index) => {
return {
name: step.group_name,
id: step.group_code,
};
}));
if(data.formData.bridge){
let obj = columns5.find(item=>item.id==data.formData.bridge);
if(!obj) return ;
bridge_name.value = obj?.name||'';
}
});
}
const farmTypeListsn = (id) => {
farmTypeLists().then((res) => {
farm_tpye_list.splice(0, farm_tpye_list.length, ...res.data.map((step, index) => {
return {
name: step.name,
value: step.value,
id: step.id
};
}));
if(data.formData.farm_type) {
let obj = farm_tpye_list.find(item=>item.value==data.formData.farm_type);
farm_type_name.value = obj?.name||'';
}
});
}
const selectFarmType = (e)=>{
farm_type_name.value = e.name;
data.formData.farm_type = e.value;
}
const breedTypeListsn = (id) => {
breedTypeLists().then((res) => {
breed_tpye_list.splice(0, breed_tpye_list.length, ...res.data.map((step, index) => {
return {
name: step.name,
value: step.value,
id: step.id
};
}));
if(data.formData.breed_type) {
let obj = breed_tpye_list.find(item=>item.value==data.formData.breed_type);
breed_type_name.value = obj?.name||'';
}
});
}
const selectBreedType = (e)=>{
breed_type_name.value = e.name;
data.formData.breed_type = e.value;
}
//
const delimg = (i) => {
pic.splice(i, 1);
}
//
const updateImgFn = async () => {
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
Uploads(res.tempFilePaths[0], 'img').then(res => {
// console.log(res)
if (res.code == 1) {
pic.push(res.data.url)
uni.$u.toast('上传成功')
}
}).catch(err => {
//console.log('err', err);
// uni.$u.toast('')
})
},
fail: function(err) {
//console.log('choose');
uni.$u.toast('添加失败')
}
});
// let res = await Uploads()
// data.formData.pic = res.data.image
}
//
const isshow = () => {
if(readonly.value) return ;
show.value = true
}
const isshow1 = () => {
if(readonly.value) return ;
show1.value = true
}
const isshow2 = () => {
if(readonly.value) return ;
show2.value = true
}
const isshow3 = () => {
if(readonly.value) return ;
show3.value = true
}
const isshow4 = () => {
if(readonly.value) return ;
show4.value = true
}
const isshow5 = () => {
if(readonly.value) return ;
show5.value = true
}
const isshowFarm = () =>{
if(readonly.value) return ;
showFarm.value = true
}
const isshowBreed = () =>{
if(readonly.value) return ;
showBreed.value = true
}
const leavaType = (e) => {
console.log(e);
province_name.value = e.name
data.formData.province = e.id
cityn(e.id)
}
const leavaType1 = (e) => {
city_name.value = e.name
data.formData.city = e.id
countyn(e.id)
}
const leavaType2 = (e) => {
area_name.value = e.name
data.formData.area = e.id
townsn(e.id)
}
const leavaType3 = (e) => {
street_name.value = e.name
data.formData.street = e.id
villagesn(e.id)
}
const leavaType4 = (e) => {
village_name.value = e.name
data.formData.village = e.id
groupsn()
}
const leavaType5 = (e) => {
bridge_name.value = e.name
data.formData.bridge = e.id
}
const location = () => {
if(readonly.value) return;
uni.navigateTo({
url: '/pages/addPlant/select_address_n',
success: (res)=>{
uni.$once('setData', (e)=>{
e = JSON.parse(e||'{}');
console.log('选择地址', e);
data.formData.address = e.address;
data.formData.lat = e.lat;
data.formData.lon = e.lon;
})
}
})
}
onReady(() => {
form1.value.setRules(data.rules);
});
const submit = async () => {
try {
const valid = await form1.value.validate();
if (valid) {
// console.log('', data.formData);
if (pic.length == 0) {
uni.$u.toast('请上传图片')
return
}
data.formData.image = JSON.stringify(pic)
//
farmAdd(data.formData).then((res) => {
console.log(res)
if (res.code == 1) {
uni.navigateBack({
delta: 1
})
uni.$u.toast(res.msg)
// console.log('');
}
})
} else {
//
console.log('表单验证未通过');
}
} catch (error) {
//
console.error(error);
}
}
function convertNumbersToStrings(obj) {
for (let key in obj) {
if (typeof obj[key] === 'object') {
convertNumbersToStrings(obj[key]); //
} else if (typeof obj[key] === 'number') {
obj[key] = obj[key].toString(); //
}
}
}
const readonly = ref(false);
onLoad((options) => {
const eventChannel = getCurrentInstance().proxy.getOpenerEventChannel();
eventChannel.on('setDatasItem', (e)=> {
convertNumbersToStrings(e);
console.log(e);
readonly.value = true;
e.pic = JSON.parse(e.pic||'[]');
e.image = JSON.parse(e.image||'[]');
e.pic.length>0 ? Object.assign(pic, e.pic) : Object.assign(pic, e.image);
Object.assign(data.formData, e);
provincen();
farmTypeListsn();
breedTypeListsn();
})
})
</script>
<style lang="scss">
page {
background-color: #fffcf5;
}
.card {
background-color: #fffcf5;
padding: 0;
padding-bottom: 80rpx;
.c-title {
font-weight: bold;
display: flex;
align-items: center;
padding: 30rpx;
padding-bottom: 15rpx;
&:before {
content: '';
display: inline-block;
height: 0.8rem;
width: 6rpx;
margin-top: 0.2rem;
margin-right: 10rpx;
background-color: #feb048;
border-radius: 6rpx;
}
}
.c-box {
background-color: #fff;
padding-left: 30rpx;
padding-right: 20rpx;
padding-bottom: 20rpx;
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1);
}
.c-box-p {
padding: 20rpx;
}
.btn {
margin: 20rpx auto;
width: 694rpx;
height: 80rpx;
border-radius: 80rpx;
background-color: #ffb049;
color: #fff;
}
}
.card-li-tit {
position: relative;
span {
position: absolute;
left: -9px;
color: #f56c6c;
line-height: 20px;
font-size: 20px;
top: 3px;
}
margin-bottom: 20rpx;
}
.confim-btn {
margin: 0 auto;
width: 196.26rpx;
height: 66.59rpx;
/* border: ; */
border: #00A15E 1px solid;
color: #00A15E;
display: flex;
align-items: center;
justify-content: center;
border-radius: 42.06rpx 42.06rpx 42.06rpx 42.06rpx;
}
.up-img {
width: 341.71rpx
}
.today-btn {
width: 588.79rpx;
background-color: #00A15E;
color: white;
position: fixed;
bottom: 40rpx;
/* transform: ; */
left: 50%;
transform: translateX(-50%);
background: linear-gradient(to right, #00A15E, #4CC593);
/* margin: 0 auto; */
}
.code-img {
background-color: #F4F4F4;
height: 350.47rpx;
position: relative;
.carime-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
}
}
</style>

View File

@ -40,11 +40,7 @@
<view class="right" style="color: #7B7B7B;" @click="navFeed(item, index)"> <view class="right" style="color: #7B7B7B;" @click="navFeed(item, index)">
<view class="r-item"> <view class="r-item">
<view class="item-title">操作类型:</view> <view class="item-title">操作类型:</view>
<view v-if="index==0">{{'驱虫'}}</view> <view>{{item.type_text}}</view>
<view v-else-if="index==1">{{'消毒'}}</view>
<view v-else-if="index==2">{{'喂食'}}</view>
<view v-else-if="index==3">{{'疫苗'}}</view>
<view v-else-if="index==4">{{'喂水'}}</view>
</view> </view>
<view class="r-item"> <view class="r-item">
<view class="item-title">操作人员:</view> <view class="item-title">操作人员:</view>
@ -148,6 +144,11 @@
fence_house_id: typeID.value fence_house_id: typeID.value
}).then(res=>{ }).then(res=>{
res.data = res.data.map(item=>{ res.data = res.data.map(item=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
if(item) item.pic = JSON.parse(item.pic||'[]'); if(item) item.pic = JSON.parse(item.pic||'[]');
return item ?? null; return item ?? null;
}) })

View File

@ -38,7 +38,7 @@
<view class="left"> <view class="left">
<u--image @click="perviewFn(item.pic)" radius='10' :src="item.pic[0]" width="250rpx" <u--image @click="perviewFn(item.pic)" radius='10' :src="item.pic[0]" width="250rpx"
height="250rpx"></u--image> height="250rpx"></u--image>
<u---image class="qr-code" @click="perviewFn(item.qr_code)" src="/static/main/house/su_yuan_ma_btn.png" width="60rpx" height="60rpx"></u---image> <u---image class="qr-code" @click="showBarCode(item)" src="/static/main/house/su_yuan_ma_btn.png" width="60rpx" height="60rpx"></u---image>
</view> </view>
<u--image src="/static/main/house/xia_yi_ji_btn.png" class="next" width="38rpx" height="38rpx" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"></u--image> <u--image src="/static/main/house/xia_yi_ji_btn.png" class="next" width="38rpx" height="38rpx" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"></u--image>
<view class="right" style="color: #7B7B7B;" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"> <view class="right" style="color: #7B7B7B;" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)">
@ -95,11 +95,7 @@
<view class="right" style="color: #7B7B7B;" @click="navFeed(item, index)"> <view class="right" style="color: #7B7B7B;" @click="navFeed(item, index)">
<view class="r-item"> <view class="r-item">
<view class="item-title">操作类型:</view> <view class="item-title">操作类型:</view>
<view v-if="index==0">{{'驱虫'}}</view> <view>{{item.type_text}}</view>
<view v-else-if="index==1">{{'消毒'}}</view>
<view v-else-if="index==2">{{'喂食'}}</view>
<view v-else-if="index==3">{{'疫苗'}}</view>
<view v-else-if="index==4">{{'喂水'}}</view>
</view> </view>
<view class="r-item"> <view class="r-item">
<view class="item-title">操作人员:</view> <view class="item-title">操作人员:</view>
@ -132,7 +128,15 @@
<u-action-sheet :show="show" keyName="name" closeOnClickOverlay :actions="selectList" title="请选择" <u-action-sheet :show="show" keyName="name" closeOnClickOverlay :actions="selectList" title="请选择"
@close="show = false" @select="selectOne"> @close="show = false" @select="selectOne">
</u-action-sheet> </u-action-sheet>
<uni-popup ref="codeRef">
<view class="bar-code">
<view class="title">{{options.code.split('d_')[1]}}</view>
<w-qrcode ref="qrCode" :options="options"></w-qrcode>
<view @click="saveCode" class="btn">保存图片</view>
</view>
</uni-popup>
</view> </view>
</view> </view>
</template> </template>
@ -159,6 +163,39 @@
import { import {
animalTypeLists animalTypeLists
} from "@/api/dict.js" } from "@/api/dict.js"
const options = ref({
code: '',//
size: 460,// 460460rpx
})
const qrCode = ref('');
const saveCode = async ()=>{//
const img = await qrCode.value.GetCodeImg()
uni.saveImageToPhotosAlbum({
filePath: img.tempFilePath,
success(res) {
uni.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
});
},
fail(err) {
uni.showToast({
title: '保存失败',
icon: 'none',
duration: 2000
});
}
});
}
const codeRef = ref(null);
const showBarCode = (e)=>{
options.value.code = 'd_' + e.sn;
codeRef.value.open();
}
const dataList = reactive([]) const dataList = reactive([])
const dataobj = reactive({}) const dataobj = reactive({})
const typeID = ref('') const typeID = ref('')
@ -552,4 +589,26 @@
.actBtn { .actBtn {
background: linear-gradient(to right, #FEFFFF 0%, #E8FAF2 100%); background: linear-gradient(to right, #FEFFFF 0%, #E8FAF2 100%);
} }
.bar-code{
padding: 28rpx;
background-color: #fff;
border-radius: 24rpx;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
.title{
font-size: 32rpx;
font-weight: bold;
margin-bottom: 15rpx;
}
.btn{
background-color: rgba(#999, 0.2);
font-size: 24rpx;
padding: 5rpx 20rpx;
border-radius: 50rpx;
margin-top: 30rpx;
}
}
</style> </style>

View File

@ -8,7 +8,7 @@
<view class="left"> <view class="left">
<u--image @click="perviewFn(item.pic[0])" radius='10' :src="item.pic[0]" width="250rpx" <u--image @click="perviewFn(item.pic[0])" radius='10' :src="item.pic[0]" width="250rpx"
height="250rpx"></u--image> height="250rpx"></u--image>
<u---image class="qr-code" @click="perviewFn(item.qr_code)" src="/static/main/house/su_yuan_ma_btn.png" width="60rpx" height="60rpx"></u---image> <u---image class="qr-code" @click="showBarCode(item)" src="/static/main/house/su_yuan_ma_btn.png" width="60rpx" height="60rpx"></u---image>
</view> </view>
<u--image src="/static/main/house/xia_yi_ji_btn.png" class="next" width="38rpx" height="38rpx" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"></u--image> <u--image src="/static/main/house/xia_yi_ji_btn.png" class="next" width="38rpx" height="38rpx" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"></u--image>
<view class="right" style="color: #7B7B7B;" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"> <view class="right" style="color: #7B7B7B;" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)">
@ -48,7 +48,13 @@
</view> </view>
</view> </view>
<uni-popup ref="codeRef">
<view class="bar-code">
<view class="title">{{options.code.split('d_')[1]}}</view>
<w-qrcode ref="qrCode" :options="options"></w-qrcode>
<view @click="saveCode" class="btn">保存图片</view>
</view>
</uni-popup>
</view> </view>
</view> </view>
</template> </template>
@ -59,7 +65,6 @@
ref, ref,
reactive reactive
} from "vue" } from "vue"
import { import {
onLoad, onLoad,
onShow, onShow,
@ -82,6 +87,38 @@
url url
}) })
} }
const options = ref({
code: '',//
size: 460,// 460460rpx
})
const qrCode = ref('');
const saveCode = async ()=>{//
const img = await qrCode.value.GetCodeImg()
uni.saveImageToPhotosAlbum({
filePath: img.tempFilePath,
success(res) {
uni.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
});
},
fail(err) {
uni.showToast({
title: '保存失败',
icon: 'none',
duration: 2000
});
}
});
}
const codeRef = ref(null);
const showBarCode = (e)=>{
options.value.code = 'd_' + e.sn;
codeRef.value.open();
}
const getNowTimeFn = () => { const getNowTimeFn = () => {
const now = new Date(); const now = new Date();
@ -123,7 +160,7 @@
item.pic = JSON.parse(item.pic||'[]'); item.pic = JSON.parse(item.pic||'[]');
return item return item
}) })
dataList.splice(0, dataList.length, ...res.data.lists); dataList.splice(0, dataList, ...res.data.lists);
// console.log(dataList) // console.log(dataList)
} }
}); });
@ -336,4 +373,26 @@
.actBtn { .actBtn {
background: linear-gradient(to right, #FEFFFF 0%, #E8FAF2 100%); background: linear-gradient(to right, #FEFFFF 0%, #E8FAF2 100%);
} }
.bar-code{
padding: 28rpx;
background-color: #fff;
border-radius: 24rpx;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
.title{
font-size: 32rpx;
font-weight: bold;
margin-bottom: 15rpx;
}
.btn{
background-color: rgba(#999, 0.2);
font-size: 24rpx;
padding: 5rpx 20rpx;
border-radius: 50rpx;
margin-top: 30rpx;
}
}
</style> </style>

View File

@ -175,12 +175,12 @@
} }
const getList1 = ()=>{ const getList1 = ()=>{
waterLogLists(where.value).then(res=>{ waterLogLists(where.value).then(res=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
res.data.lists = res.data.lists.map(item=>{ res.data.lists = res.data.lists.map(item=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
item.pic = JSON.parse(item.pic||'[]'); item.pic = JSON.parse(item.pic||'[]');
return item; return item;
}) })
@ -189,12 +189,12 @@
} }
const getList2 = ()=>{ const getList2 = ()=>{
disinfectLogLists(where.value).then(res=>{ disinfectLogLists(where.value).then(res=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
res.data.lists = res.data.lists.map(item=>{ res.data.lists = res.data.lists.map(item=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
item.pic = JSON.parse(item.pic||'[]'); item.pic = JSON.parse(item.pic||'[]');
return item; return item;
}) })
@ -202,13 +202,13 @@
}) })
} }
const getList3 = ()=>{ const getList3 = ()=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
vaccinumLogLists(where.value).then(res=>{ vaccinumLogLists(where.value).then(res=>{
res.data.lists = res.data.lists.map(item=>{ res.data.lists = res.data.lists.map(item=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
item.pic = JSON.parse(item.pic||'[]'); item.pic = JSON.parse(item.pic||'[]');
return item; return item;
}) })
@ -217,12 +217,12 @@
} }
const getList4 = ()=>{ const getList4 = ()=>{
dewormingLogLists(where.value).then(res=>{ dewormingLogLists(where.value).then(res=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
res.data.lists = res.data.lists.map(item=>{ res.data.lists = res.data.lists.map(item=>{
item = {
...item.detail,
create_time: item.create_time,
type_text: item.type_text
};
item.pic = JSON.parse(item.pic||'[]'); item.pic = JSON.parse(item.pic||'[]');
return item; return item;
}) })

View File

@ -39,7 +39,7 @@
<view class="left"> <view class="left">
<u--image @click="perviewFn(item.pic[0])" radius='10' :src="item.pic[0]" width="250rpx" <u--image @click="perviewFn(item.pic[0])" radius='10' :src="item.pic[0]" width="250rpx"
height="250rpx"></u--image> height="250rpx"></u--image>
<u---image class="qr-code" @click="perviewFn(item.qr_code)" src="/static/main/house/su_yuan_ma_btn.png" width="60rpx" height="60rpx"></u---image> <u---image class="qr-code" @click="showBarCode(item)" src="/static/main/house/su_yuan_ma_btn.png" width="60rpx" height="60rpx"></u---image>
</view> </view>
<u--image src="/static/main/house/xia_yi_ji_btn.png" class="next" width="38rpx" height="38rpx" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"></u--image> <u--image src="/static/main/house/xia_yi_ji_btn.png" class="next" width="38rpx" height="38rpx" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"></u--image>
<view class="right" style="color: #7B7B7B;" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)"> <view class="right" style="color: #7B7B7B;" @click="navTo(`/pages/plantAdmin/breedDetail?id=${item.id}&house_id=${item.fence_house_id}`)">
@ -84,6 +84,14 @@
<u-action-sheet :show="show" keyName="name" closeOnClickOverlay :actions="selectList" title="请选择" <u-action-sheet :show="show" keyName="name" closeOnClickOverlay :actions="selectList" title="请选择"
@close="show = false" @select="selectOne"> @close="show = false" @select="selectOne">
</u-action-sheet> </u-action-sheet>
<uni-popup ref="codeRef">
<view class="bar-code">
<view class="title">{{options.code.split('d_')[1]}}</view>
<w-qrcode ref="qrCode" :options="options"></w-qrcode>
<view @click="saveCode" class="btn">保存图片</view>
</view>
</uni-popup>
</view> </view>
</template> </template>
@ -107,6 +115,38 @@
animalTypeLists animalTypeLists
} from "@/api/dict.js" } from "@/api/dict.js"
import Myindex from '@/components/return/index.vue'; import Myindex from '@/components/return/index.vue';
const options = ref({
code: '',//
size: 460,// 460460rpx
})
const qrCode = ref('');
const saveCode = async ()=>{//
const img = await qrCode.value.GetCodeImg()
uni.saveImageToPhotosAlbum({
filePath: img.tempFilePath,
success(res) {
uni.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
});
},
fail(err) {
uni.showToast({
title: '保存失败',
icon: 'none',
duration: 2000
});
}
});
}
const codeRef = ref(null);
const showBarCode = (e)=>{
options.value.code = 'd_' + e.sn;
codeRef.value.open();
}
const searchKey = ref(''); const searchKey = ref('');
const dataList = reactive([]) const dataList = reactive([])
@ -170,7 +210,7 @@
item.pic = JSON.parse(item.pic||'[]'); item.pic = JSON.parse(item.pic||'[]');
return item return item
}) })
dataList.splice(0, dataList.length, ...res.data.lists); dataList.splice(0, dataList, ...res.data.lists);
// console.log(dataList) // console.log(dataList)
} }
}); });
@ -397,4 +437,25 @@
} }
} }
.bar-code{
padding: 28rpx;
background-color: #fff;
border-radius: 24rpx;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
.title{
font-size: 32rpx;
font-weight: bold;
margin-bottom: 15rpx;
}
.btn{
background-color: rgba(#999, 0.2);
font-size: 24rpx;
padding: 5rpx 20rpx;
border-radius: 50rpx;
margin-top: 30rpx;
}
}
</style> </style>

View File

@ -0,0 +1,84 @@
<a href="https://meet-ui.com" target="_blank">
<h1 align="center">文档地址</h1>
</a>
<h1 align="center">https://meet-ui.com/#/</h1>
<p align="center">为了能够第一时间解决问题,为了不影响各位在项目中使用特此提供微信群交流</p>
<center>
<img src="https://img.lovewmf.com/2022-10-19.png"/>
<img src="https://img.lovewmf.com/2022-05-10.png"/>
</center>
# 温馨提示
如果使用cli创建的应用请在`vue.config.js`里面添加如下配置
```
module.exports = {
transpileDependencies: [
/[/\\]node_modules[/\\](.+?)?@uni-ui(.*)[/\\]code-plugs/,
/[/\\]node_modules[/\\](.+?)?@uni-ui(.*)[/\\]code-ui/
]
}
```
# 微信小程序特别说明
如果在弹窗里面使用,并且弹窗有动画 当弹窗显示的时候二维码会发生偏移或抖动
因为微信小程序的canvas在真机预览渲染的是原生组件并不是 h5的canavas 所以在开发工具里面没问题但是真机会有问题
解决方案:
1. 如果是使用uView组件的弹窗 请关闭动画
2. 如果是使用uni-popup组件 关闭动画无效 因为uni的弹窗动画关闭 其实是动画时长为0并且是包含在uni-transition详情请查看uni-popup代码
## 如果是使用uni_modules而非Npm
在`pages.json`里面配置如下
```js
"easycom": {
"^w-(.*)": "@/uni_modules/wmf-code/components/w-$1/w-$1.vue"//二维码条形码的配置 如果是uni_modules
},
"pages": [
//...
]
```
## 如果是使用npm而非uni_modules
在`pages.json`里面配置如下
```js
"easycom": {
"^w-(.*)": "@uni-ui/code-ui/components/w-$1/index.vue"//二维码条形码的配置 如果是npm方式使用
},
"pages": [
//...
]
```
## 条形码支持添加文字
<img src="https://img.lovewmf.com/WeChat315bd9b33217fabb1beaaa0d65421bee.png" style="margin-bottom: 10px;" />
<img src="https://img.lovewmf.com/WeChat9e319e9cd08e96369c09099f2863bff5.png" style="margin-bottom: 10px;" />
<center>
<figure>
<img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/07d4381cff624fc79ab28cdd1bf3cc6a~tplv-k3u1fbpfcp-watermark.image" style="margin-bottom: 10px;" />
<img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/71d7c20e8c91495c81d245ccfc83d7e7~tplv-k3u1fbpfcp-watermark.image" style="margin-bottom: 10px;" />
</figure>
</center>
#
<center>
<figure>
<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/bfe9eb88cea44007b2627bb640343dcc~tplv-k3u1fbpfcp-watermark.image" style="margin-bottom: 10px;" />
<img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/b625254802404a9b84bd699e67b03db4~tplv-k3u1fbpfcp-watermark.image" style="margin-bottom: 10px;" />
</figure>
</center>
#
<center>
<figure>
<img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f84328d92b104edbad4c34a8665b4c72~tplv-k3u1fbpfcp-watermark.image" style="margin-bottom: 10px;" />
<img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c1548ccd6c944bbe90ef288817077b8c~tplv-k3u1fbpfcp-watermark.image" style="margin-bottom: 10px;" />
</figure>
</center>

View File

@ -0,0 +1,108 @@
## 1.6.22022-10-24
* 修复已知问题
## 1.6.12022-10-19
* 支付宝小程序适配问题
* 修改文档
## 1.6.02022-07-27
* 修改条形码bug
## 1.5.92022-07-26
* 修复条形码保存图片部分黑底问题
## 1.5.82022-07-26
* 修复支付宝小程序图片保存缺失问题
## 1.5.72022-07-09
* 修复条形码保存缺失问题
## 1.5.62022-07-01
修改引入错误
## 1.5.52022-07-01
* 修复vue3无法通过ref获取保存图片方法
## 1.5.42022-06-01
* 条形码支持添加文字
## 1.5.32022-05-31
* 修复二维码有时候无法识别问题
* 建议使用npm方式
## 1.5.22022-05-31
修改条形码垂直方向生成图片 参数互换
## 1.5.12022-05-31
条形码增加垂直方向 默认水平方向
## 1.5.02022-05-30
修改uni_modules引入错误
## 1.4.92022-05-25
支持vue3
## 1.4.82021-12-06
* 百度小程序不支持canvas的arcTo方法 如果在百度小程序中不支持的全部默认值
* 小程序平台绘制文字不支持渐变 取color数组第一个
## 1.4.72021-12-05
* 修复已知问题
## 1.4.52021-12-05
* 修复已知问题
## 1.4.42021-11-30
* level默认值修改为2
## 1.4.32021-11-30
* 修复引用js_sdk引用路径
## 1.4.22021-11-29
* 修复设置画布大小时没有带单位px导致显示不全
## 1.4.12021-11-29
1. 修复在高分辨率屏幕上支付宝小程序显示模糊问题
2. 修复保存相册图片模糊问题
## 1.4.02021-11-23
1. 使用TS重构
2. 新增二维码文字绘制
3. 新增二维码padding
4. 新增二维码中间图片圆角 圆形
5. 新增长按事件
6. 二维码边框支持透明
7. 颜色最多支持10中颜色渐变
## 1.3.72021-11-08
修改引入
## 1.3.62021-11-02
修改引用路径
## 1.3.52021-10-19
canvas 增加 type="2d"
## 1.3.42021-10-14
1. 修改百度小程序修改参数无法重新渲染问题
2. 修改纯中文无法识别问题
## 1.3.32021-09-04
修改uni_module引用路径
## 1.3.22021-09-03
* 【重要】多个条形码或者二维码同时渲染
* 增加示例
## 1.3.12021-08-31
uni_modules支持组件方式
## 1.3.02021-08-31
支持纯文字以及文字数字 字母的混合
## 1.2.92021-08-30
新增二维码创建成功回调方法中返回生成的二维码图片
## 1.2.82021-08-20
支持vue3
## 1.2.72021-08-20
修改版本号
## 1.2.62021-06-28
1. 修改自定义组件时微信小程序无法显示二维码的问题
2. 统一二维码的大小单位为rpx
## 1.2.52021-06-25
二维码logo大小增加默认值30
## 1.2.42021-06-24
1. nvue 二维码支持渐变色
## 1.2.32021-06-23
1. 修改app不支持颜色渐变问题
2. 修改判断方式Object.prototype.toString.call()
## 1.2.22021-06-23
修改插件描述
## 1.2.12021-06-23
修改return 错误
## 1.1.22021-06-23
修改文档
## 1.1.12021-06-23
二维码支持渐变色
## 1.0.82021-06-22
兼容nvue
## 1.0.72021-06-09
1. 修改保存二维码图片的方法名以及传参方式
2. 修改微信小程序保存二维码时显示为黑色
3. 二维码增加参数
## 1.0.62021-06-04
修改 description说明
## 1.0.52021-06-04
修改文档展示名称
## 1.0.42021-06-04
修改符合uni_modules规范

View File

@ -0,0 +1,105 @@
// 判断arr是否为一个数组返回一个bool值
function isArray(arr) {
return Object.prototype.toString.call(arr) === '[object Array]';
}
// 深度克隆
function deepClone(obj) {
// 对常见的“非”值,直接返回原来值
if ([null, undefined, NaN, false].includes(obj)) return obj;
if (typeof obj !== "object" && typeof obj !== 'function') {
//原始类型直接返回
return obj;
}
var o = isArray(obj) ? [] : {};
for (let i in obj) {
if (obj.hasOwnProperty(i)) {
o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i];
}
}
return o;
}
function getUUid(len = 32, firstU = true, radix = null) {
let chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
let uuid = [];
radix = radix || chars.length;
if (len) {
// 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
for (let i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
let r;
// rfc4122标准要求返回的uuid中,某些位为固定的字符
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (let i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
// 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class
if (firstU) {
uuid.shift();
return 'u' + uuid.join('');
} else {
return uuid.join('');
}
}
function platform () {
let val = null;
// #ifdef VUE3
val = 'VUE3'
// #endif
// #ifdef APP-PLUS
val = 'APP-PLUS'
// #endif
// #ifdef APP-PLUS-NVUE || APP-NVUE
val = 'NVUE'
// #endif
// #ifdef H5
val = 'H5'
// #endif
// #ifdef MP-WEIXIN
val = 'MP-WEIXIN'
// #endif
// #ifdef MP-ALIPAY
val = 'MP-ALIPAY'
// #endif
// #ifdef MP-BAIDU
val = 'MP-BAIDU'
// #endif
// #ifdef MP-TOUTIAO
val = 'MP-TOUTIAO'
// #endif
// #ifdef MP-LARK
val = 'MP-LARK'
// #endif
// #ifdef MP-TOUTIAO
val = 'MP-QQ'
// #endif
// #ifdef MP-KUAISHOU
val = 'MP-KUAISHOU'
// #endif
// #ifdef MP-360
val = 'MP-360'
// #endif
// #ifdef QUICKAPP-WEBVIEW
val = 'QUICKAPP-WEBVIEW'
// #endif
// #ifdef QUICKAPP-WEBVIEW-UNION
val = 'QUICKAPP-WEBVIEW-UNION'
// #endif
// #ifdef QUICKAPP-WEBVIEW-HUAWEI
val = 'QUICKAPP-WEBVIEW-HUAWEI'
// #endif
return val;
}
export {
deepClone,
getUUid,
platform
};

View File

@ -0,0 +1,204 @@
<template>
<view @longtap.stop="longtap">
<canvas
:width="info.orient == 'vertical' ? info.destHeight : info.destWidth "
:height="info.orient == 'vertical' ? info.destWidth : info.destHeight"
:canvas-id="item.id"
:id="item.id"
:style="{width:info.orient == 'vertical' ? info.height : info.width,height: info.orient == 'vertical' ? info.width : info.height}"
v-for="item in info.listCode"
:key="item.id"
@error="handleError"></canvas>
</view>
</template>
<!-- #ifdef VUE3 -->
<script setup name="WBarcode">
import {
reactive,
watch,
onMounted,
nextTick,
getCurrentInstance,
defineExpose
} from 'vue';
import {
BarCode,
GetImg,
GetPixelRatio,
GetPx ,
} from '../../js_sdk/index.js';
import {
getUUid,
deepClone,
platform,
} from '../../common/helper.js'
//props
const props = defineProps({
options:{
type: Object,
required: true,
default: () =>{
return {}
}
}
});
const emits = defineEmits(['generate','press','error'])
const opt = props.options;
const that = getCurrentInstance();
const HSize = opt.text ? opt.text.size || 40 + opt.text.padding || 20 : 0;
let info = reactive({
id: getUUid(),
destWidth: GetPixelRatio() * GetPx(opt.width) + 'px',
destHeight: GetPixelRatio() * GetPx(opt.height + HSize) + 'px',
width: GetPx(opt.width) + 'px',
height: GetPx(opt.height + HSize) + 'px',
orient: opt.orient || 'horizontal',
listCode: []
})
onMounted(()=>{
SpecialTreatment(opt);
nextTick(()=>{
generateCode(opt)
})
});
watch(()=>props.options,(val)=>{
SpecialTreatment(val);
const HSize = val.text ? val.text.size || 40 + val.text.padding || 20 : 0;
info.destWidth= GetPixelRatio() * GetPx(val.width) + 'px',
info.destHeight= GetPixelRatio() * GetPx(val.height + HSize) + 'px',
info.orient = val.orient || 'horizontal',
info.width= GetPx(val.width) + 'px',
info.height= GetPx(val.height + HSize) + 'px',
setTimeout(()=>{
generateCode(val)
},100)
},{ deep: true })
const generateCode = (val)=> {
try{
const parameter = {...val,orient: info.orient,source: platform(),id: info.id,ctx: that};
BarCode(parameter,(res)=>{
emits('generate',res)
})
}catch(err){console.warn(err)}
}
const GetCodeImg = async ()=> {
try{
return await GetImg({id: info.id,source: platform(),width: opt.orient == 'vertical' ? opt.height : opt.width,height: opt.orient == 'vertical' ? opt.width : opt.height,ctx: that});
}catch(e){console.warn(e)}
};
const SpecialTreatment = (val) => {//canvas
let obj = deepClone(val);
obj.id = info.id;
info.listCode = [obj];
};
//
const longtap = (e)=>{
emits('press',e)
}
// canvas
const handleError = (e)=>{
emits('error',e.detail)
}
defineExpose({
GetCodeImg
})
</script>
<!-- #endif -->
<!-- #ifndef VUE3 -->
<script>
import { BarCode, GetImg,GetPixelRatio,GetPx } from '../../js_sdk/index.js';
import { getUUid, deepClone,platform } from '../../common/helper.js'
export default {
name: 'WBarcode',
props:{
options:{
type: Object,
required: true,
default: () =>{
return {
}
}
}
},
data () {
return {
info:{
destHeight: 0,
destWidth: 0,
width: 0,
height: 0,
listCode: [],
orient: 'horizontal'
},
id: getUUid()
}
},
mounted() {
const HSize = this.options.text ? ((this.options.text.size || 40) + ( this.options.text.padding || 20)) : 0;
this.info.height = GetPx(this.options.height + HSize) + 'px';
this.info.orient = this.options.orient || 'horizontal';
this.info.width = GetPx(this.options.width) + 'px';
this.info.destHeight = GetPx(this.options.height + HSize) * GetPixelRatio() + 'px';
this.info.destWidth = GetPx(this.options.width) * GetPixelRatio() + 'px';
this.SpecialTreatment(this.options)
this.$nextTick(()=>{
this.generateCode();
})
},
watch: {
options:{
deep: true,
handler (val) {
const HSize = val.text ? val.text.size || 40 + val.text.padding || 20 : 0;
this.info.height = GetPx(val.height + HSize) + 'px';
this.info.width = GetPx(val.width) + 'px';
this.info.destHeight = GetPx(val.height + HSize) * GetPixelRatio() + 'px';
this.info.destWidth = GetPx(val.width) * GetPixelRatio() + 'px';
this.info.orient = val.orient || 'horizontal'
this.SpecialTreatment(val)
setTimeout(()=>{// h5canvas
this.generateCode();
},100)
}
}
},
methods: {
longtap (e){
this.$emit('press',e)
},
handleError (e) {// error
this.$emit('error',e.detail)
},
SpecialTreatment (val) {//canvas
let obj = deepClone(val);
obj.id = this.id;
this.info.listCode = [obj]
},
generateCode () {
try{
const parameter = {...this.options,orient: this.info.orient,source: platform(),id: this.id,ctx: this};
console.log(parameter)
BarCode(parameter,(res)=>{
this.$emit('generate',res)
})
}catch(err){console.log(err)}
},
async GetCodeImg (){
try{
const pars = {
id: this.id,
source: platform(),
width: this.options.orient == 'vertical' ? this.info.height : this.info.width,
height: this.options.orient == 'vertical' ? this.info.width : this.info.height,
ctx: this,
}
return await GetImg(pars);
}catch(e){console.warn(e)}
}
}
}
</script>
<!-- #endif -->

View File

@ -0,0 +1,175 @@
<template>
<view @longtap.stop="longtap">
<canvas
:width="info.destWidth"
:height="info.destHeight"
:canvas-id="item.id"
:id="item.id"
:style="{width:info.width,height: info.height}"
v-for="item in info.listCode"
:key="item.id"
@error="handleError"></canvas>
</view>
</template>
<!-- #ifdef VUE3 -->
<script setup name="WQrcode">
import {reactive, watch,onMounted,nextTick,getCurrentInstance ,defineExpose } from 'vue';
import { QRCode, GetImg,GetPixelRatio,GetPx } from '@/uni_modules/wmf-code/js_sdk/index.js';
import { getUUid, deepClone,platform } from '../../common/helper.js'
//props
const props = defineProps({
options:{
type: Object,
required: true,
default: () =>{
return {}
}
}
});
const emits = defineEmits(['generate','press','error'])
const opt = props.options;
const that = getCurrentInstance();
const SIZE = GetPx(opt.size);
let info = reactive({
destHeight: SIZE * GetPixelRatio() + 'px',
destWidth: SIZE * GetPixelRatio() + 'px',
width: SIZE + 'px',
height: SIZE + 'px',
listCode:[],
id: getUUid(),
})
onMounted(()=>{
SpecialTreatment(opt);
nextTick(()=>{
generateCode(opt)
})
});
watch(()=>props.options,(val)=>{
SpecialTreatment(val);
const SIZE_Dynamic = GetPx(val.size);
info.destWidth= GetPixelRatio() * SIZE_Dynamic + 'px',
info.destHeight= GetPixelRatio() * SIZE_Dynamic + 'px',
info.width= SIZE_Dynamic + 'px',
info.height= SIZE_Dynamic + 'px',
setTimeout(()=>{
generateCode(val)
},50)
},{ deep: true })
const SpecialTreatment =(val)=> {//canvas
let obj = deepClone(val);
obj.id = info.id;
info.listCode = [obj]
};
const generateCode = (val)=>{
try{
const parameter = {...val,source: platform(),id: info.id,ctx: that};
QRCode(parameter,(res)=>{
emits('generate',res)
})
}catch(err){console.warn(err)}
};
const GetCodeImg = async ()=> {
try{
return await GetImg({id: info.id,source: platform(),width: opt.width,height: opt.height,ctx: that});
}catch(e){console.warn(e)}
};
//
const longtap = (e)=>{
emits('press',e)
}
// canvas
const handleError = (e)=>{
emits('error',e.detail)
}
defineExpose({
GetCodeImg
})
</script>
<!-- #endif -->
<!-- #ifndef VUE3 -->
<script>
import { QRCode, GetImg,GetPixelRatio,GetPx } from '@/uni_modules/wmf-code/js_sdk/index.js';
import { getUUid, deepClone,platform } from '../../common/helper.js'
export default {
name: 'WQrcode',
props:{
options:{
type: Object,
required: true,
default: () =>{
return {
}
}
}
},
data () {
return {
info:{
destHeight: 0,
destWidth: 0,
width: 0,
height: 0,
listCode:[],
},
destHeight: 0,
destWidth: 0,
width: 0,
height: 0,
listCode:[],
id: getUUid(),
}
},
mounted() {
this.info.height = this.info.width = GetPx(this.options.size) + 'px';
this.info.destHeight = this.info.destWidth = GetPx(this.options.size) * GetPixelRatio() + 'px';
this.SpecialTreatment(this.options)
this.$nextTick(()=>{
this.generateCode();
})
},
watch: {
options:{
deep: true,
handler (val) {
this.info.height = this.info.width = GetPx(val.size) + 'px';
this.info.destHeight = this.info.destWidth = GetPx(val.size) * GetPixelRatio() + 'px';
this.SpecialTreatment(val)
setTimeout(()=>{// h5canvas
this.generateCode();
},50)
}
}
},
methods: {
longtap (e){//
this.$emit('press',e);
},
handleError (e) {// error
this.$emit('error',e.detail)
},
SpecialTreatment (val) {//canvas
let obj = deepClone(val);
obj.id = this.id;
this.info.listCode = [obj]
},
//
generateCode () {
try{
const parameter = {...this.options,source: platform(),id: this.id,ctx: this};
QRCode(parameter,(res)=>{
this.$emit('generate',res)
})
}catch(err){console.warn(err)}
},
//
async GetCodeImg (){
try{
return await GetImg({id: this.id,source: platform(),width: this.options.size,height: this.options.size,ctx: this});
}catch(e){console.warn(e)}
}
}
}
</script>
<!-- #endif -->

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,77 @@
{
"id": "wmf-code",
"displayName": "二维码 条形码生成 支持链接 支持nvue 支持纯文字",
"version": "1.6.2",
"description": "二维码 条形码生成,支持渐变色边框 保存二维码图片,支持链接 ,支持nvue 支持纯文字",
"keywords": [
"二维码",
"条形码"
],
"repository": "https://github.com/lovewmf/uni-code",
"engines": {
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无 ",
"permissions": "无 "
},
"npmurl": "https://www.npmjs.com/package/@uni-ui/code-ui",
"type": "sdk-js"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "y"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "y",
"字节跳动": "y",
"QQ": "y"
},
"快应用": {
"华为": "y",
"联盟": "y"
},
"Vue": {
"vue2": "y",
"vue3": "y"
}
}
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long