Browse Source

print connect js success

dev
赵明涛 11 months ago
parent
commit
a0c457f6b7
  1. 4
      app/build.gradle
  2. 2
      app/src/main/assets/apps/__UNI__3B4D40B/www/__uniappview.html
  3. 6
      app/src/main/assets/apps/__UNI__3B4D40B/www/app-config-service.js
  4. 45
      app/src/main/assets/apps/__UNI__3B4D40B/www/app-renderjs.js
  5. 7
      app/src/main/assets/apps/__UNI__3B4D40B/www/app-service.js
  6. 1
      app/src/main/assets/apps/__UNI__3B4D40B/www/app.css
  7. 2
      app/src/main/assets/apps/__UNI__3B4D40B/www/manifest.json
  8. 2
      uniapp_project_code/src/manifest.json
  9. 59
      uniapp_project_code/src/pages/login/index.vue
  10. 16
      uniplugin_padprinter/build.gradle
  11. 3
      uniplugin_padprinter/proguard-rules.pro
  12. 2
      uniplugin_padprinter/src/main/AndroidManifest.xml
  13. 59
      uniplugin_padprinter/src/main/java/net/zmt/padprinter/Helper/Printer_Helper.java
  14. 76
      uniplugin_padprinter/src/main/java/net/zmt/padprinter/UniPluginPadPrinter.java

4
app/build.gradle

