15 Commits

11 geänderte Dateien mit 502 neuen und 408 gelöschten Zeilen
  1. +1
    -0
      .gitignore
  2. +1
    -1
      app.js
  3. +2
    -1
      app.json
  4. +16
    -3
      ext.json
  5. +108
    -40
      index/passCar.js
  6. +15
    -7
      index/passCar.wxml
  7. +4
    -1
      index/passCar.wxss
  8. +10
    -12
      pages/addPark/addPark.js
  9. +1
    -0
      pages/cardorder/index/index.js
  10. +21
    -10
      pages/scanPay/scanPay.js
  11. +323
    -333
      utils/barcode.js

+ 1
- 0
.gitignore Datei anzeigen

@@ -2,3 +2,4 @@
/ext.json
/project.config.json
/.vscode/**
.DS_Store

+ 1
- 1
app.js Datei anzeigen

@@ -154,7 +154,7 @@ App({
// 支持智慧停车, 用户名下有车
phone: null,
supportCar: false,
parkVendor: 1, // 1: ETCP, 2: TJD
parkVendor: 1, // 1-ETCP, 2-TJD停简单 3-Dahua大华, 4-ShangAn尚安, 5-BoLink泊链
// ETCP token
etcpToken: null,
carLogin: false,


+ 2
- 1
app.json Datei anzeigen

@@ -65,7 +65,8 @@
],
"navigateToMiniProgramAppIdList": [
"wx192b7d2e8dcbefd0",
"wxc07f9d67923d676d"
"wxc07f9d67923d676d",
"wxbd08b4baa10fcc1d"
],
"permission": {
"scope.userLocation": {


+ 16
- 3
ext.json Datei anzeigen

@@ -15,11 +15,24 @@
"orgUrl": "https://wx.qlogo.cn"
}
],
"car": {
"etcp": {
"etcpAppId": "wxc07f9d67923d676d",
"etcpCallbackUrl": "https://admin.malls.iformall.com/api/carCallback/etcpPaidCallback",
"payPath": "pages/pay/order-pay-open/main"
},
"tjd": {
"tjdAppId": "wx6945d1bda68d7993",
"payPath": ""
},
"bolink": {
"bolinkAppId": "wxbd08b4baa10fcc1d",
"payPath": "pages/park/park"
},
"version": "release"
},
"configUrl": "https://c.malls.iformall.com/C/api",
"etcpAppId": "wxc07f9d67923d676d",
"ifStoreApp": "0",
"etcpVersion": "release",
"etcpCallbackUrl": "https://admin.malls.iformall.com/api/carCallback/etcpPaidCallback",
"ifHaveWebSocket": "0",
"ifHaveCarModular": "1"
},


+ 108
- 40
index/passCar.js Datei anzeigen

@@ -136,7 +136,7 @@ Page({
}
// that.data.ticketList = that.data.ticketList.concat(res.data.list);
this.hideLoading();
wx.hideLoading();
})
.catch(err => {
setTimeout(function () {
@@ -206,22 +206,23 @@ Page({
bindfail: function (res) {
console.log(res)
},
gotoetcp: function (e) {
gotoCarMini: function (e) {
var that = this
// etcp parkVendor1
// 泊链停车 parkVendor5
if (e.target.dataset.flag == 'parkVendor1'){
wx.navigateToMiniProgram({
appId: this.data.etcpAppId,
extraData: this.data.extraData,
envVersion: 'release',
path: "pages/pay/order-pay-open/main",
appId: that.data.etcpAppId,
extraData: that.data.extraData,
envVersion: that.data.carMiniVersion,
path: that.data.payPath
})
} else if (e.target.dataset.flag == 'parkVendor5'){
wx.navigateToMiniProgram({
appId: 'wxbd08b4baa10fcc1d',
extraData: this.data.extraData,
envVersion: 'release',
path: "pages/park/park",
appId: that.data.bolinkAppId,
extraData: that.data.extraData,
envVersion: that.data.carMiniVersion,
path: that.data.payPath
})
}
},
@@ -246,9 +247,10 @@ Page({
}
var that = this;
that.setData({
etcpAppId: extConfig.attr.etcpAppId,
etcpVersion: extConfig.attr.etcpVersion,
etcpCallbackUrl: extConfig.attr.etcpCallbackUrl,
etcpAppId: extConfig.attr.car.etcp.etcpAppId,
carMiniVersion: extConfig.attr.car.version,
etcpCallbackUrl: extConfig.attr.car.etcp.etcpCallbackUrl,
payPath: extConfig.attr.car.etcp.payPath,
ifHaveCarModular: extConfig.attr.ifHaveCarModular
})
if (app.globalData.token) {
@@ -447,25 +449,33 @@ Page({
var that = this;
/**
* etcp
*/
var etcpData = {
*/
var postCouponData = {
etcpToken: app.globalData.etcpToken,
carNumber: that.data.listCardNum,
couponOrderId: quanid
};
/**
* 停简单
*/
var tjdData = {
carNumber: that.data.listCardNum
};
var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
if (app.globalData.parkVendor == 2) {
// 停简单
postCouponData = {
carNumber: that.data.listCardNum
}
}
if (app.globalData.parkVendor == 4){
// 尚安
postCouponData = {
carNumber: that.data.listCardNum,
couponOrderId: quanid
}
}
if (app.globalData.parkVendor == 5) {
// 泊链
postCouponData = {
carNumber: that.data.listCardNum,
orderId: that.data.bolinkOrderId,
couponOrderId: quanid
}
}
Http.post({
url: config.api.getCarCoupon,
data: postCouponData
@@ -618,10 +628,10 @@ Page({
etcpToken: app.globalData.etcpToken,
carNumber: carNum
};
var tjdData = {
var otherData = {
carNumber: carNum
};
var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
var postData = app.globalData.parkVendor == 1 ? etcpData : otherData;
Http.post({
url: config.api.bindCar,
data: postData
@@ -662,6 +672,38 @@ Page({
})
if (res.data){
app.globalData.parkVendor = res.data.vendorType;
if (app.globalData.parkVendor == 1) {
console.log("payPath: " + extConfig.attr.car.etcp.payPath)
// etcp
that.setData({
parkVendor: app.globalData.parkVendor,
etcpAppId: extConfig.attr.car.etcp.etcpAppId,
carMiniVersion: extConfig.attr.car.version,
etcpCallbackUrl: extConfig.attr.car.etcp.etcpCallbackUrl,
payPath: extConfig.attr.car.etcp.payPath
})
} else if (app.globalData.parkVendor == 2) {
// TJD
var vendorObj = JSON.parse(res.data.vendorParams)
that.setData({
parkVendor: app.globalData.parkVendor,
tjdAppId: extConfig.attr.car.tjd.tjdAppId,
carMiniVersion: extConfig.attr.car.version,
payPath: extConfig.attr.car.tjd.payPath
})
} else if (app.globalData.parkVendor == 5) {
// 泊链
var vendorObj = JSON.parse(res.data.vendorParams)
console.log("payPath: " + extConfig.attr.car.bolink.payPath)
that.setData({
parkVendor: app.globalData.parkVendor,
bolinkAppId: extConfig.attr.car.bolink.bolinkAppId,
carMiniVersion: extConfig.attr.car.version,
payPath: extConfig.attr.car.bolink.payPath,
bolinkComId: vendorObj.comid,
bolinkUnionId: vendorObj.union_id
})
}
}
})
.catch(err => {
@@ -751,7 +793,7 @@ Page({
})
.then(res => {
console.log(res)
if(app.globalData.parkVendor != 5){
if(app.globalData.parkVendor == 1){ // ETCP
var extraDataStr = {
params: {
token: app.globalData.etcpToken,
@@ -763,24 +805,50 @@ Page({
actionId: "1" //操作ID,1:小程序支付
}
}
} else if (app.globalData.parkVendor == 5) {
that.setData({
parkVendor: app.globalData.parkVendor,
extraData: extraDataStr,
stopFees: res.data,
timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
});
} else if (app.globalData.parkVendor == 2) { // TJD // TODO
var extraDataStr = {
params: {
union_id: '200389',
order_id: res.data.orderId,
park_id: "30536",
plate_number: carNumber,
money: res.data.remainingFee,
park_name: "",
}
prePayType: that.data.prePayType,
channel: res.data.channel,
isShowDetail: true,
orderId: res.data.orderId
}
that.setData({
parkVendor: app.globalData.parkVendor,
extraData: extraDataStr,
stopFees: {
orderId: res.data.orderId,
entranceTime: res.data.start_time,
remainingFee: res.data.money
},
timecha: res.data.duration
});
} else if (app.globalData.parkVendor == 5) { // BoLink
var extraDataStr = {
union_id: that.data.bolinkUnionId,
order_id: res.data.order_id,
park_id: that.data.bolinkComId,
plate_number: res.data.plate_number,
money: res.data.money,
park_name: res.data.park_name
}
that.setData({
parkVendor: app.globalData.parkVendor,
bolinkOrderId: res.data.order_id,
extraData: extraDataStr,
stopFees: {
orderId: res.data.order_id,
entranceTime: res.data.start_time,
remainingFee: res.data.money
},
timecha: res.data.duration
});
}
that.setData({
extraData: extraDataStr,
stopFees: res.data,
timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
});

that.setData({
scroll: true


+ 15
- 7
index/passCar.wxml Datei anzeigen

@@ -45,18 +45,26 @@
<text class="fl">待缴费用:</text>
<text class='fr' style='color:#ff4949;'>{{stopFees.remainingFee}}元</text>
</view>
<!-- 停车费用大于0 -->
<view class="buy-view" wx:if="{{stopFees.orderId&&stopFees.remainingFee>0&&app.globalData.parkVendor!=1}}">
<navigator bindfail="bindfail" path="pages/pay/order-pay-open/main" wx:if="{{canIUse}}" class='buy' target="miniProgram" open-type="navigate" app-id="{{etcpAppId}}" extra-data='{{extraData}}' version="{{etcpVersion}}">
<!-- 停车费用大于0 etcp -->
<view class="buy-view" wx:if="{{stopFees.orderId&&stopFees.remainingFee>0&&parkVendor==1}}">
<navigator bindfail="bindfail" path="{{payPath}}" wx:if="{{canIUse}}" class='buy' target="miniProgram" open-type="navigate" app-id="{{etcpAppId}}" extra-data='{{extraData}}' version="{{carMiniVersion}}">
立即支付
</navigator>
<view wx:if="{{!canIUse}}" class='buy' data-flag="parkVendor1" bindtap='gotoetcp'>立即支付</view>
<view wx:if="{{!canIUse}}" class='buy' data-flag="parkVendor1" bindtap='gotoCarMini'>立即支付</view>
</view>
<view class="buy-view" wx:if="{{stopFees.orderId&&stopFees.remainingFee>0&&app.globalData.parkVendor==5}}">
<navigator bindfail="bindfail" path="pages/park/park" wx:if="{{canIUse}}" class='buy' target="miniProgram" open-type="navigate" app-id="wxbd08b4baa10fcc1d" extra-data='{{extraData}}' version="{{etcpVersion}}">
<!-- 停车费用大于0 tjd -->
<view class="buy-view" wx:if="{{stopFees.orderId&&stopFees.remainingFee>0&&parkVendor==2}}">
<navigator bindfail="bindfail" path="{{payPath}}" wx:if="{{canIUse}}" class='buy' target="miniProgram" open-type="navigate" app-id="{{tjdAppId}}" extra-data='{{extraData}}' version="{{carMiniVersion}}">
立即支付
</navigator>
<view wx:if="{{!canIUse}}" class='buy' data-flag="parkVendor5" bindtap='gotoetcp'>立即支付</view>
<view wx:if="{{!canIUse}}" class='buy' data-flag="parkVendor1" bindtap='gotoCarMini'>立即支付</view>
</view>
<!-- 停车费用大于0 bolink -->
<view class="buy-view" wx:if="{{stopFees.orderId&&stopFees.remainingFee>0&&parkVendor==5}}">
<navigator bindfail="bindfail" path="{{payPath}}" wx:if="{{canIUse}}" class='buy' target="miniProgram" open-type="navigate" app-id="{{bolinkAppId}}" extra-data='{{extraData}}' version="{{carMiniVersion}}">
立即支付
</navigator>
<view wx:if="{{!canIUse}}" class='buy' data-flag="parkVendor5" bindtap='gotoCarMini'>立即支付</view>
</view>
<!-- 停车费用为0 -->
<view wx:if="{{stopFees.remainingFee==0}}" class='buy' bindtap='paySuccess'>立即支付</view>


+ 4
- 1
index/passCar.wxss Datei anzeigen

@@ -396,6 +396,9 @@ page {
position: relative;
height: 88rpx;
margin-top: 30rpx;
display: flex;
justify-content: center;
align-items: center;
}

.buy {
@@ -407,7 +410,7 @@ page {
font-size: 36rpx;
line-height: 88rpx;
border-radius: 60rpx;
position: relative;
position: absolute;
z-index: 100;
text-align: center;
}


+ 10
- 12
pages/addPark/addPark.js Datei anzeigen

@@ -60,22 +60,22 @@ Page({
},


onLoad: function (options) {
onLoad: function(options) {
let that = this;

if (Object.keys(options).length!=0){
if (Object.keys(options).length != 0) {
that.setData({
flags: options.flags
})
}
},
jumpTo: function () {
jumpTo: function() {
// 返回
wx.navigateBack({
url: '/index/passCar'
})
},
handleTap: function (e) {
handleTap: function(e) {
this.buttonStatus();
this.setData({
choose: e.target.dataset.cardata,
@@ -116,7 +116,7 @@ Page({

}
},
chooseNum: function (e) {
chooseNum: function(e) {
if (e.target.dataset.msg == 'I') {
return
}
@@ -340,7 +340,7 @@ Page({
this.buttonStatus();
},

submit: function () {
submit: function() {
if (this.data.title != "" && this.data.numFir != "" && this.data.numSco != "" && this.data.numThr != "" && this.data.numFor != "" && this.data.numFive != "" && this.data.numSix != "") {
var carNumber = ''
carNumber += this.data.title + this.data.numFir + this.data.numSco + this.data.numThr + this.data.numFor + this.data.numFive + this.data.numSix
@@ -351,12 +351,11 @@ Page({
prevPage.setData({
addCar: carNumber
})
if (this.data.flags =='managepalte'){
if (this.data.flags == 'managepalte') {
wx.navigateBack({
url: '/pages/managelicenseplate/managelicenseplate?addcar=' + carNumber,
})
}
else{
} else {
wx.navigateBack({
url: '/index/passCar?addcar=' + carNumber,
})
@@ -364,7 +363,7 @@ Page({
}
},

buttonStatus: function () {
buttonStatus: function() {
if (this.data.title != "" && this.data.numFir != "" && this.data.numSco != "" && this.data.numThr != "" && this.data.numFor != "" && this.data.numFive != "" && this.data.numSix != "") {
this.setData({
buttonStatus: true
@@ -375,5 +374,4 @@ Page({
});
}
}
})

})

+ 1
- 0
pages/cardorder/index/index.js Datei anzeigen

@@ -82,6 +82,7 @@ Page({
if (res.code == 200) {
let merChantDetail = JSON.stringify(res.data);
if (merChantDetail && e.currentTarget.dataset.cardid && e.currentTarget.dataset.remainingamount) {
merChantDetail = encodeURIComponent(merChantDetail)
wx.navigateTo({
url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${e.currentTarget.dataset.cardid}&remainingAmount=${e.currentTarget.dataset.remainingamount}`,
})


+ 21
- 10
pages/scanPay/scanPay.js Datei anzeigen

@@ -28,8 +28,9 @@ Page({
*/
onLoad: function(options) {
let that = this;
let merChant = decodeURIComponent(options.merChant)
that.setData({
merChant: JSON.parse(options.merChant),
merChant: JSON.parse(merChant),
cardid: options.cardid,
cardids: options.cardid,
remainingAmount: options.remainingAmount,
@@ -61,7 +62,7 @@ Page({
let that = this;
const startSoterAuthentication = () => {
wx.startSoterAuthentication({
requestAuthModes: ["fingerPrint"],
requestAuthModes: [AUTH_MODE],
challenge: 'test',
authContent: '请验证已有的指纹以继续',
success: (res) => {
@@ -79,6 +80,13 @@ Page({
remainingAmount: that.data.remainingAmounts
})
if(err.errCode==90008||err.errCode == 90009){
// 90009 指纹验证失败
// 90008 用户已取消
wx.showModal({
title: '提示',
showCancel: false,
content: '指纹验证后才能支付'
})
}else{
that.gotoPay();
}
@@ -98,20 +106,23 @@ Page({
},
fail: (err) => {
console.error(err)
that.gotoPay();
}
})
}
wx.checkIsSupportSoterAuthentication({
success: (res) => {
console.log(res)
if (res.supportMode == []) {
that.gotoPay();
} else if (res.supportMode == ['fingerPrint']) {
checkIsEnrolled();
} else if (res.supportMode == ['fingerPrint', 'facial']) {
checkIsEnrolled();
}else{
that.gotoPay();
var bfingprint = false
for (var i in res.supportMode) {
if (res.supportMode[i] == AUTH_MODE) {
bfingprint = true
}
}
if (bfingprint) {
checkIsEnrolled()
} else {
that.gotoPay()
}
},
fail: (err) => {


+ 323
- 333
utils/barcode.js Datei anzeigen

@@ -11,392 +11,382 @@ var SET_STOP = 106;


var REPLACE_CODES = {
CHAR_TILDE: CODE_FNC1 //~ corresponds to FNC1 in GS1-128 standard
CHAR_TILDE: CODE_FNC1 //~ corresponds to FNC1 in GS1-128 standard
}

var CODESET = {
ANY: 1,
AB: 2,
A: 3,
B: 4,
C: 5
ANY: 1,
AB: 2,
A: 3,
B: 4,
C: 5
};

function getBytes(str) {
var bytes = [];
for (var i = 0; i < str.length; i++) {
bytes.push(str.charCodeAt(i));
}
return bytes;
var bytes = [];
for (var i = 0; i < str.length; i++) {
bytes.push(str.charCodeAt(i));
}
return bytes;
}

exports.code128 = function (ctx, text, width, height) {
exports.code128 = function(ctx, text, width, height) {

width = parseInt(width);
width = parseInt(width);

height = parseInt(height);
height = parseInt(height);

var codes = stringToCode128(text);
var codes = stringToCode128(text);

var g = new Graphics(ctx, width, height);
var g = new Graphics(ctx, width, height);

var barWeight = g.area.width / ((codes.length - 3) * 11 + 35);
var barWeight = g.area.width / ((codes.length - 3) * 11 + 35);

var x = g.area.left;
var y = g.area.top;
for (var i = 0; i < codes.length; i++) {
var c = codes[i];
//two bars at a time: 1 black and 1 white
for (var bar = 0; bar < 8; bar += 2) {
var barW = PATTERNS[c][bar] * barWeight;
// var barH = height - y - this.border;
var barH = height - y;
var spcW = PATTERNS[c][bar + 1] * barWeight;
var x = g.area.left;
var y = g.area.top;
for (var i = 0; i < codes.length; i++) {
var c = codes[i];
//two bars at a time: 1 black and 1 white
for (var bar = 0; bar < 8; bar += 2) {
var barW = PATTERNS[c][bar] * barWeight;
// var barH = height - y - this.border;
var barH = height - y;
var spcW = PATTERNS[c][bar + 1] * barWeight;

//no need to draw if 0 width
if (barW > 0) {
g.fillFgRect(x, y, barW, barH);
}
//no need to draw if 0 width
if (barW > 0) {
g.fillFgRect(x, y, barW, barH);
}

x += barW + spcW;
}
x += barW + spcW;
}
}

ctx.draw();
ctx.draw();
}


function stringToCode128(text) {

var barc = {
currcs: CODESET.C
};

var bytes = getBytes(text);
//decide starting codeset
var index = bytes[0] == CHAR_TILDE ? 1 : 0;

var csa1 = bytes.length > 0 ? codeSetAllowedFor(bytes[index++]) : CODESET.AB;
var csa2 = bytes.length > 0 ? codeSetAllowedFor(bytes[index++]) : CODESET.AB;
barc.currcs = getBestStartSet(csa1, csa2);
barc.currcs = perhapsCodeC(bytes, barc.currcs);

//if no codeset changes this will end up with bytes.length+3
//start, checksum and stop
var codes = new Array();

switch (barc.currcs) {
case CODESET.A:
codes.push(SET_STARTA);
break;
case CODESET.B:
codes.push(SET_STARTB);
break;
default:
codes.push(SET_STARTC);
break;
var barc = {
currcs: CODESET.C
};

var bytes = getBytes(text);
//decide starting codeset
var index = bytes[0] == CHAR_TILDE ? 1 : 0;

var csa1 = bytes.length > 0 ? codeSetAllowedFor(bytes[index++]) : CODESET.AB;
var csa2 = bytes.length > 0 ? codeSetAllowedFor(bytes[index++]) : CODESET.AB;
barc.currcs = getBestStartSet(csa1, csa2);
barc.currcs = perhapsCodeC(bytes, barc.currcs);

//if no codeset changes this will end up with bytes.length+3
//start, checksum and stop
var codes = new Array();

switch (barc.currcs) {
case CODESET.A:
codes.push(SET_STARTA);
break;
case CODESET.B:
codes.push(SET_STARTB);
break;
default:
codes.push(SET_STARTC);
break;
}


for (var i = 0; i < bytes.length; i++) {
var b1 = bytes[i]; //get the first of a pair
//should we translate/replace
if (b1 in REPLACE_CODES) {
codes.push(REPLACE_CODES[b1]);
i++ //jump to next
b1 = bytes[i];
}


//get the next in the pair if possible
var b2 = bytes.length > (i + 1) ? bytes[i + 1] : -1;

codes = codes.concat(codesForChar(b1, b2, barc.currcs));
//code C takes 2 chars each time
if (barc.currcs == CODESET.C) i++;
}

//calculate checksum according to Code 128 standards
var checksum = codes[0];
for (var weight = 1; weight < codes.length; weight++) {
checksum += (weight * codes[weight]);
}
codes.push(checksum % 103);

codes.push(SET_STOP);

//encoding should now be complete
return codes;

function getBestStartSet(csa1, csa2) {
//tries to figure out the best codeset
//to start with to get the most compact code
var vote = 0;
vote += csa1 == CODESET.A ? 1 : 0;
vote += csa1 == CODESET.B ? -1 : 0;
vote += csa2 == CODESET.A ? 1 : 0;
vote += csa2 == CODESET.B ? -1 : 0;
//tie goes to B due to my own predudices
return vote > 0 ? CODESET.A : CODESET.B;
}

function perhapsCodeC(bytes, codeset) {
for (var i = 0; i < bytes.length; i++) {
var b1 = bytes[i]; //get the first of a pair
//should we translate/replace
if (b1 in REPLACE_CODES) {
codes.push(REPLACE_CODES[b1]);
i++ //jump to next
b1 = bytes[i];
}

//get the next in the pair if possible
var b2 = bytes.length > (i + 1) ? bytes[i + 1] : -1;

codes = codes.concat(codesForChar(b1, b2, barc.currcs));
//code C takes 2 chars each time
if (barc.currcs == CODESET.C) i++;
}

//calculate checksum according to Code 128 standards
var checksum = codes[0];
for (var weight = 1; weight < codes.length; weight++) {
checksum += (weight * codes[weight]);
}
codes.push(checksum % 103);

codes.push(SET_STOP);

//encoding should now be complete
return codes;

function getBestStartSet(csa1, csa2) {
//tries to figure out the best codeset
//to start with to get the most compact code
var vote = 0;
vote += csa1 == CODESET.A ? 1 : 0;
vote += csa1 == CODESET.B ? -1 : 0;
vote += csa2 == CODESET.A ? 1 : 0;
vote += csa2 == CODESET.B ? -1 : 0;
//tie goes to B due to my own predudices
return vote > 0 ? CODESET.A : CODESET.B;
}

function perhapsCodeC(bytes, codeset) {
for (var i = 0; i < bytes.length; i++) {
var b = bytes[i]
if ((b < 48 || b > 57) && b != CHAR_TILDE)
return codeset;
}
return CODESET.C;
var b = bytes[i]
if ((b < 48 || b > 57) && b != CHAR_TILDE)
return codeset;
}

//chr1 is current byte
//chr2 is the next byte to process. looks ahead.
function codesForChar(chr1, chr2, currcs) {
var result = [];
var shifter = -1;

if (charCompatible(chr1, currcs)) {
if (currcs == CODESET.C) {
if (chr2 == -1) {
shifter = SET_CODEB;
currcs = CODESET.B;
}
else if ((chr2 != -1) && !charCompatible(chr2, currcs)) {
//need to check ahead as well
if (charCompatible(chr2, CODESET.A)) {
shifter = SET_CODEA;
currcs = CODESET.A;
}
else {
shifter = SET_CODEB;
currcs = CODESET.B;
}
}
}
}
else {
//if there is a next char AND that next char is also not compatible
if ((chr2 != -1) && !charCompatible(chr2, currcs)) {
//need to switch code sets
switch (currcs) {
case CODESET.A:
shifter = SET_CODEB;
currcs = CODESET.B;
break;
case CODESET.B:
shifter = SET_CODEA;
currcs = CODESET.A;
break;
}
}
else {
//no need to shift code sets, a temporary SHIFT will suffice
shifter = SET_SHIFT;
}
return CODESET.C;
}

//chr1 is current byte
//chr2 is the next byte to process. looks ahead.
function codesForChar(chr1, chr2, currcs) {
var result = [];
var shifter = -1;

if (charCompatible(chr1, currcs)) {
if (currcs == CODESET.C) {
if (chr2 == -1) {
shifter = SET_CODEB;
currcs = CODESET.B;
} else if ((chr2 != -1) && !charCompatible(chr2, currcs)) {
//need to check ahead as well
if (charCompatible(chr2, CODESET.A)) {
shifter = SET_CODEA;
currcs = CODESET.A;
} else {
shifter = SET_CODEB;
currcs = CODESET.B;
}
}
//ok some type of shift is nessecary
if (shifter != -1) {
result.push(shifter);
result.push(codeValue(chr2));
}
else {
if (currcs == CODESET.C) {
//include next as well
result.push(codeValue(chr1, chr2));
}
else {
result.push(codeValue(chr1));
}
}
} else {
//if there is a next char AND that next char is also not compatible
if ((chr2 != -1) && !charCompatible(chr2, currcs)) {
//need to switch code sets
switch (currcs) {
case CODESET.A:
shifter = SET_CODEB;
currcs = CODESET.B;
break;
case CODESET.B:
shifter = SET_CODEA;
currcs = CODESET.A;
break;
}
barc.currcs = currcs;
} else {
//no need to shift code sets, a temporary SHIFT will suffice
shifter = SET_SHIFT;
}
}

return result;
//ok some type of shift is nessecary
if (shifter != -1) {
result.push(shifter);
result.push(codeValue(chr2));
} else {
if (currcs == CODESET.C) {
//include next as well
result.push(codeValue(chr1, chr2));
} else {
result.push(codeValue(chr1));
}
}
barc.currcs = currcs;

return result;
}
}

//reduce the ascii code to fit into the Code128 char table
function codeValue(chr1, chr2) {
if (typeof chr2 == "undefined") {
return chr1 >= 32 ? chr1 - 32 : chr1 + 64;
}
else {
return parseInt(String.fromCharCode(chr1) + String.fromCharCode(chr2));
}
if (typeof chr2 == "undefined") {
return chr1 >= 32 ? chr1 - 32 : chr1 + 64;
} else {
return parseInt(String.fromCharCode(chr1) + String.fromCharCode(chr2));
}
}

function charCompatible(chr, codeset) {
var csa = codeSetAllowedFor(chr);
if (csa == CODESET.ANY) return true;
//if we need to change from current
if (csa == CODESET.AB) return true;
if (csa == CODESET.A && codeset == CODESET.A) return true;
if (csa == CODESET.B && codeset == CODESET.B) return true;
return false;
var csa = codeSetAllowedFor(chr);
if (csa == CODESET.ANY) return true;
//if we need to change from current
if (csa == CODESET.AB) return true;
if (csa == CODESET.A && codeset == CODESET.A) return true;
if (csa == CODESET.B && codeset == CODESET.B) return true;
return false;
}

function codeSetAllowedFor(chr) {
if (chr >= 48 && chr <= 57) {
//0-9
return CODESET.ANY;
}
else if (chr >= 32 && chr <= 95) {
//0-9 A-Z
return CODESET.AB;
}
else {
//if non printable
return chr < 32 ? CODESET.A : CODESET.B;
}
if (chr >= 48 && chr <= 57) {
//0-9
return CODESET.ANY;
} else if (chr >= 32 && chr <= 95) {
//0-9 A-Z
return CODESET.AB;
} else {
//if non printable
return chr < 32 ? CODESET.A : CODESET.B;
}
}

var Graphics = function(ctx, width, height) {

this.width = width;
this.height = height;
this.quiet = Math.round(this.width / 40);
this.border_size = 0;
this.padding_width = 0;
this.area = {
width : width - this.padding_width * 2 - this.quiet * 2,
height: height - this.border_size * 2,
top : this.border_size - 4,
left : this.padding_width + this.quiet
};
this.ctx = ctx;
this.fg = "#000000";
this.bg = "#ffffff";
// fill background
this.fillBgRect(0,0, width, height);
// fill center to create border
this.fillBgRect(0, this.border_size, width, height - this.border_size * 2);
this.width = width;
this.height = height;
this.quiet = Math.round(this.width / 40);
this.border_size = 0;
this.padding_width = 0;
this.area = {
width: width - this.padding_width * 2 - this.quiet * 2,
height: height - this.border_size * 2,
top: this.border_size - 4,
left: this.padding_width + this.quiet
};
this.ctx = ctx;
this.fg = "#000000";
this.bg = "#ffffff";
// fill background
this.fillBgRect(0, 0, width, height);
// fill center to create border
this.fillBgRect(0, this.border_size, width, height - this.border_size * 2);
}

//use native color
Graphics.prototype._fillRect = function(x, y, width, height, color) {
this.ctx.setFillStyle(color)
this.ctx.fillRect(x, y, width, height)
this.ctx.setFillStyle(color)
this.ctx.fillRect(x, y, width, height)
}

Graphics.prototype.fillFgRect = function(x,y, width, height) {
this._fillRect(x, y, width, height, this.fg);
Graphics.prototype.fillFgRect = function(x, y, width, height) {
this._fillRect(x, y, width, height, this.fg);
}

Graphics.prototype.fillBgRect = function(x,y, width, height) {
this._fillRect(x, y, width, height, this.bg);
Graphics.prototype.fillBgRect = function(x, y, width, height) {
this._fillRect(x, y, width, height, this.bg);
}

var PATTERNS = [
[2, 1, 2, 2, 2, 2, 0, 0], // 0
[2, 2, 2, 1, 2, 2, 0, 0], // 1
[2, 2, 2, 2, 2, 1, 0, 0], // 2
[1, 2, 1, 2, 2, 3, 0, 0], // 3
[1, 2, 1, 3, 2, 2, 0, 0], // 4
[1, 3, 1, 2, 2, 2, 0, 0], // 5
[1, 2, 2, 2, 1, 3, 0, 0], // 6
[1, 2, 2, 3, 1, 2, 0, 0], // 7
[1, 3, 2, 2, 1, 2, 0, 0], // 8
[2, 2, 1, 2, 1, 3, 0, 0], // 9
[2, 2, 1, 3, 1, 2, 0, 0], // 10
[2, 3, 1, 2, 1, 2, 0, 0], // 11
[1, 1, 2, 2, 3, 2, 0, 0], // 12
[1, 2, 2, 1, 3, 2, 0, 0], // 13
[1, 2, 2, 2, 3, 1, 0, 0], // 14
[1, 1, 3, 2, 2, 2, 0, 0], // 15
[1, 2, 3, 1, 2, 2, 0, 0], // 16
[1, 2, 3, 2, 2, 1, 0, 0], // 17
[2, 2, 3, 2, 1, 1, 0, 0], // 18
[2, 2, 1, 1, 3, 2, 0, 0], // 19
[2, 2, 1, 2, 3, 1, 0, 0], // 20
[2, 1, 3, 2, 1, 2, 0, 0], // 21
[2, 2, 3, 1, 1, 2, 0, 0], // 22
[3, 1, 2, 1, 3, 1, 0, 0], // 23
[3, 1, 1, 2, 2, 2, 0, 0], // 24
[3, 2, 1, 1, 2, 2, 0, 0], // 25
[3, 2, 1, 2, 2, 1, 0, 0], // 26
[3, 1, 2, 2, 1, 2, 0, 0], // 27
[3, 2, 2, 1, 1, 2, 0, 0], // 28
[3, 2, 2, 2, 1, 1, 0, 0], // 29
[2, 1, 2, 1, 2, 3, 0, 0], // 30
[2, 1, 2, 3, 2, 1, 0, 0], // 31
[2, 3, 2, 1, 2, 1, 0, 0], // 32
[1, 1, 1, 3, 2, 3, 0, 0], // 33
[1, 3, 1, 1, 2, 3, 0, 0], // 34
[1, 3, 1, 3, 2, 1, 0, 0], // 35
[1, 1, 2, 3, 1, 3, 0, 0], // 36
[1, 3, 2, 1, 1, 3, 0, 0], // 37
[1, 3, 2, 3, 1, 1, 0, 0], // 38
[2, 1, 1, 3, 1, 3, 0, 0], // 39
[2, 3, 1, 1, 1, 3, 0, 0], // 40
[2, 3, 1, 3, 1, 1, 0, 0], // 41
[1, 1, 2, 1, 3, 3, 0, 0], // 42
[1, 1, 2, 3, 3, 1, 0, 0], // 43
[1, 3, 2, 1, 3, 1, 0, 0], // 44
[1, 1, 3, 1, 2, 3, 0, 0], // 45
[1, 1, 3, 3, 2, 1, 0, 0], // 46
[1, 3, 3, 1, 2, 1, 0, 0], // 47
[3, 1, 3, 1, 2, 1, 0, 0], // 48
[2, 1, 1, 3, 3, 1, 0, 0], // 49
[2, 3, 1, 1, 3, 1, 0, 0], // 50
[2, 1, 3, 1, 1, 3, 0, 0], // 51
[2, 1, 3, 3, 1, 1, 0, 0], // 52
[2, 1, 3, 1, 3, 1, 0, 0], // 53
[3, 1, 1, 1, 2, 3, 0, 0], // 54
[3, 1, 1, 3, 2, 1, 0, 0], // 55
[3, 3, 1, 1, 2, 1, 0, 0], // 56
[3, 1, 2, 1, 1, 3, 0, 0], // 57
[3, 1, 2, 3, 1, 1, 0, 0], // 58
[3, 3, 2, 1, 1, 1, 0, 0], // 59
[3, 1, 4, 1, 1, 1, 0, 0], // 60
[2, 2, 1, 4, 1, 1, 0, 0], // 61
[4, 3, 1, 1, 1, 1, 0, 0], // 62
[1, 1, 1, 2, 2, 4, 0, 0], // 63
[1, 1, 1, 4, 2, 2, 0, 0], // 64
[1, 2, 1, 1, 2, 4, 0, 0], // 65
[1, 2, 1, 4, 2, 1, 0, 0], // 66
[1, 4, 1, 1, 2, 2, 0, 0], // 67
[1, 4, 1, 2, 2, 1, 0, 0], // 68
[1, 1, 2, 2, 1, 4, 0, 0], // 69
[1, 1, 2, 4, 1, 2, 0, 0], // 70
[1, 2, 2, 1, 1, 4, 0, 0], // 71
[1, 2, 2, 4, 1, 1, 0, 0], // 72
[1, 4, 2, 1, 1, 2, 0, 0], // 73
[1, 4, 2, 2, 1, 1, 0, 0], // 74
[2, 4, 1, 2, 1, 1, 0, 0], // 75
[2, 2, 1, 1, 1, 4, 0, 0], // 76
[4, 1, 3, 1, 1, 1, 0, 0], // 77
[2, 4, 1, 1, 1, 2, 0, 0], // 78
[1, 3, 4, 1, 1, 1, 0, 0], // 79
[1, 1, 1, 2, 4, 2, 0, 0], // 80
[1, 2, 1, 1, 4, 2, 0, 0], // 81
[1, 2, 1, 2, 4, 1, 0, 0], // 82
[1, 1, 4, 2, 1, 2, 0, 0], // 83
[1, 2, 4, 1, 1, 2, 0, 0], // 84
[1, 2, 4, 2, 1, 1, 0, 0], // 85
[4, 1, 1, 2, 1, 2, 0, 0], // 86
[4, 2, 1, 1, 1, 2, 0, 0], // 87
[4, 2, 1, 2, 1, 1, 0, 0], // 88
[2, 1, 2, 1, 4, 1, 0, 0], // 89
[2, 1, 4, 1, 2, 1, 0, 0], // 90
[4, 1, 2, 1, 2, 1, 0, 0], // 91
[1, 1, 1, 1, 4, 3, 0, 0], // 92
[1, 1, 1, 3, 4, 1, 0, 0], // 93
[1, 3, 1, 1, 4, 1, 0, 0], // 94
[1, 1, 4, 1, 1, 3, 0, 0], // 95
[1, 1, 4, 3, 1, 1, 0, 0], // 96
[4, 1, 1, 1, 1, 3, 0, 0], // 97
[4, 1, 1, 3, 1, 1, 0, 0], // 98
[1, 1, 3, 1, 4, 1, 0, 0], // 99
[1, 1, 4, 1, 3, 1, 0, 0], // 100
[3, 1, 1, 1, 4, 1, 0, 0], // 101
[4, 1, 1, 1, 3, 1, 0, 0], // 102
[2, 1, 1, 4, 1, 2, 0, 0], // 103
[2, 1, 1, 2, 1, 4, 0, 0], // 104
[2, 1, 1, 2, 3, 2, 0, 0], // 105
[2, 3, 3, 1, 1, 1, 2, 0] // 106
]

[2, 1, 2, 2, 2, 2, 0, 0], // 0
[2, 2, 2, 1, 2, 2, 0, 0], // 1
[2, 2, 2, 2, 2, 1, 0, 0], // 2
[1, 2, 1, 2, 2, 3, 0, 0], // 3
[1, 2, 1, 3, 2, 2, 0, 0], // 4
[1, 3, 1, 2, 2, 2, 0, 0], // 5
[1, 2, 2, 2, 1, 3, 0, 0], // 6
[1, 2, 2, 3, 1, 2, 0, 0], // 7
[1, 3, 2, 2, 1, 2, 0, 0], // 8
[2, 2, 1, 2, 1, 3, 0, 0], // 9
[2, 2, 1, 3, 1, 2, 0, 0], // 10
[2, 3, 1, 2, 1, 2, 0, 0], // 11
[1, 1, 2, 2, 3, 2, 0, 0], // 12
[1, 2, 2, 1, 3, 2, 0, 0], // 13
[1, 2, 2, 2, 3, 1, 0, 0], // 14
[1, 1, 3, 2, 2, 2, 0, 0], // 15
[1, 2, 3, 1, 2, 2, 0, 0], // 16
[1, 2, 3, 2, 2, 1, 0, 0], // 17
[2, 2, 3, 2, 1, 1, 0, 0], // 18
[2, 2, 1, 1, 3, 2, 0, 0], // 19
[2, 2, 1, 2, 3, 1, 0, 0], // 20
[2, 1, 3, 2, 1, 2, 0, 0], // 21
[2, 2, 3, 1, 1, 2, 0, 0], // 22
[3, 1, 2, 1, 3, 1, 0, 0], // 23
[3, 1, 1, 2, 2, 2, 0, 0], // 24
[3, 2, 1, 1, 2, 2, 0, 0], // 25
[3, 2, 1, 2, 2, 1, 0, 0], // 26
[3, 1, 2, 2, 1, 2, 0, 0], // 27
[3, 2, 2, 1, 1, 2, 0, 0], // 28
[3, 2, 2, 2, 1, 1, 0, 0], // 29
[2, 1, 2, 1, 2, 3, 0, 0], // 30
[2, 1, 2, 3, 2, 1, 0, 0], // 31
[2, 3, 2, 1, 2, 1, 0, 0], // 32
[1, 1, 1, 3, 2, 3, 0, 0], // 33
[1, 3, 1, 1, 2, 3, 0, 0], // 34
[1, 3, 1, 3, 2, 1, 0, 0], // 35
[1, 1, 2, 3, 1, 3, 0, 0], // 36
[1, 3, 2, 1, 1, 3, 0, 0], // 37
[1, 3, 2, 3, 1, 1, 0, 0], // 38
[2, 1, 1, 3, 1, 3, 0, 0], // 39
[2, 3, 1, 1, 1, 3, 0, 0], // 40
[2, 3, 1, 3, 1, 1, 0, 0], // 41
[1, 1, 2, 1, 3, 3, 0, 0], // 42
[1, 1, 2, 3, 3, 1, 0, 0], // 43
[1, 3, 2, 1, 3, 1, 0, 0], // 44
[1, 1, 3, 1, 2, 3, 0, 0], // 45
[1, 1, 3, 3, 2, 1, 0, 0], // 46
[1, 3, 3, 1, 2, 1, 0, 0], // 47
[3, 1, 3, 1, 2, 1, 0, 0], // 48
[2, 1, 1, 3, 3, 1, 0, 0], // 49
[2, 3, 1, 1, 3, 1, 0, 0], // 50
[2, 1, 3, 1, 1, 3, 0, 0], // 51
[2, 1, 3, 3, 1, 1, 0, 0], // 52
[2, 1, 3, 1, 3, 1, 0, 0], // 53
[3, 1, 1, 1, 2, 3, 0, 0], // 54
[3, 1, 1, 3, 2, 1, 0, 0], // 55
[3, 3, 1, 1, 2, 1, 0, 0], // 56
[3, 1, 2, 1, 1, 3, 0, 0], // 57
[3, 1, 2, 3, 1, 1, 0, 0], // 58
[3, 3, 2, 1, 1, 1, 0, 0], // 59
[3, 1, 4, 1, 1, 1, 0, 0], // 60
[2, 2, 1, 4, 1, 1, 0, 0], // 61
[4, 3, 1, 1, 1, 1, 0, 0], // 62
[1, 1, 1, 2, 2, 4, 0, 0], // 63
[1, 1, 1, 4, 2, 2, 0, 0], // 64
[1, 2, 1, 1, 2, 4, 0, 0], // 65
[1, 2, 1, 4, 2, 1, 0, 0], // 66
[1, 4, 1, 1, 2, 2, 0, 0], // 67
[1, 4, 1, 2, 2, 1, 0, 0], // 68
[1, 1, 2, 2, 1, 4, 0, 0], // 69
[1, 1, 2, 4, 1, 2, 0, 0], // 70
[1, 2, 2, 1, 1, 4, 0, 0], // 71
[1, 2, 2, 4, 1, 1, 0, 0], // 72
[1, 4, 2, 1, 1, 2, 0, 0], // 73
[1, 4, 2, 2, 1, 1, 0, 0], // 74
[2, 4, 1, 2, 1, 1, 0, 0], // 75
[2, 2, 1, 1, 1, 4, 0, 0], // 76
[4, 1, 3, 1, 1, 1, 0, 0], // 77
[2, 4, 1, 1, 1, 2, 0, 0], // 78
[1, 3, 4, 1, 1, 1, 0, 0], // 79
[1, 1, 1, 2, 4, 2, 0, 0], // 80
[1, 2, 1, 1, 4, 2, 0, 0], // 81
[1, 2, 1, 2, 4, 1, 0, 0], // 82
[1, 1, 4, 2, 1, 2, 0, 0], // 83
[1, 2, 4, 1, 1, 2, 0, 0], // 84
[1, 2, 4, 2, 1, 1, 0, 0], // 85
[4, 1, 1, 2, 1, 2, 0, 0], // 86
[4, 2, 1, 1, 1, 2, 0, 0], // 87
[4, 2, 1, 2, 1, 1, 0, 0], // 88
[2, 1, 2, 1, 4, 1, 0, 0], // 89
[2, 1, 4, 1, 2, 1, 0, 0], // 90
[4, 1, 2, 1, 2, 1, 0, 0], // 91
[1, 1, 1, 1, 4, 3, 0, 0], // 92
[1, 1, 1, 3, 4, 1, 0, 0], // 93
[1, 3, 1, 1, 4, 1, 0, 0], // 94
[1, 1, 4, 1, 1, 3, 0, 0], // 95
[1, 1, 4, 3, 1, 1, 0, 0], // 96
[4, 1, 1, 1, 1, 3, 0, 0], // 97
[4, 1, 1, 3, 1, 1, 0, 0], // 98
[1, 1, 3, 1, 4, 1, 0, 0], // 99
[1, 1, 4, 1, 3, 1, 0, 0], // 100
[3, 1, 1, 1, 4, 1, 0, 0], // 101
[4, 1, 1, 1, 3, 1, 0, 0], // 102
[2, 1, 1, 4, 1, 2, 0, 0], // 103
[2, 1, 1, 2, 1, 4, 0, 0], // 104
[2, 1, 1, 2, 3, 2, 0, 0], // 105
[2, 3, 3, 1, 1, 1, 2, 0] // 106
]

Laden…
Abbrechen
Speichern