有人可以帮助我了解如何使用nativescript-barcodescanner的结果

问题描述 投票:0回答:1

条码扫描器读取条码并显示在控制台日志中,但如何在Google Book API上查找该书。书籍详细信息(如书名,作者和出版年份)应显示在其他页面上。这是我关注的插件:https://github.com/EddyVerbruggen/nativescript-barcodescanner

这是我的hardcopy-view-model.js文件

var observable_1 = require("data/observable");
var dialogs_1 = require("ui/dialogs");
var view = require("ui/core/view");
var nativescript_barcodescanner = require("nativescript-barcodescanner");
const httpModule = require("http");

var BarCodeModel = (function (_super) {
__extends(BarCodeModel, _super);
function BarCodeModel() {
    _super.call(this);
    this.barcodeScanner = new nativescript_barcodescanner.BarcodeScanner();
}
BarCodeModel.prototype.doCheckHasCameraPermission = function () {
    this.barcodeScanner.hasCameraPermission().then(function (permitted) {
        dialogs_1.alert({
            title: "Has Camera permission?",
            message: permitted ? "YES" : "NO",
            okButtonText: "OK"
        });
    }, function (err) {
        dialogs_1.alert(err);
    });
};
BarCodeModel.prototype.doScanWithTorch = function () {
    this.scan(false, true, true, "landscape");
};
;
BarCodeModel.prototype.doScanLandscape = function () {
    this.scan(false, true, true, "landscape");
};
;

BarCodeModel.prototype.scan = function () {
 this.barcodeScanner.scan({
 cancelLabel: "EXIT. Also, try the volume buttons!", 
 cancelLabelBackgroundColor: "#333333", 
 message: "Tap the bulb button or Use the volume button for turning on 
 light", 
 showFlipCameraButton: false,   
 preferFrontCamera: false,     
 showTorchButton: true,        
 beepOnScan: true,             
 torchOn: false,               
 closeCallback: function () { console.log("Scanner closed"); }, 
 resultDisplayDuration: 500,  
 orientation: "landscape",     
 openSettingsIfPermissionWasPreviouslyDenied: true 
 }).then(

 function(result) {
        console.log("---- scanned " +result.text);
        httpModule.request({
            url: "https://www.googleapis.com/books/v1/volumes? 
 q=isbn:"+result,
            method: "GET"
        }).then((response) => {
            var obj = response.content.toJSON();
            console.log("Book: " +obj);
            console.log(JSON.parse(response)); 
            alert({
                title:"Scan Result",
                message: "Barcode Format: " + result.format + "\nCode: " + 
 result.text + "\nBook Title: " + result.response,
                okButtonText:"OK"
            });
        });  
     },          
  function(error) {
    console.log("No scan: " + error);
 });
};
;
return BarCodeModel;
}(observable_1.Observable));
exports.BarCodeModel = BarCodeModel;
javascript android google-api nativescript barcode-scanner
1个回答
0
投票

我认为问题是您需要在URL中传递result.text。 result.text具有实际的条形码。

url:“ https://www.googleapis.com/books/v1/volumes?q=isbn:” + result.text,

© www.soinside.com 2019 - 2024. All rights reserved.