模板修改

master
张萌 3 years ago
parent c0db9d2871
commit 88397f8589

@ -2,6 +2,15 @@
汉印打印机插件 汉印打印机插件
仅支持安卓 仅支持安卓
###
在build.gradle中 需要把minSdkVersion 改为19
权限配置中加入
```dart
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
```
##扫描设备 ##扫描设备
```dart ```dart
HyPrinter.getDevices(); HyPrinter.getDevices();

@ -56,7 +56,7 @@ public class HyPrinterPlugin implements FlutterPlugin, MethodCallHandler {
} }
result.success(status); result.success(status);
} else if (call.method.equals("printAsOrder")) { } else if (call.method.equals("printAsOrder")) {
int re = PrintAsOrder.print(call.argument("code"), call.argument("fbaCode"), call.argument("country"), call.argument("channel"), call.argument("count")); int re = PrintAsOrder.print(call.argument("code"), call.argument("fbaCode"), call.argument("country"), call.argument("channel"), call.argument("count"), call.argument("hasPlan"));
result.success(re); result.success(re);
} else if (call.method.equals("printBarCode")) { } else if (call.method.equals("printBarCode")) {
int re = -1; int re = -1;

@ -1,7 +1,5 @@
package com.hy.print.hy_printer; package com.hy.print.hy_printer;
import android.content.Context;
import cpcl.PrinterHelper; import cpcl.PrinterHelper;
public class PrintAsOrder { public class PrintAsOrder {
@ -21,19 +19,18 @@ public class PrintAsOrder {
} }
} }
public static int print(String code, String fbaCode, String country, String channel, String count) { public static int print(String code, String fbaCode, String country, String channel, String count, Boolean hasPlan) {
int re = 0; int re = 0;
if (fbaCode.isEmpty()) { if (!hasPlan) {
re = printNoFba(code, count); re = printNoPlan(code, count);
} else { } else {
re = printFba(code, fbaCode, country, channel, count); re = printHasPlan(code, fbaCode, country, channel, count);
} }
return re; return re;
} }
;
public static int printNoFba(String code, String count) { public static int printNoPlan(String code, String count) {
int reusult = 0; int reusult = 0;
System.out.println("print start"); System.out.println("print start");
try { try {
@ -47,14 +44,14 @@ public class PrintAsOrder {
PrinterHelper.Line("42", "228", "550", "228", "2"); PrinterHelper.Line("42", "228", "550", "228", "2");
setBold(); setBold();
PrinterHelper.SetMag("2","2"); PrinterHelper.SetMag("2", "2");
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "45", "254", "未建计划"); PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "45", "254", "未建计划");
PrinterHelper.Align(PrinterHelper.RIGHT); PrinterHelper.Align(PrinterHelper.RIGHT);
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "42", "254", "件数"); PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "42", "254", "件数");
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "42", "300", count); PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "42", "300", count);
PrinterHelper.SetMag("1","1"); PrinterHelper.SetMag("1", "1");
closeBold(); closeBold();
PrinterHelper.Align(PrinterHelper.LEFT); PrinterHelper.Align(PrinterHelper.LEFT);
PrinterHelper.Form(); PrinterHelper.Form();
@ -67,7 +64,7 @@ public class PrintAsOrder {
return reusult; return reusult;
} }
public static int printFba(String code, String fbaCode, String country, String channel, String count) { public static int printHasPlan(String code, String fbaCode, String country, String channel, String count) {
int reusult = 0; int reusult = 0;
System.out.println("print start"); System.out.println("print start");
try { try {
@ -78,7 +75,11 @@ public class PrintAsOrder {
PrinterHelper.SetBold("3"); PrinterHelper.SetBold("3");
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "170", 500, 4, code); PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "170", 500, 4, code);
closeBold(); closeBold();
fbaCode = "FBA号" + fbaCode; if (fbaCode.isEmpty()) {
fbaCode = "非BFA订单";
} else {
fbaCode = "FBA号" + fbaCode;
}
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "222", 500, 8, fbaCode); PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "222", 500, 8, fbaCode);
PrinterHelper.Line("42", "269", "550", "269", "2"); PrinterHelper.Line("42", "269", "550", "269", "2");
setBold(); setBold();

@ -75,14 +75,24 @@ class _HomeState extends State<Home> {
TextButton( TextButton(
onPressed: () async { onPressed: () async {
await HyPrinter.printAsOrder( await HyPrinter.printAsOrder(
'ASSZ202112120001', '', "", '', "2/10"); code: 'ASASNB2021121200010002',
fbaCode: '',
channel: "",
country: '',
count: "2/10",
hasPlan: false);
setState(() {}); setState(() {});
}, },
child: const Text('打印非FBA面单')), child: const Text('打印面单')),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
await HyPrinter.printAsOrder('ASSZ202112120001', await HyPrinter.printAsOrder(
'FBA15RY33MN8U00001', "欧洲特快", '法国', "2/10"); code: 'ASASNB2021121200010002',
fbaCode: 'FBA15RY33MN8U00001',
channel: "欧洲特快",
country: '法国',
count: "2/10",
hasPlan: true);
setState(() {}); setState(() {});
}, },
child: const Text('打印FBA面单')), child: const Text('打印FBA面单')),

@ -25,6 +25,11 @@ class HyPrinter {
return devices; return devices;
} }
static Future<bool> blutIsOn() async {
var result = await flutterBlue.isOn;
return result;
}
///0 ///0
///-1 ///-1
///-2 ///-2
@ -106,14 +111,26 @@ class HyPrinter {
return result; return result;
} }
static Future<int> printAsOrder(String code, String fbaCode, String channel, /// 'code': code,
String country, String count) async { // 'fbaCode': fbaCode, fba/fba
// 'channel': channel,
// 'country': country,
// 'count': count,
// 'hasPlan':hasPlan
static Future<int> printAsOrder(
{required String code,
required String fbaCode,
required String channel,
required String country,
required String count,
required bool hasPlan}) async {
int result = await _channel.invokeMethod('printAsOrder', { int result = await _channel.invokeMethod('printAsOrder', {
'code': code, 'code': code,
'fbaCode': fbaCode, 'fbaCode': fbaCode,
'channel': channel, 'channel': channel,
'country': country, 'country': country,
'count': count, 'count': count,
'hasPlan': hasPlan
}); });
return result; return result;
} }

Loading…
Cancel
Save