ChicoreDriver Web 打印 - APISampleVue js靜默打印 ,,web 打印, Vue js打印,Vue 打印, Vue Javascript 打印,Vue Vue js 靜默打印,Vue js 不預覽打印,Vue 浏覽器(qì)打印,Vue js标簽打印,Vue 單據打印 ,CCPrintingAPI for ChicoreDriver, Vue 打印範例代碼,Vue 标簽打印API,條碼,二維碼标簽,Vue單據打印,很(hěn)容易集成。
CCPrintingAPI XI
輕量、簡潔、穩定、可(kě)靠,打印機API接口,ChicoreDriver 免驅。
免驅打印接口API Vue 代碼
Vue
CCPrintingAPI for ChicoreDriver Vue API打印範例代碼,Vue 浏覽器(qì)Web前端打印,通(tōng)過Vue 調用CCPrintingAPI打印機接口API。

{{myhid}}
{{mytipsmessage}}
{{timetick}}
1. 引入 CCPrintingAPI.min.vue.js
引入CCPrintingAPI.min.vue.js後,即可(kě)使用API的相關方法,進行(xíng)設置和(hé)打印操作(zuò)。
import { CCPrintingAPI } from 'static/js/CCPrintingAPI.min.vue.js'
2. 獲取打印機
獲取計(jì)算(suàn)機上(shàng)所有(yǒu)打印機, 打印時(shí),指定該列表的打印機名稱。如果能确保打印機名稱不變,該操作(zuò)也可(kě)省去。
GetPrinters: function () {
    var cfgData = new Object;
    cfgData.XAction = "Printers";
    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];
	   }
        }
    );
}
3. 打印
進行(xíng)相關參數(shù)設置後(指定打印機,設置模闆,設置打印數(shù)據),将指令通(tōng)過API傳給打印機。
Print: function () {
    var cfgPrintSettings = new Object;
    cfgPrintSettings.XAction = "Print"
	var ccdriverPrinter = new Object;
	/*免驅打印機名稱ChicoreDriver-USB-Honeywell PC42t-203-FP-1*/
	ccdriverPrinter.Name = this.selected;
	ccdriverPrinter.InterfaceType = 0;
	/*打印速度 2,3,4*/
	ccdriverPrinter.Speed = 4;
	/*打印方向 0-0°,1-90°,2-180°,3-270°*/
	ccdriverPrinter.Direction = 0;
	/*打印濃度0~30*/
	ccdriverPrinter.Density = 10;
	/*打印方式 0-熱轉印,1-熱敏*/
	ccdriverPrinter.MediaType = 1;
	/*介質類型 0-連續紙,2-有(yǒu)間(jiān)隙的标簽,3-有(yǒu)标記的紙*/
	ccdriverPrinter.MediaSensing = 2;
	/*負片打印 0-否,2-是*/
	ccdriverPrinter.ReversePrint= 0;
	/*水(shuǐ)平偏移mm*/
	ccdriverPrinter.StartX= 0;
	/*垂直偏移mm*/
	ccdriverPrinter.StartY= 0;

	/*指定打印機*/
	cfgPrintSettings.PrinterName =JSON.stringify(ccdriverPrinter);


    /*模闆方式,0-客戶端模闆,1-遠程模闆,
                2-如果本地模闆存在,使用本地,不存在使用遠程模闆,3-不使用模闆*/
    cfgPrintSettings.TemplateMode = "1";
    /*遠程模闆URL或本地模闆的文件夾*/
    cfgPrintSettings.TemplateURL = "http://img.51321.cn/web/chicore/VPrinting/API";
    //cfgPrintSettings.TemplateURL =  "E:\\臨時(shí)數(shù)據\\打印\\打印樣本\\API标簽模闆";
    /*模闆文件名*/
    cfgPrintSettings.TemplateName = "183601-70X40.Lblx";
    /*打印數(shù)據的類型,0-數(shù)組,1-Json數(shù)組,元素為(wèi)JSON對象,字段:值*/
    cfgPrintSettings.PrintDataType = 1;
    /*傳遞打印數(shù)據 Json數(shù)組*/ /*內(nèi)容不允許 半角的逗号及半角的分隔符*/
    var arr = [
        { sku: 'OBJ100001', name: '測試1', kw: 'D12-1', bh: 'RKD123451' },
        { sku: 'OBJ100002', name: '測試2', kw: 'D12-2', bh: 'RKD123452' },
        { sku: 'OBJ100003', name: '測試3', kw: 'D12-3', bh: 'RKD123453' },
    ];
    cfgPrintSettings.PrintData = JSON.stringify(arr);
    /*打印 發送給打印機進行(xíng)打印*/
    CCPrintingAPI.Excute(cfgPrintSettings,
        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];
	      }
        }
    );
}
4. 讀取客戶端HID
讀取安裝CCPrintingAPI的客戶端計(jì)算(suàn)機HID,該HID可(kě)以用來(lái)标識計(jì)算(suàn)機。該方法,根據需要使用。
GetHID: function () {
    var cfgData = new Object;
    cfgData.XAction = 'HID';
    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.myhid = smsg;
	    }else{
		  if (apiResult.Message.length > 1)
				this.mytipsmessage = apiResult.Message[0] +  " :  " + apiResult.Message[1];
		   else
				this.mytipsmessage = apiResult.Message[0];
	     }
        }
    );
}