feat:样品库管理
This commit is contained in:
3
uni_modules/zzjc-urovo/utssdk/app-android/config.json
Normal file
3
uni_modules/zzjc-urovo/utssdk/app-android/config.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "21"
|
||||
}
|
||||
118
uni_modules/zzjc-urovo/utssdk/app-android/index.uts
Normal file
118
uni_modules/zzjc-urovo/utssdk/app-android/index.uts
Normal file
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* 引用 Android 系统库,示例如下:
|
||||
* import { Context } from "android.content.Context";
|
||||
* [可选实现,按需引入]
|
||||
*/
|
||||
import Activity from 'android.app.Activity';
|
||||
import IntentFilter from 'android.content.IntentFilter';
|
||||
import BroadcastReceiver from 'android.content.BroadcastReceiver';
|
||||
import Context from 'android.content.Context';
|
||||
import Intent from 'android.content.Intent';
|
||||
|
||||
/* 引入 interface.uts 文件中定义的变量 */
|
||||
import { MyApiOptions, MyApiResult, MyApi, MyApiSync, OnScanReceiverCallback, ScanRegister, ScanUnRegister } from '../interface.uts';
|
||||
|
||||
/* 引入 unierror.uts 文件中定义的变量 */
|
||||
import { MyApiFailImpl } from '../unierror';
|
||||
|
||||
import ScanBroadcastReceiver from './scan/ScanBroadcastReceiver';
|
||||
|
||||
/**
|
||||
* 引入三方库
|
||||
* [可选实现,按需引入]
|
||||
*
|
||||
* 在 Android 平台引入三方库有以下两种方式:
|
||||
* 1、[推荐] 通过 仓储 方式引入,将 三方库的依赖信息 配置到 config.json 文件下的 dependencies 字段下。详细配置方式[详见](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#dependencies)
|
||||
* 2、直接引入,将 三方库的aar或jar文件 放到libs目录下。更多信息[详见](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#android%E5%B9%B3%E5%8F%B0%E5%8E%9F%E7%94%9F%E9%85%8D%E7%BD%AE)
|
||||
*
|
||||
* 在通过上述任意方式依赖三方库后,使用时需要在文件中 import,如下示例:
|
||||
* import { LottieAnimationView } from 'com.airbnb.lottie.LottieAnimationView'
|
||||
*/
|
||||
|
||||
/**
|
||||
* UTSAndroid 为平台内置对象,不需要 import 可直接调用其API,[详见](https://uniapp.dcloud.net.cn/uts/utsandroid.html#utsandroid)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 异步方法
|
||||
*
|
||||
* uni-app项目中(vue/nvue)调用示例:
|
||||
* 1、引入方法声明 import { myApi } from "@/uni_modules/uts-api"
|
||||
* 2、方法调用
|
||||
* myApi({
|
||||
* paramA: false,
|
||||
* complete: (res) => {
|
||||
* console.log(res)
|
||||
* }
|
||||
* });
|
||||
* uni-app x项目(uvue)中调用示例:
|
||||
* 1、引入方法及参数声明 import { myApi, MyApiOptions } from "@/uni_modules/uts-api";
|
||||
* 2、方法调用
|
||||
* let options = {
|
||||
* paramA: false,
|
||||
* complete: (res : any) => {
|
||||
* console.log(res)
|
||||
* }
|
||||
* } as MyApiOptions;
|
||||
* myApi(options);
|
||||
*
|
||||
*/
|
||||
export const myApi : MyApi = function (options : MyApiOptions) {
|
||||
if (options.paramA == true) {
|
||||
// 返回数据
|
||||
const res : MyApiResult = {
|
||||
fieldA: 85,
|
||||
fieldB: true,
|
||||
fieldC: 'some message'
|
||||
};
|
||||
options.success?.(res);
|
||||
options.complete?.(res);
|
||||
} else {
|
||||
// 返回错误
|
||||
const err = new MyApiFailImpl(9010001);
|
||||
options.fail?.(err)
|
||||
options.complete?.(err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步方法
|
||||
*
|
||||
* uni-app项目中(vue/nvue)调用示例:
|
||||
* 1、引入方法声明 import { myApiSync } from "@/uni_modules/uts-api"
|
||||
* 2、方法调用 myApiSync(true)
|
||||
*
|
||||
* uni-app x项目(uvue)中调用示例:
|
||||
* 1、引入方法及参数声明 import { myApiSync } from "@/uni_modules/uts-api";
|
||||
* 2、方法调用 myApiSync(true)
|
||||
*/
|
||||
export const myApiSync : MyApiSync = function (paramA : boolean) : MyApiResult {
|
||||
// 返回数据,根据插件功能获取实际的返回值
|
||||
const res : MyApiResult = {
|
||||
fieldA: 85,
|
||||
fieldB: paramA,
|
||||
fieldC: 'some message'
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
// 目前装饰器不支持 export const test:Test = ()=>{} // 这种导出方式,需要使用export function test(){}
|
||||
// @UTSJS.keepAlive
|
||||
// export const scanRegister : ScanRegister = function (callback: OnScanReceiverCallback) {
|
||||
// const sbr = ScanBroadcastReceiver.getInstance(UTSAndroid.getAppContext());
|
||||
// sbr.registerReceiver(callback);
|
||||
// }
|
||||
|
||||
@UTSJS.keepAlive
|
||||
export function scanRegister(callback: OnScanReceiverCallback) {
|
||||
const sbr = ScanBroadcastReceiver.getInstance(UTSAndroid.getAppContext());
|
||||
sbr.registerReceiver(callback);
|
||||
}
|
||||
|
||||
export const scanUnRegister : ScanUnRegister = function () {
|
||||
const sbr = ScanBroadcastReceiver.getInstance(UTSAndroid.getAppContext());
|
||||
sbr.unregisterReceiver();
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,86 @@
|
||||
import Activity from 'android.app.Activity';
|
||||
import IntentFilter from 'android.content.IntentFilter';
|
||||
import BroadcastReceiver from 'android.content.BroadcastReceiver';
|
||||
import Context from 'android.content.Context';
|
||||
import Intent from 'android.content.Intent';
|
||||
|
||||
import ScanManager from 'android.device.ScanManager';
|
||||
import PropertyID from 'android.device.scanner.configuration.PropertyID';
|
||||
|
||||
import { OnScanReceiverCallback } from '../../interface.uts';
|
||||
|
||||
export default class ScanBroadcastReceiver {
|
||||
private static instance : ScanBroadcastReceiver = new ScanBroadcastReceiver();
|
||||
|
||||
private context : Context | null = null;
|
||||
|
||||
private scanBroadcastReceiver: UrovoScanBroadcastReceiver | null = null;
|
||||
|
||||
private scanManager: ScanManager | null = null;
|
||||
|
||||
private intentFilter: IntentFilter | null = null;
|
||||
|
||||
private constructor() {
|
||||
}
|
||||
|
||||
static getInstance(context : Context | null) : ScanBroadcastReceiver {
|
||||
ScanBroadcastReceiver.instance.context = context;
|
||||
return ScanBroadcastReceiver.instance;
|
||||
}
|
||||
|
||||
registerReceiver(callback: OnScanReceiverCallback) {
|
||||
this.scanBroadcastReceiver = new UrovoScanBroadcastReceiver(callback);
|
||||
if(this.scanManager == null) {
|
||||
this.scanManager = new ScanManager();
|
||||
this.scanManager!.openScanner();
|
||||
this.scanManager!.switchOutputMode(0);
|
||||
}
|
||||
this.intentFilter = new IntentFilter();
|
||||
let idbuf = intArrayOf(PropertyID.WEDGE_INTENT_ACTION_NAME, PropertyID.WEDGE_INTENT_DATA_STRING_TAG);
|
||||
let value_buf = this.scanManager!.getParameterString(idbuf);
|
||||
if (value_buf != null && value_buf[0] != null && !value_buf[0].equals("")) {
|
||||
this.intentFilter!.addAction(value_buf[0]);
|
||||
} else {
|
||||
this.intentFilter!.addAction(ScanManager.ACTION_DECODE);
|
||||
}
|
||||
//this.intentFilter!.addAction(ScanManager.ACTION_CAPTURE_IMAGE);
|
||||
|
||||
UTSAndroid.getUniActivity()!.registerReceiver(this.scanBroadcastReceiver, this.intentFilter);
|
||||
}
|
||||
|
||||
unregisterReceiver () {
|
||||
let uniActivity: Activity | null = UTSAndroid.getUniActivity();
|
||||
if(this.scanBroadcastReceiver != null) {
|
||||
uniActivity!.unregisterReceiver(this.scanBroadcastReceiver);
|
||||
}
|
||||
|
||||
//停止扫描
|
||||
if (this.scanManager != null){
|
||||
this.scanManager?.stopDecode();
|
||||
}
|
||||
|
||||
this.scanBroadcastReceiver = null;
|
||||
}
|
||||
}
|
||||
|
||||
class UrovoScanBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
private callback: OnScanReceiverCallback;
|
||||
|
||||
constructor(callback: OnScanReceiverCallback) {
|
||||
super();
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
override onReceive(context : Context, intent : Intent) {
|
||||
let barcode = intent.getByteArrayExtra(ScanManager.DECODE_DATA_TAG);
|
||||
let barcodelen = intent.getIntExtra(ScanManager.BARCODE_LENGTH_TAG, 0);
|
||||
let temp = intent.getByteExtra(ScanManager.BARCODE_TYPE_TAG, 0);
|
||||
console.log("----codetype--:" + temp);
|
||||
if(barcode != null) {
|
||||
let barcodeStr : string = new String(barcode, 0, barcodelen.toInt());
|
||||
this.callback(barcodeStr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user