forked from handsomeliuyang/taro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request handsomeliuyang#466 from xiaoyan428820/release-3.6…
….8-app feat: 新增支持一维码二维码扫码能力
- Loading branch information
Showing
6 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/mini-program-example/src/pages/api/location/index.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export default { | ||
navigationBarTitleText: '位置', | ||
navigationStyle: 'custom' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,42 @@ | ||
import Taro from '@tarojs/api' | ||
import { shouldBeObject } from 'src/utils' | ||
import { MethodHandler } from 'src/utils/handler' | ||
|
||
/** | ||
* 调起客户端扫码界面,扫码成功后返回对应的结果(harmony平台暂不支持) | ||
* 调起客户端扫码界面,扫码成功后返回对应的结果 | ||
* | ||
* @canNotUse scanCode | ||
* @canUse scanCode | ||
* @__object [onlyFromCamera, scanType[barCode, qrCode, datamatrix, pdf417]] | ||
* @__success [charSet, rawData, result, scanType[QR_CODE, AZTEC, CODABAR, CODE_39, CODE_93, CODE_128,\ | ||
* DATA_MATRIX, EAN_8, EAN_13, ITF, PDF_417, UPC_A, UPC_E]] | ||
*/ | ||
export { scanCode } from '@tarojs/taro-h5' | ||
export const scanCode: typeof Taro.scanCode = (options) => { | ||
const name = 'scanCode' | ||
const isValid = shouldBeObject(options).flag || typeof options === 'undefined' | ||
if (!isValid) { | ||
const res = { errMsg: `${name}:fail invalid params` } | ||
return Promise.reject(res) | ||
} | ||
const { | ||
onlyFromCamera = false, | ||
scanType = [], | ||
success, | ||
fail, | ||
complete | ||
} = options || {} | ||
const handle = new MethodHandler({ name, success, fail, complete }) | ||
|
||
return new Promise((resolve, reject) => { | ||
// @ts-ignore | ||
native.scanCode({ | ||
onlyFromCamera, | ||
scanType, | ||
success: (res: any) => { | ||
handle.success(res, { resolve, reject }) | ||
}, | ||
fail: (res: any) => { | ||
handle.fail(res, { resolve, reject }) | ||
}, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters