提交 2c269700 编写于 作者: Q qiang

feat: App 端 uni.scanCode 支持配置 autoDecodeCharSet

上级 13f78be7
...@@ -114,11 +114,12 @@ ...@@ -114,11 +114,12 @@
scan = new plus.barcode.Barcode('scan', webview.__uniapp_scan_type, { scan = new plus.barcode.Barcode('scan', webview.__uniapp_scan_type, {
frameColor: '#118CE9', frameColor: '#118CE9',
scanbarColor: '#118CE9' scanbarColor: '#118CE9'
}); }, webview.__uniapp_auto_decode_char_set);
scan.onmarked = function(type, code, file) { scan.onmarked = function(type, code, file, charSet) {
var res = { var res = {
type: type, type: type,
code: code code: code,
charSet: charSet
}; };
back() back()
plus.webview.postMessageToUniNView({ plus.webview.postMessageToUniNView({
......
...@@ -114,11 +114,12 @@ ...@@ -114,11 +114,12 @@
scan = new plus.barcode.Barcode('scan', webview.__uniapp_scan_type, { scan = new plus.barcode.Barcode('scan', webview.__uniapp_scan_type, {
frameColor: '#118CE9', frameColor: '#118CE9',
scanbarColor: '#118CE9' scanbarColor: '#118CE9'
}); }, webview.__uniapp_auto_decode_char_set);
scan.onmarked = function(type, code, file) { scan.onmarked = function(type, code, file, charSet) {
var res = { var res = {
type: type, type: type,
code: code code: code,
charSet: charSet
}; };
back() back()
plus.webview.postMessageToUniNView({ plus.webview.postMessageToUniNView({
......
export const scanCode = {
onlyFromCamera: {
type: Boolean
},
scanType: {
type: Array
},
autoDecodeCharSet: {
type: Boolean
}
}
...@@ -23,7 +23,8 @@ const MESSAGE_TYPE = 'scanCode' ...@@ -23,7 +23,8 @@ const MESSAGE_TYPE = 'scanCode'
export function scanCode ({ export function scanCode ({
onlyFromCamera = false, onlyFromCamera = false,
scanType scanType,
autoDecodeCharSet
}, callbackId) { }, callbackId) {
const barcode = plus.barcode const barcode = plus.barcode
const SCAN_TYPES = { const SCAN_TYPES = {
...@@ -95,18 +96,19 @@ export function scanCode ({ ...@@ -95,18 +96,19 @@ export function scanCode ({
width: '60px', width: '60px',
onclick: function () { onclick: function () {
plus.gallery.pick(file => { plus.gallery.pick(file => {
barcode.scan(file, (type, code) => { barcode.scan(file, (type, code, path, charSet) => {
if (isDark) { if (isDark) {
plus.navigator.setStatusBarStyle('isDark') plus.navigator.setStatusBarStyle('isDark')
} }
result = { result = {
type, type,
code code,
charSet
} }
webview.close('auto') webview.close('auto')
}, () => { }, () => {
plus.nativeUI.toast('识别失败') plus.nativeUI.toast('识别失败')
}, filters) }, filters, autoDecodeCharSet)
}, err => { }, err => {
if (err.code !== 12) { if (err.code !== 12) {
plus.nativeUI.toast('选择失败') plus.nativeUI.toast('选择失败')
...@@ -135,6 +137,7 @@ export function scanCode ({ ...@@ -135,6 +137,7 @@ export function scanCode ({
__uniapp_type: 'scan', __uniapp_type: 'scan',
__uniapp_dark: isDark, __uniapp_dark: isDark,
__uniapp_scan_type: filters, __uniapp_scan_type: filters,
__uniapp_auto_decode_char_set: autoDecodeCharSet,
'uni-app': 'none' 'uni-app': 'none'
}) })
const waiting = plus.nativeUI.showWaiting() const waiting = plus.nativeUI.showWaiting()
...@@ -148,7 +151,7 @@ export function scanCode ({ ...@@ -148,7 +151,7 @@ export function scanCode ({
invoke(callbackId, { invoke(callbackId, {
result: result.code, result: result.code,
scanType: SCAN_MAPS[result.type] || '', scanType: SCAN_MAPS[result.type] || '',
charSet: 'utf8', charSet: result.charSet || 'utf8',
path: '', path: '',
errMsg: 'scanCode:ok' errMsg: 'scanCode:ok'
}) })
......
...@@ -23,9 +23,7 @@ export function scanCode (options, callbackId) { ...@@ -23,9 +23,7 @@ export function scanCode (options, callbackId) {
let result let result
const page = showPage({ const page = showPage({
url: '__uniappscan', url: '__uniappscan',
data: { data: options,
scanType: options.scanType
},
style: { style: {
animationType: options.animationType || 'pop-in', animationType: options.animationType || 'pop-in',
titleNView: { titleNView: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册