瀏覽代碼

[dev]
1、增加ws请求接口
2、增加pad端打印native插件
3、增加打印标签功能

天梦 2 年之前
父節點
當前提交
54c87f3baa
共有 8 個文件被更改,包括 375 次插入155 次删除
  1. 1 1
      App.vue
  2. 14 0
      components/nav-bar/nav-bar.vue
  3. 92 0
      components/print-config/print-config.vue
  4. 104 87
      manifest.json
  5. 60 63
      pages.json
  6. 104 4
      pages/edit/edit.vue
  7. 二進制
      static/OpenSans-Bold.ttf
  8. 二進制
      static/Roboto-Spell.ttf

+ 1 - 1
App.vue

@@ -34,7 +34,7 @@ onShow(()=>{
 		try {
 			//建立socket连接
 			// websocket.connectSocket(`wss://zhongyao.fscuc.cn/webSocket/sentMessage/${data.userId}`,() => {
-				websocket.connectSocket(`wss://zhongyao.fscuc.cn/webSocket/sentMessage/${data.userId}`,() => {
+				websocket.connectSocket(`ws://zy-web.fscuc.cn:8006/websocket/${data.userId}`,() => {
 				//如果连接成功则发送心跳检测
 				heartBeatTest()
 			})

+ 14 - 0
components/nav-bar/nav-bar.vue

@@ -2,6 +2,7 @@
   <view class="nav">
 		<view class="navbar">
 			<button class="scanbara" @click="handleScanbara">复核扫码</button>
+			<button class="scanbara" @click="gotoPrint">打印设置</button>
 			<view class="status">{{props.userInfo.workStatus === '0'?"接单中":"暂停接单"}}</view>
 			<view class="userinfo">
 				<button class="lef" @click="dialogToggle">{{props.userInfo.workStatus === '0'?"暂停接单":"开始接单"}}</button>
@@ -26,6 +27,11 @@
 				@close="dialogClose"></uni-popup-dialog>
 		</uni-popup>
 	</view>
+	<view class="print">
+		<uni-popup ref="alertPrint" type="dialog">
+			<print-config @emit-close="emitclose"></print-config>
+		</uni-popup>
+	</view>
 </template>
 
 <script>
@@ -71,6 +77,10 @@ const dialogClose = ()=>{
 	console.log('guanbi')
 }
 
+const emitclose =()=>{
+	proxy.$refs.alertPrint.close()
+}
+
 const handleChange =async()=>{
 	
 	console.log("props.userInfo.workStatus》》》", props.userInfo.workStatus)
@@ -129,6 +139,10 @@ const handleLogout = async()=>{
 	
 }
 
+const gotoPrint = ()=>{
+	proxy.$refs.alertPrint.open()
+}
+
 </script>
 
 <style lang="scss">

+ 92 - 0
components/print-config/print-config.vue

@@ -0,0 +1,92 @@
+<template>
+  <view class="printconfig">
+		<view v-if="initPrint==false" class="initPrint">
+			<view class="title">使用须知</view>
+			<view class="tips">使用前先连接wifi打印机</view>
+			<uni-easyinput class="input" confirm-type="done" v-model="printInfo.ip" placeholder="请输入打印机ip地址" @confirm="connectPrint"></uni-easyinput>
+		</view>
+		<view v-else class="printInfo">
+			<view>当前连接打印机</view>
+			<uni-easyinput disabled v-model="printInfo.ip" placeholder="请输入打印机ip地址"></uni-easyinput>
+			<button @click="resetPrint">断开连接</button>
+		</view>
+  </view>
+</template>
+
+<script>
+  export default {
+    name: 'printConfig'
+  }
+</script>
+
+<script setup>
+import { onMounted, ref } from 'vue'
+
+const plug= uni.requireNativePlugin('Html5app-Gprinter');
+const initPrint = ref(false)
+const printInfo = ref({
+	ip:'',
+	port:'9100'
+})
+onMounted(() => {
+
+})
+
+const emit = defineEmits(['emitClose'])
+
+const connectPrint = ()=>{
+	const ipReg = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
+	if(ipReg.test(printInfo.value.ip)){
+		if(RegExp.$1<256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256){
+			plug.connectIP({"ip":printInfo.value.ip,"port":printInfo.value.port},ret=>{
+				console.log('connectPrint>>ret',ret)
+				const res = JSON.parse(JSON.stringify(ret))
+				console.log('connectPrint>>res',res.code)
+				if(res.code==3){
+					initPrint.value = true
+					// _this.tip=JSON.stringify(ret);
+					// console.log(_this.tip);	
+					// 关闭配置页操作
+					emit('emitClose')
+				} else{
+					uni.$showMsg('打印机连接失败,请重试!', 500)
+				}
+				
+			});
+		} else{
+			uni.$showMsg('ip地址有误,请重试!', 2000)
+		}
+	}
+}
+
+const resetPrint = ()=>{
+	plug.disconnect({},ret=>{
+		uni.$showMsg(ret.msg, 2000)
+		initPrint.value = false
+		// console.log(_this.tip);
+	});
+}
+
+
+</script>
+
+<style lang="scss">
+  .printconfig{
+		background-color: #fff;
+		width: 500rpx;
+		height: 300rpx;
+		padding: 20rpx;
+		.initPrint{
+			.title{
+				font-size: 20rpx;
+			}
+			.tips{
+				font-size: 16rpx;
+			}
+			.input{
+				width: 300rpx;
+			}
+		}
+		
+	}
+</style>

+ 104 - 87
manifest.json

@@ -1,87 +1,104 @@
-{
-	"name": "中药处方煎配",
-	"appid": "__UNI__F501A17",
-	"description": "",
-	"versionName": "1.0.0",
-	"versionCode": "100",
-	"transformPx": false,
-	/* 5+App特有相关 */
-	"app-plus": {
-		"usingComponents": true,
-		"nvueStyleCompiler": "uni-app",
-		"compilerVersion": 3,
-		"debug": true,
-		"splashscreen": {
-			"alwaysShowBeforeRender": true,
-			"waiting": true,
-			"autoclose": true,
-			"delay": 0
-		},
-		/* 模块配置 */
-		"modules": {
-			"Barcode": {}
-		},
-		/* 应用发布信息 */
-		"distribute": {
-			/* android打包配置 */
-			"android": {
-				"permissions": [
-					"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
-					"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
-					"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
-					"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
-					"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
-					"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
-					"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
-					"<uses-permission android:name=\"android.permission.CAMERA\"/>",
-					"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
-					"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
-					"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
-					"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
-					"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
-					"<uses-feature android:name=\"android.hardware.camera\"/>",
-					"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
-				]
-			},
-			/* ios打包配置 */
-			"ios": {},
-			/* SDK配置 */
-			"sdkConfigs": {}
-		}
-	},
-	/* 快应用特有相关 */
-	"quickapp": {},
-	/* 小程序特有相关 */
-	"mp-weixin": {
-		"appid": "",
-		"setting": {
-			"urlCheck": false,
-			"es6": true,
-			"minified": true
-			
-		},
-		"usingComponents": true,
-		"lazyCodeLoading": "requiredComponents"
-	},
-	"mp-alipay": {
-		"usingComponents": true
-	},
-	"mp-baidu": {
-		"usingComponents": true
-	},
-	"mp-toutiao": {
-		"usingComponents": true
-	},
-	"uniStatistics": {
-		"enable": false
-	},
-	"vueVersion": "3",
-	
-	"h5": {
-		"devServer": {
-			// host:'0.0.0.0',
-			// port:5173,
-			
-		}
-	}
-}
+{
+    "name" : "中药处方煎配",
+    "appid" : "__UNI__F501A17",
+    "description" : "",
+    "versionName" : "1.0.0",
+    "versionCode" : 101,
+    "transformPx" : false,
+    /* 5+App特有相关 */
+    "app-plus" : {
+        "usingComponents" : true,
+        "nvueStyleCompiler" : "uni-app",
+        "compilerVersion" : 3,
+        "debug" : true,
+        "splashscreen" : {
+            "alwaysShowBeforeRender" : true,
+            "waiting" : true,
+            "autoclose" : true,
+            "delay" : 0
+        },
+        /* 模块配置 */
+        "modules" : {
+            "Barcode" : {}
+        },
+        /* 应用发布信息 */
+        "distribute" : {
+            /* android打包配置 */
+            "android" : {
+                "permissions" : [
+                    "<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
+                    "<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
+                    "<uses-permission android:name=\"android.permission.VIBRATE\"/>",
+                    "<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
+                    "<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
+                    "<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
+                    "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
+                    "<uses-permission android:name=\"android.permission.CAMERA\"/>",
+                    "<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
+                    "<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
+                    "<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
+                    "<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
+                    "<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
+                    "<uses-feature android:name=\"android.hardware.camera\"/>",
+                    "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
+                ]
+            },
+            /* ios打包配置 */
+            "ios" : {
+                "dSYMs" : false
+            },
+            /* SDK配置 */
+            "sdkConfigs" : {
+                "ad" : {}
+            }
+        },
+        "nativePlugins" : {
+            "Html5app-Gprinter" : {
+                "__plugin_info__" : {
+                    "name" : "Android 和 IOS 佳博 蓝牙小票 标签 打印插件支持 ESC 、TSC、CPCL 指令 - [试用版,仅用于自定义调试基座]",
+                    "description" : "Android / IOS 小票 、标签 打印机插件,QQ交流群:891416757",
+                    "platforms" : "Android,iOS",
+                    "url" : "https://ext.dcloud.net.cn/plugin?id=462",
+                    "android_package_name" : "",
+                    "ios_bundle_id" : "",
+                    "isCloud" : true,
+                    "bought" : 0,
+                    "pid" : "462",
+                    "parameters" : {}
+                }
+            }
+        }
+    },
+    /* 快应用特有相关 */
+    "quickapp" : {},
+    /* 小程序特有相关 */
+    "mp-weixin" : {
+        "appid" : "",
+        "setting" : {
+            "urlCheck" : false,
+            "es6" : true,
+            "minified" : true
+        },
+        "usingComponents" : true,
+        "lazyCodeLoading" : "requiredComponents"
+    },
+    "mp-alipay" : {
+        "usingComponents" : true
+    },
+    "mp-baidu" : {
+        "usingComponents" : true
+    },
+    "mp-toutiao" : {
+        "usingComponents" : true
+    },
+    "uniStatistics" : {
+        "enable" : false
+    },
+    "vueVersion" : "3",
+    "h5" : {
+        "devServer" : {}
+    }
+}
+// host:'0.0.0.0',
+// port:5173,
+

+ 60 - 63
pages.json

@@ -1,72 +1,69 @@
 {
-	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
-		{
-		      "path" : "pages/login/login",
-		      "style" :                                                                                    
-		      {
-		          "navigationBarTitleText": "",
-		          "enablePullDownRefresh": false,
-							"navigationStyle": "custom"
-		      }
-		      
-		  },
-		{
-			"path": "pages/index/index",
-			"style": {
-				// "navigationBarTitleText": "uni-app",
-				"navigationStyle": "custom"
-			}
-		}
-        ,{
+    "pages" : [
+        //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
+        {
+            "path" : "pages/login/login",
+            "style" : {
+                "navigationBarTitleText" : "",
+                "enablePullDownRefresh" : false,
+                "navigationStyle" : "custom"
+            }
+        },
+        {
+            "path" : "pages/index/index",
+            "style" : {
+                // "navigationBarTitleText": "uni-app",
+                "navigationStyle" : "custom"
+            }
+        },
+        {
             "path" : "pages/detail/detail",
-            "style" :                                                                                    
-            {
-                "navigationBarTitleText": "调配详情",
-								"navigationStyle": "custom",
-                "enablePullDownRefresh": false
+            "style" : {
+                "navigationBarTitleText" : "调配详情",
+                "navigationStyle" : "custom",
+                "enablePullDownRefresh" : false
             }
-            
-        }
-        ,{
+        },
+        {
             "path" : "pages/edit/edit",
-            "style" :                                                                                    
-            {
-                "navigationBarTitleText": "",
-								"navigationStyle": "custom",
-                "enablePullDownRefresh": false
+            "style" : {
+                "navigationBarTitleText" : "",
+                "navigationStyle" : "custom",
+                "enablePullDownRefresh" : false
+            }
+        },
+        {
+            "path" : "pages/review/review",
+            "style" : {
+                "navigationBarTitleText" : "",
+                "enablePullDownRefresh" : false,
+                "navigationStyle" : "custom"
             }
+        },
+        {
+            "path" : "components/print-config/print-config",
+            "style" : {}
         }
-        
-        ,{
-            "path" : "pages/review/review",
-            "style" :                                                                                    
+    ],
+    "globalStyle" : {
+        "navigationBarTextStyle" : "black",
+        "navigationBarTitleText" : "中药处方煎配",
+        "navigationBarBackgroundColor" : "#F8F8F8",
+        "backgroundColor" : "#F8F8F8",
+        "rpxCalcMaxDeviceWidth" : 0,
+        // "rpxCalcIncludeWidth": 2000,
+        "rpxCalcBaseDeviceWidth" : 686
+    },
+    "uniIdRouter" : {},
+    "condition" : {
+        //模式配置,仅开发期间生效
+        "current" : 0, //当前激活的模式(list 的索引项)
+        "list" : [
             {
-                "navigationBarTitleText": "",
-                "enablePullDownRefresh": false,
-								"navigationStyle": "custom"
+                "name" : "", //模式名称
+                "path" : "", //启动页面,必选
+                "query" : "" //启动参数,在页面的onLoad函数里面得到
             }
-            
-        }
-    ],
-	"globalStyle": {
-		"navigationBarTextStyle": "black",
-		"navigationBarTitleText": "中药处方煎配",
-		"navigationBarBackgroundColor": "#F8F8F8",
-		"backgroundColor": "#F8F8F8",
-		"rpxCalcMaxDeviceWidth": 0,
-		// "rpxCalcIncludeWidth": 2000,
-		"rpxCalcBaseDeviceWidth": 686
-		
-	},
-	"uniIdRouter": {},
-	"condition" : { //模式配置,仅开发期间生效
-		"current": 0, //当前激活的模式(list 的索引项)
-		"list": [
-			{
-				"name": "", //模式名称
-				"path": "", //启动页面,必选
-				"query": "" //启动参数,在页面的onLoad函数里面得到
-			}
-		]
-	}
+        ]
+    }
 }

+ 104 - 4
pages/edit/edit.vue

@@ -159,6 +159,10 @@ import { saveDepoly } from '@/static/js/api.js'
 import { onLoad } from '@dcloudio/uni-app'
 
 const urlConfig = ref('http://zhongyao.fscuc.cn')
+
+const plug= uni.requireNativePlugin('Html5app-Gprinter');
+
+
 // const preseId = ref(11220822134401)
 const preseObj = ref({
 		code: '',
@@ -217,6 +221,7 @@ const v=ref({
 	symName:'脾胃虚寒证',
 	prescriptionTime:'2023-06-01 15:58',
 	address:'浙江省某某事某某去某某事中医院门诊楼三楼302是',
+	birth:'',
 	rp:[
 		{matName:'车前子',matDose:'6',matUnitName:'g',tips:'包煎',sign:'医生签名'},
 		{matName:'车前子',matDose:'6',matUnitName:'g',tips:'先煎',sign:'医生签名'},
@@ -367,7 +372,7 @@ onLoad(async(options) => {
 		v.value.entrust = res.data.entrust,
 		v.value.rp = res.data.detailList
 		v.value.yljgName = res.data.yljgName || ''
-	 
+		v.value.birth = res.data.birth || ''
 		v.value.status = res.data.status,
 		console.log('res.data.status',res.data.status)
 		switch (res.data.status) {
@@ -456,9 +461,9 @@ const handleSubmit = async()=>{
 	}
 	if(isPrint.value){
 		// 直接调用接口,然后打印
-		print("#printMe")
+		// print("#printMe")
 		// 打印成功后调用/userPrescription/sendToUser
-		
+		const ret = printerTsc()
 		const res = await sendToUser({
 			token: uni.getStorageSync('token'),
 			data: JSON.stringify({id:uni.getStorageSync('userId')})
@@ -477,7 +482,7 @@ const handleSubmit = async()=>{
 
 const dialogConfirm = async()=>{
 	console.log('dialogConfirm直接调用接口,然后打印')
-	print("#printMe")
+	const ret = printerTsc()
 	// 打印成功后调用/userPrescription/sendToUser
 	const res = await sendToUser({
 			token: uni.getStorageSync('token'),
@@ -532,6 +537,101 @@ const selectUpload = (e)=>{
 	}
 }
 
+const printerTsc = ()=>{
+	
+	//制作标签格式,
+	let data=[];  //定义一个数组
+	let line={};  //每添加一个,代表一行字
+	
+	//设置标签纸大小
+	line={};
+	line.width=80; //mm
+	line.height=50; //mm
+	line.gap=2; //标签纸之间,间隙长度 mm
+	line.page=1; //打印几份
+	line.direction=0, //上下反面打印,0=>正方向,1=> 反方向
+	data.push(line); //每添加一个,代表一行字
+	
+	let filePath=plus.io.convertLocalFileSystemURL("static/OpenSans-Bold.ttf")
+	//添加文字
+	line={};
+	line.customText=v.value.yljgName;
+	line.x=100;
+	line.y=40;
+	line.fontSize=30;
+	line.fontPath=filePath;
+	data.push(line); //每添加一个,代表一行字
+	
+	//添加图片
+	// var imgage=plus.io.convertLocalFileSystemURL("static/gprinter.png"); 
+	// line={};
+	// line.image=imgage;
+	// line.x=20;
+	// line.y=65;
+	// line.width=80;
+	// data.push(line);
+	
+	
+	// //添加黑块
+	// line={};
+	// line.addBar={x:10,y:10,width:200,height:4};
+	// data.push(line);
+	
+	// //添加方框
+	// line={};
+	// line.addBox={x:10,y:25,xend:180,yend:50,thickness:2};
+	// data.push(line);
+					
+
+	// //添加二维码		
+	// line={};
+	// line.qrcode="https://www.baidu.com/";
+	// line.x=205; //横坐标
+	// line.y=25; //纵坐标
+	// line.width=3; //二维码大小,1-10 之间
+	// line.rotation=0;  // 角度:有四个值:0,90,180,270 
+	// data.push(line);
+
+				//添加条型码         
+	line={};
+	line.barcode=v.value.preNo;
+	line.x=50; //横坐标
+	line.y=150; //纵坐标
+	line.type="CODE128"; //条型码类型
+	line.height=160; //条型码高度
+	line.readable=true; //是否显示文字在条型下方
+	line.rotation=0;  // 角度:有四个值:0,90,180,270
+	data.push(line)
+	
+	//患者
+	line={};
+	line.text='患者:'+v.value.name+', '+v.value.sex+', '+v.value.age+'岁';
+	line.x=300;
+	line.y=180;
+	line.fontSize=14;
+	line.fontPath='';
+	data.push(line); //每添加一个,代表一行字
+	
+	//出生
+	line={};
+	line.customText='出生日期:'+v.value.birth;
+	line.x=300;
+	line.y=240;
+	line.fontSize=13;
+	line.fontPath='';
+	data.push(line); //每添加一个,代表一行字
+	
+	// let _this=this;
+	
+			
+	plug.printer({TSC:data}, ret => {
+		// _this.tip = JSON.stringify(ret);
+		console.log('print data', data)
+		console.log(ret)
+	})
+
+ }
+
 </script>
 
 <style lang="scss">

二進制
static/OpenSans-Bold.ttf


二進制
static/Roboto-Spell.ttf