mdq / yii2-instascan-widget
使用 instascan 插件读取二维码的 Yii2 小部件
dev-master
2019-02-22 19:17 UTC
Requires
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2024-09-19 09:40:52 UTC
README
使用 instascan 插件读取二维码的 Yii2 小部件 https://github.com/schmich/instascan
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist mdq/yii2-instascan-widget "*"
或者将以下内容添加到你的 composer.json 文件的 require 部分。
"mdq/yii2-instascan-widget": "*"
使用方法
扩展安装完成后,只需在代码中通过以下方式使用它:
<?= QrReader::widget([ 'videoOptions' => ['class' => 'qr-reader-preview', 'style' => 'width: 300px; height: 188px; ']; // When buttonLabel is "false", render camera immediately. 'buttonLabel' => 'Scan'; 'buttonOptions' => ['class' => 'btn btn-default']; 'options' = ['class' => 'qr-reader']; 'successCallback' => 'function(data){console.log(data);}', 'noCameraFoundCallback' => 'function(cameras){console.error('No cameras found.');}'; 'initErrorCallback' => 'function (e) {console.error(e);}'; // Whether to scan continuously for QR codes. If false, use scanner.scan() to manually scan. // If true, the scanner emits the "scan" event when a QR code is scanned. Default true. 'continuous' => true, // Whether to horizontally mirror the video preview. This is helpful when trying to // scan a QR code with a user-facing camera. Default true. 'mirror' => true, // Whether to include the scanned image data as part of the scan result. See the "scan" event // for image format details. Default false. 'captureImage' => false, // Only applies to continuous mode. Whether to actively scan when the tab is not active. // When false, this reduces CPU usage when the tab is not active. Default true. 'backgroundScan' => false, // Only applies to continuous mode. The period, in milliseconds, before the same QR code // will be recognized in succession. Default 5000 (5 seconds). 'refractoryPeriod' => 5000, // Only applies to continuous mode. The period, in rendered frames, between scans. A lower scan period // increases CPU usage but makes scan response faster. Default 1 (i.e. analyze every frame). 'scanPeriod' => 10, 'debug' => YII_DEBUG, ]); ?>```