import { CCPrintingAPI } from 'static/js/CCPrintingAPI.min.vue.js'
GetPrinters: function () {
var cfgData = new Object;
cfgData.XAction = "Printers";
cfgData.XOpenId = m_OpenId;
cfgData.XTokens = m_Tokens;
CCPrintingAPI.Excute(cfgData,
XTimeout => { },
XFail => {
this.mytipsmessage = 'API可(kě)能未安裝或未啓動, ' + XFail;
},
XSuccess => {
var d = new Date;
this.timetick = d.getTime();
var apiResult = JSON.parse(XSuccess.trim());
if (apiResult.Status == "1") {
if (apiResult.Message.length > 1) {
this.options = [];
for (var i = 1; i < apiResult.Message.length; i++) {
var op = new Object;
op.text = apiResult.Message[i];
op.value = apiResult.Message[i];
this.options.push(op);
}
/*設置上(shàng)次使用的打印機*/
this.selected = this.options[0].value;
}
} else {
if (apiResult.Message.length > 1)
this.mytipsmessage = apiResult.Message[0] + " : " + apiResult.Message[1];
else
this.mytipsmessage = apiResult.Message[0];
}
}
);
}
GetSelfDraw:function(){
var selfdraw = {
"Image":
[
{
"Name" : "Image1" ,
"LabelType" : "1" ,
"X" : "0" ,
"Y" : "0" ,
"Width" : "50" ,
"Height" : "30" ,
"Data" : "" ,
"IsBind" : "1" ,
"BindField" : "Field1" ,
"Embed" : "" ,
"IsToFront" : "0" ,
"IsThird" : "0" ,
"ImageColor" : "0" ,
"RotateOrientation" : "0" ,
"KeepRatio" : "1" ,
"Visible" : "1"
}
],
"PageSettings":
{
"Width" : "52" ,
"Height" : "30" ,
"TopMargin" : "0" ,
"BottomMargin" : "0" ,
"LeftMargin" : "1" ,
"RightMargin" : "0" ,
"PrinterPaperAutoSet" : "1" ,
"UseQuickSetTool" : "1" ,
"Landscape" : "0"
},
"LabelDetail":
{
"Width" : "50" ,
"Height" : "30" ,
"RowSpan" : "2" ,
"ColumnSpan" : "2" ,
"Visible" : "1"
},
"DataBase":
{
"FieldNumbers" : "15" ,
"FieldNames":
[
]
}
};
return JSON.stringify(selfdraw);
}
Print: function () {
var cfgData = new Object;
cfgData.XAction = "Print"
cfgData.XOpenId = m_OpenId;
cfgData.XTokens = m_Tokens;
/*指定打印機*/
cfgData.PrinterName = this.selected;
/*模闆方式,0-客戶端模闆,1-遠程模闆,
2-如果本地模闆存在,使用本地,不存在使用遠程模闆,3-不使用模闆*/
cfgData.TemplateMode = "3";
cfgData.SelfDraw = this.GetSelfDraw();
/*打印數(shù)據的類型,0-數(shù)組,1-Json數(shù)組,元素為(wèi)JSON對象,字段:值*/
cfgData.PrintDataType = 1;
/*傳遞打印數(shù)據 Json數(shù)組*/ /*內(nèi)容不允許 半角的逗号及半角的分隔符*/
var arr = [
{ Field1: 'static/picture/2315002468301572.jpg'}
];
cfgData.PrintData = JSON.stringify(arr);
/*打印 發送給打印機進行(xíng)打印*/
CCPrintingAPI.Excute(cfgData,
XTimeout => { },
XFail => {
this.mytipsmessage = 'API可(kě)能未安裝或未啓動, ' + XFail;
},
XSuccess => {
var d = new Date;
this.timetick = d.getTime();
var apiResult = JSON.parse(XSuccess.trim());
if (apiResult.Status == "1") {
var smsg = apiResult.Message[0];
if (apiResult.Message.length > 1)
smsg += " : " + apiResult.Message[1]
this.mytipsmessage = smsg;
} else {
if (apiResult.Message.length > 1)
this.mytipsmessage = apiResult.Message[0] + " : " + apiResult.Message[1];
else
this.mytipsmessage = apiResult.Message[0];
}
}
);
}