@ -8,8 +8,8 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 //21 io.dcloud.PandoraEntry apk入口时 targetSDKVersion>=21 targetSdkVersion 28 //21 io.dcloud.PandoraEntry apk入口时 targetSDKVersion>=21
versionCode 100
versionName "1.0.0"
versionCode 110
versionName "1.1.0"
multiDexEnabled true multiDexEnabled true
ndk { ndk {
// abiFilters 'x86','armeabi-v7a' // abiFilters 'x86','armeabi-v7a'

2
app/src/main/assets/apps/__UNI__3B4D40B/www/__uniappview.html

@ -16,7 +16,7 @@
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="uni-app-view.umd.js"></script> <script src="uni-app-view.umd.js"></script>
<script src="app-wxs.js"></script>
<script src="app-renderjs.js"></script> <script src="app-renderjs.js"></script>
</body> </body>

6
app/src/main/assets/apps/__UNI__3B4D40B/www/app-config-service.js
File diff suppressed because it is too large
View File

45
app/src/main/assets/apps/__UNI__3B4D40B/www/app-renderjs.js
File diff suppressed because it is too large
View File

7
app/src/main/assets/apps/__UNI__3B4D40B/www/app-service.js
File diff suppressed because it is too large
View File

1
app/src/main/assets/apps/__UNI__3B4D40B/www/app.css
File diff suppressed because it is too large
View File

2
app/src/main/assets/apps/__UNI__3B4D40B/www/manifest.json

@ -1 +1 @@
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__3B4D40B","name":"checkoutPad_uni_app","version":{"name":"1.0.0","code":"100"},"description":"uni-app 框架示例,一套代码,同时发行到iOS、Android、H5、小程序等多个平台,请使用手机扫码快速体验 uni-app 的强大功能","developer":{"name":"","email":"","url":""},"permissions":{"OAuth":{},"Payment":{},"Push":{},"Share":{},"Speech":{},"VideoPlayer":{},"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"id":"1","kernel":"WKWebview","uniNView":{"path":"pages/tabBar/component/component.js"}},"usingComponents":true,"nvueCompiler":"uni-app","nvueStyleCompiler":"uni-app","compilerVersion":3,"uniStatistics":{"version":"2","enable":true},"statusbar":{"immersed":"supportedDevice","style":"light","background":"#007AFF"},"allowsInlineMediaPlayback":true,"safearea":{"background":"#F8F8F8","bottom":{"offset":"auto"}},"uni-app":{"control":"uni-v3","vueVersion":"3","compilerVersion":"3.99","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"fast","webView":{"minUserAgentVersion":"49.0"}},"tabBar":{"position":"bottom","color":"#7A7E83","selectedColor":"#007AFF","borderStyle":"rgba(0,0,0,0.4)","blurEffect":"none","fontSize":"10px","iconWidth":"24px","spacing":"3px","height":"50px","backgroundColor":"#F8F8F8","list":[{"pagePath":"pages/tabBar/component/component","iconPath":"/static/component.png","selectedIconPath":"/static/componentHL.png","text":"内置组件"},{"pagePath":"pages/tabBar/API/API","iconPath":"/static/api.png","selectedIconPath":"/static/apiHL.png","text":"接口"},{"pagePath":"pages/tabBar/extUI/extUI","iconPath":"/static/extui.png","selectedIconPath":"/static/extuiHL.png","text":"扩展组件"},{"pagePath":"pages/tabBar/template/template","iconPath":"/static/template.png","selectedIconPath":"/static/templateHL.png","text":"模板"}],"selectedIndex":0,"shown":true,"child":["lauchwebview"],"selected":0}},"screenOrientation":["portrait-primary","portrait-secondary"]}
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__3B4D40B","name":"欧轩收银端","version":{"name":"1.0.0","code":"100"},"description":"","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"usingComponents":true,"nvueStyleCompiler":"uni-app","compilerVersion":3,"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"uniStatistics":{"enable":false},"allowsInlineMediaPlayback":true,"uni-app":{"control":"uni-v3","vueVersion":"3","compilerVersion":"3.99","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal","webView":{"minUserAgentVersion":"49.0"}}},"launch_path":"__uniappview.html"}

2
uniapp_project_code/src/manifest.json

@ -1,6 +1,6 @@
{ {
"name" : "欧轩收银端", "name" : "欧轩收银端",
"appid" : "",
"appid" : "__UNI__3B4D40B",
"description" : "", "description" : "",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "100", "versionCode" : "100",

59
uniapp_project_code/src/pages/login/index.vue

@ -13,7 +13,9 @@
></login-form> ></login-form>
</view> </view>
<view class="li-tip">*登录账号密码请从pc端后台管理设备运营管理平板管理里获取</view>
<view class="li-tip" @click="testPrinter">*登录账号密码请从pc端后台管理设备运营管理平板管理里获取</view>
<view class="li-tip" @click="testPH">*登录账号密码请从pc端后台管理222222里获取</view>
<view class="li-btn"> <view class="li-btn">
<login-button @click="clickLogin">登录</login-button> <login-button @click="clickLogin">登录</login-button>
</view> </view>
@ -23,6 +25,14 @@
</template> </template>
<script setup> <script setup>
// #ifdef APP-PLUS
// const modal = uni.requireNativePlugin('modal');
const ox_pad_printer = uni.requireNativePlugin('OX_Pad_Printer');
const ph_module = uni.requireNativePlugin('Ph-Module');
const tmodule = uni.requireNativePlugin('TestModule');
// #endif
import loginBackground from '@/components/login/background.vue'; import loginBackground from '@/components/login/background.vue';
import logoVue from '@/components/login/logo.vue'; import logoVue from '@/components/login/logo.vue';
import loginForm from '@/components/login/form.vue'; import loginForm from '@/components/login/form.vue';
@ -42,7 +52,8 @@
} from 'vue' } from 'vue'
import { onLoad,onReady } from '@dcloudio/uni-app'; import { onLoad,onReady } from '@dcloudio/uni-app';
import md5 from '@/utils/md5.js' import md5 from '@/utils/md5.js'
import print from "@/utils/print";
onReady(async () => { onReady(async () => {
autoLogin() autoLogin()
@ -58,6 +69,50 @@
const update_brand_id = (val)=>{brand_id.value = val} const update_brand_id = (val)=>{brand_id.value = val}
//,, //,,
function testPH(){
tmodule.testAsyncFunc({
'testPrinter':"testPrinter",
})
}
function testPrinter2(){
ox_pad_printer.execAPI({
'testPrinter111':"testPrinter111",
})
}
function testPrinter(){
console.log("OX_Pad_Printer test------begin---!")
// OX_Pad_Printer.execAPI_Printer(
// {
// 'testPrinter':"testPrinter" ,
// },
// ret => {
// console.log("testPrinter " + JSON.stringify(ret))
// }
// );
let obj = print.resetOXPrintInfo(print.testPrintInfo)
ox_pad_printer.execAPI({
api_name:"doPrint",
value:obj
},ret => {
console.log("testPrinter: " + JSON.stringify(ret))
})
// OX_Pad_Printer.execAPI_Printer(
// {
// 'api_name': "doPrint",
// // 'value': obj
// },
// ret => {
// console.log("testPrinter " + JSON.stringify(ret))
// }
// );
// console.log(123,print.testPrintInfo,print.resetOXPrintInfo(print.testPrintInfo))
}
function testmd5(){ function testmd5(){
console.log("testmd5-------------------") console.log("testmd5-------------------")
let str = "123123" let str = "123123"

16
uniplugin_padprinter/build.gradle

@ -29,16 +29,28 @@ android {
} }
dependencies { dependencies {
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
// compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar'])
// implementation 'androidx.appcompat:appcompat:1.2.0' // implementation 'androidx.appcompat:appcompat:1.2.0'
// implementation 'com.google.android.material:material:1.2.1' // implementation 'com.google.android.material:material:1.2.1'
// testImplementation 'junit:junit:4.+' // testImplementation 'junit:junit:4.+'
// androidTestImplementation 'androidx.test.ext:junit:1.1.2' // androidTestImplementation 'androidx.test.ext:junit:1.1.2'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' // androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar'])
// implementation fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar'])
// compileOnly 'com.alibaba:fastjson:1.1.46.android' // compileOnly 'com.alibaba:fastjson:1.1.46.android'
compileOnly 'com.alibaba:fastjson:1.2.83' //uni离线SDK升级后升级
// compileOnly 'com.alibaba:fastjson:1.2.83' //uni离线SDK升级后升级
implementation files('libs\\printersdkv5.7.2.jar') implementation files('libs\\printersdkv5.7.2.jar')
//
compileOnly 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
compileOnly 'androidx.core:core:1.1.0'
compileOnly 'androidx.fragment:fragment:1.1.0'
compileOnly 'androidx.appcompat:appcompat:1.1.0'
compileOnly 'androidx.recyclerview:recyclerview:1.1.0'
compileOnly 'com.alibaba:fastjson:1.2.83'
compileOnly fileTree(include: ['uniapp-v8-release.aar'], dir: '../app/libs')
} }

3
uniplugin_padprinter/proguard-rules.pro

@ -18,4 +18,5 @@
# If you keep the line number information, uncomment this to # If you keep the line number information, uncomment this to
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
-keep public class * extends io.dcloud.feature.uniapp.common.UniModule{*;}

2
uniplugin_padprinter/src/main/AndroidManifest.xml

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--<?xml version="1.0" encoding="utf-8"?>-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.zmt.padprinter"> package="net.zmt.padprinter">

59
uniplugin_padprinter/src/main/java/net/zmt/padprinter/Helper/Printer_Helper.java

@ -9,7 +9,6 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Resources;
import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager; import android.hardware.usb.UsbManager;
import android.os.Handler; import android.os.Handler;
@ -17,7 +16,7 @@ import android.os.Message;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import com.printer.sdk.PrinterConstants;
import com.alibaba.fastjson.JSONArray;
import com.printer.sdk.PrinterInstance; import com.printer.sdk.PrinterInstance;
import com.printer.sdk.PrinterConstants.Command; import com.printer.sdk.PrinterConstants.Command;
import com.printer.sdk.PrinterConstants.Connect; import com.printer.sdk.PrinterConstants.Connect;
@ -61,6 +60,33 @@ public class Printer_Helper {
this.mContext = application.getApplicationContext(); this.mContext = application.getApplicationContext();
} }
public void doPrint(JSONArray printList){
Log.d(TAG, "TestPrinter: 1");
UsbManager manager = (UsbManager) mContext.getSystemService(mContext.USB_SERVICE);
Log.d(TAG, "TestPrinter: 2"+manager.getDeviceList().toString());
myPrinter = PrinterInstance.mPrinter;
usbAutoConn(manager);
if (myPrinter.equals(null)){
Log.d(TAG, "TestPrinter: null");
myPrinter = PrinterInstance.mPrinter;
}else{
Log.d(TAG, "TestPrinter: not null---"+myPrinter.toString());
}
Log.d(TAG, "TestPrinter: "+myPrinter.getCharsetName());
Log.d(TAG, "TestPrinter_getCurrentStatus: "+myPrinter.getCurrentStatus());
new Thread(new Runnable() {
public void run() {
// XTUtils.printNote(application.getResources(), myPrinter);
// XTUtils.printTable1(application.getResources(), myPrinter);
printOXTable(myPrinter,printList);
}
}).start();
}
public void TestPrinter(Application application){ public void TestPrinter(Application application){
Log.d(TAG, "TestPrinter: 1"); Log.d(TAG, "TestPrinter: 1");
UsbManager manager = (UsbManager) application.getSystemService(application.USB_SERVICE); UsbManager manager = (UsbManager) application.getSystemService(application.USB_SERVICE);
@ -88,14 +114,15 @@ public class Printer_Helper {
} }
/** /**
* *
* @Description: 打印需求定制表格小票 TODO:跟后台约定打印数据格式后改写 * @Description: 打印需求定制表格小票 TODO:跟后台约定打印数据格式后改写
* @param * @param
* @return void * @return void
*/ */
public static void printOXTable(PrinterInstance mPrinter){
public static void printOXTable(PrinterInstance mPrinter){ //test func
//居中打印标题,完成后切回默认字体 //居中打印标题,完成后切回默认字体
mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_CENTER); mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_CENTER);
mPrinter.setFont(0, 1, 1, 0, 0); mPrinter.setFont(0, 1, 1, 0, 0);
@ -120,6 +147,30 @@ public class Printer_Helper {
mPrinter.cutPaper(65, 50); //65/66-半切/全切 mPrinter.cutPaper(65, 50); //65/66-半切/全切
} }
public static void printOXTable(PrinterInstance mPrinter, JSONArray printList){
//居中打印标题,完成后切回默认字体
mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_CENTER);
mPrinter.setFont(0, 1, 1, 0, 0);
mPrinter.printText("零售小票" + "\n");
mPrinter.setPrinter(Command.ALIGN, Command.ALIGN_LEFT);
mPrinter.setFont(0, 0, 0, 0, 0);
String column = "品名;数量;单价;金额";
Table table = null;
table = new Table(column, ";", new int[] { 12, 6, 7, 7 });
for (int i = 0; i < printList.size(); i++) {
String value = printList.getString (i);
System.out.println ("Value at index " + i + ": " + value);
table.addRow(value);
}
mPrinter.printTable(table);
// mPrinter.setPrinter(Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2); // 打印并走纸2行
mPrinter.cutPaper(65, 50); //65/66-半切/全切
}
@SuppressLint({"InlinedApi", "NewApi", "WrongConstant"}) @SuppressLint({"InlinedApi", "NewApi", "WrongConstant"})
public void usbAutoConn(UsbManager manager) { public void usbAutoConn(UsbManager manager) {

76
uniplugin_padprinter/src/main/java/net/zmt/padprinter/UniPluginPadPrinter.java

@ -4,12 +4,17 @@ package net.zmt.padprinter;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
//import org.json.JSONException;
//import org.json.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import io.dcloud.feature.uniapp.annotation.UniJSMethod; import io.dcloud.feature.uniapp.annotation.UniJSMethod;
import io.dcloud.feature.uniapp.bridge.UniJSCallback; import io.dcloud.feature.uniapp.bridge.UniJSCallback;
import io.dcloud.feature.uniapp.common.UniModule; import io.dcloud.feature.uniapp.common.UniModule;
import net.zmt.padprinter.Helper.Printer_Helper;
public class UniPluginPadPrinter extends UniModule { public class UniPluginPadPrinter extends UniModule {
@ -27,54 +32,61 @@ public class UniPluginPadPrinter extends UniModule {
// public void setMjscallbackCard(final UniJSCallback jb){ // public void setMjscallbackCard(final UniJSCallback jb){
// this.mjscallbackPh = jb; // this.mjscallbackPh = jb;
// } // }
@UniJSMethod(uiThread = true)
public void execAPI_V4(JSONObject options, UniJSCallback callback) throws JSONException {//执行简单api_name的控制方法
Log.e(TAG, "execAPI--"+options+"----");
//run ui thread
@UniJSMethod(uiThread = false)
public void execAPI(JSONObject options, UniJSCallback callback) throws JSONException {
Log.e(TAG, "execAPI--"+options.toString());
if(callback != null) { if(callback != null) {
Context ct = mUniSDKInstance.getContext();
String api_name = options.getString("api_name"); String api_name = options.getString("api_name");
//判断不同的api_name, 执行不同的操作
String code = "0";
String reason = api_name;
String status = null;
if(api_name.equals("doPrint")){
Context ct = mUniSDKInstance.getContext();
JSONArray printList = options.getJSONArray("value");
boolean isPhAvailable = false;
for (int i = 0; i < printList.size(); i++) {
String value = printList.getString (i);
System.out.println ("Value at index " + i + ": " + value);
}
try {
Class.forName("com.peripheral.library.PhController");
isPhAvailable = true;
} catch (ClassNotFoundException e) {
e.printStackTrace();
Log.e(TAG, "Ph SDK 不可用"+e);
new Printer_Helper(ct).doPrint(printList);
} }
if (isPhAvailable) {
// lztek SDK 可用的代码
} else {
// lztek SDK 不可用的代码
// 执行其他逻辑或提示用户
return;
}
JSONObject data = new JSONObject();
data.put("code", "success");
callback.invoke(data);
//callback.invokeAndKeepAlive(data);
}
}
try{
}catch ( Exception e){
Log.e(TAG, "execAPI--"+e.toString());
code = "error";
reason = e.toString();
}
@UniJSMethod(uiThread = true)
public void execAPI_Printer1(JSONObject options, UniJSCallback callback) throws JSONException {//执行简单api_name的控制方法
Log.e(TAG, "execAPI_Printer execAPI--"+options+"----");
if(callback != null) {
Context ct = mUniSDKInstance.getContext();
// new Printer_Helper(ct).doPrint(); //启动时自动连接打印机并测试打印
String api_name = options.getString("api_name");
//判断不同的api_name, 执行不同的操作
String code = "0";
String reason = api_name;
String status = null;
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
data.put("code", code); data.put("code", code);
data.put("reason", reason); data.put("reason", reason);
data.put("status", status); data.put("status", status);
Log.e(TAG, "PhController execAPI--end");
Log.e(TAG, "execAPI_Printer execAPI--end");
callback.invoke(data); callback.invoke(data);
//callback.invokeAndKeepAlive(data); //callback.invokeAndKeepAlive(data);
}else{ }else{
Log.e(TAG, "PhController execAPI--callback null");
Log.e(TAG, "execAPI_Printer execAPI--callback null");
} }
} }

Loading…
Cancel
Save