1.0.3 • Published 4 years ago
@uni/scan v1.0.3
scan
Opens the code scanning interface in the app to scan the code.
Supported
Install
$ npm install @uni/scan --save
or
$ npm install @uni/apis --save
示例
import scan from '@uni/scan';
scan({
scanType: ['qrCode','barCode'],
success (res) {
console.log(res.result)
},
fail (res) {
console.log(res)
}
});
// promise
scan({
scanType: ['qrCode','barCode'],
}).then(res => {
console.log(res.result)
});
You can also import from big package:
import { scan } from '@uni/apis';
Function
scan(options)
Property
Property | Type | Description | Required | Default |
---|---|---|---|---|
options | object | ✘ | - | |
options.success | Function | The callback function for a successful API call | ✘ | - |
options.fail | Function | The callback function for a failed API call | ✘ | - |
options.complete | Function | The callback function used when the API call completed | ✘ | - |
Valid values of object.scanType
Value | Description | Supported |
---|---|---|
barCode | Barcode | |
qrCode | QR code | |
dmCode | Data Matrix code | |
pdf417Code | PDF417 barcode | |
narrowCode | Narrow bar QR code | |
hmCode | Heterogeneous code |
Non general parameters
Property | Type | Description | Required | Default | Supported |
---|---|---|---|---|---|
options.hideAlbum | Boolean | Indicates whether to allow to scan code with camera only | ✘ | false | |
options.scanType | Array<string> | Type of code to scan | ✘ | 'barCode', 'qrCode' |
object.success callback function
Object res
Property | Type | Description |
---|---|---|
result | string | Content of code to scan |
Non general parameters
Property | Type | Description | Supported |
---|---|---|---|
charSet | string | Character set of code to scan | |
path | string | If the scanned code is the QR code of the current Mini Program, this field is returned, and the content is the path carried by the QR code. | |
scanType | string | Type of code to scan | |
rawData | string | Base64 encoded raw data | |
imageChannel | string | source | |
code | string | Scan data | |
qrCode | string | Return QR code data when scanning QR code | |
barCode | string | Return barcode data when scanning barcode. |