Эх сурвалжийг харах

[dev]
1、优化打印流程
2、清除无效参数
3、合并三个接口及完成接口调用后的路由跳转到一个方法depoly中
4、进入当前页面时,需要从本地缓存中获取ip并传给printInfo.value.ip
5、清除打印相关的无效
6、配置打印机时,在打印后执行depoly

Neo 1 жил өмнө
parent
commit
ae6414a5f9
1 өөрчлөгдсөн 50 нэмэгдсэн , 66 устгасан
  1. 50 66
      pages/edit/edit.vue

+ 50 - 66
pages/edit/edit.vue

@@ -173,9 +173,10 @@ import { onLoad } from '@dcloudio/uni-app'
 
 const printInfo = ref({
 	ip: '',
-	port: '9100'
+	port: '9100',
 })
 
+
 const urlConfig = ref('http://zhongyao.fscuc.cn')
 // #ifdef APP-PLUS 
 const plug= uni.requireNativePlugin('Html5app-Gprinter');
@@ -186,6 +187,7 @@ const connectThenPrint = ()=>{
 	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){
+			uni.$showMsg('打印机连接成功!', 500)
 			plug.connectIP({"ip":printInfo.value.ip,"port":printInfo.value.port},ret=>{
 				console.log('connectPrint>>ret',ret)
 				const res = JSON.parse(JSON.stringify(ret))
@@ -194,31 +196,22 @@ const connectThenPrint = ()=>{
 					// initPrint.value = true
 					console.log('printInfo>>>', printInfo.value)
 					uni.setStorageSync('hasPrinter', '1')
+					
 					uni.setStorageSync('printerIp', printInfo.value.ip)
 					// _this.tip=JSON.stringify(ret);
 					// console.log(_this.tip);	
 					// 关闭配置弹窗
 					proxy.$refs.printerDialog.close()
-					printerTsc()
+						printerTsc()
 					
-					// // 打印成功后调用/userPrescription/sendToUser
-					// const res1 =  sendToUser({
-					// 	token: uni.getStorageSync('token'),
-					// 	data: JSON.stringify({id:uni.getStorageSync('userId')})
-					// })
-					// console.log('sendToUser res1',res1)
-					// if (res1.code !== 200){
-					// 	uni.$showMsg(res1.msg, 2000)
-					// }
+					if(uni.getStorageSync('hasPrinter') == '1'){
+						deploy()
+					}
 					
-					uni.redirectTo({
-						url:"/pages/index/index"
-					})
 					
 				} else{
 					uni.$showMsg('打印机连接失败,请重试!', 500)
 				}
-				
 			});
 		} else{
 			uni.$showMsg('ip地址有误,请重试!', 2000)
@@ -374,7 +367,7 @@ const editForm =ref({
 	coreId: ''
 })
 onMounted(() => {
-
+printInfo.value.ip = uni.getStorageSync('printerIp')
 })
 
 
@@ -520,6 +513,7 @@ const cancelConfig = () => {
 
 const handleSubmit = debounce(async()=>{
 	console.log('handleSubmit>>>',editForm.value)
+	console.log('isPrint.value>>', isPrint.value)
 	
 	if(isPrint.value){
 		// 直接调用接口,然后打印
@@ -539,8 +533,8 @@ const handleSubmit = debounce(async()=>{
 		// todo 判断打印机是否连接成功,hasPrinter=='1'连接成功则开始打印,否则弹窗配置打印机,配置成功打印机后关闭弹窗直接打印
 		if(uni.getStorageSync('hasPrinter') == '1'){
 			printerTsc()
-			console.log("uni.getStorageSync('token')",uni.getStorageSync('token'))
 			
+			const tmp  = await deploy()
 			uni.redirectTo({
 				url:"/pages/index/index"
 			})
@@ -572,17 +566,7 @@ const dialogConfirm = debounce(async()=>{
 	if(uni.getStorageSync('hasPrinter') == '1'){
 		printerTsc()
 		console.log("uni.getStorageSync('token')",uni.getStorageSync('token'))
-		// const res = await sendToUser({
-		// 	token: uni.getStorageSync('token'),
-		// 	data: JSON.stringify({id:uni.getStorageSync('userId')})
-		// })
-		// const ret = await updateOrderStatus({
-		// 	token: uni.getStorageSync('token'),
-		// 	data: {
-		// 		id:v.value.id,
-		// 		status:'1',
-		// 	}
-		// })
+		const ret1 = await deploy()
 		uni.redirectTo({
 			url:"/pages/index/index"
 		})
@@ -618,6 +602,42 @@ const dialogClose = debounce(async()=>{
 	})
 },500)
 
+const deploy = async() => {
+	const {data:res} = await saveDepoly({
+		token: uni.getStorageSync('token'),
+		data: JSON.stringify(editForm.value)
+	})
+	if(res.code===200){
+		console.log('depoly success>>>')				
+	}
+	const res1 =  await sendToUser({
+		token: uni.getStorageSync('token'),
+		data: JSON.stringify({id:uni.getStorageSync('userId')})
+	})
+	const ret2 =  await updateOrderStatus({
+		token: uni.getStorageSync('token'),
+		data: {
+			id:v.value.id,
+			status:'1',
+		}
+	})
+	console.log('updateOrderStatus >>ret2',ret2)
+	// 保存ip和端口
+	console.log("保存ip和端口", uni.getStorageSync('userId'),printInfo.value.ip, printInfo.value.port)
+	const res2 =  await setIp({
+		token: uni.getStorageSync('token'),
+		data: JSON.stringify({userId:uni.getStorageSync('userId'),ip:printInfo.value.ip,port:printInfo.value.port})
+	})
+	
+	if (res2.data.code !== 200){
+		// uni.$showMsg('保存ip和端口数据异常', 2000)
+		console.log("保存ip和端口数据异常", res2)
+	}
+	uni.redirectTo({
+		url:"/pages/index/index"
+	})
+}
+
 const selectUpload = debounce((e)=>{
 	uni.showLoading({
 			title: "上传中"
@@ -743,44 +763,8 @@ const printerTsc = ()=>{
 	// let _this=this;
 	
 	// #ifdef APP-PLUS
-	plug.printer({TSC:data}, ret => {
-		// _this.tip = JSON.stringify(ret);
-		// console.log('print data', data)
-		// console.log('ret',ret)
-		// console.log('ret.code',ret.code)
-		// const err = JSON.parse(ret)
-		// console.log('err',err)
-		if(ret.code==1){
-			uni.$showMsg('打印失败,打印机未连接,请先连接打印机', 2000)
-			console.log('666')
-		} else {
-			const {data:res} = saveDepoly({
-				token: uni.getStorageSync('token'),
-				data: JSON.stringify(editForm.value)
-			})
-			if(res.code===200){
-				console.log('depoly success>>>')				
-			}
-			const res1 =  sendToUser({
-				token: uni.getStorageSync('token'),
-				data: JSON.stringify({id:uni.getStorageSync('userId')})
-			})
-			const ret =  updateOrderStatus({
-				token: uni.getStorageSync('token'),
-				data: {
-					id:v.value.id,
-					status:'1',
-				}
-			})
-			// 保持ip和端口
-			const res2 =  setIp({
-				token: uni.getStorageSync('token'),
-				data: JSON.stringify({userId:uni.getStorageSync('userId'),ip:printInfo.value.ip,port:printInfo.value.port})
-			})
-			if (res2.code !== 200){
-				uni.$showMsg(res2.msg, 2000)
-			}
-		}
+	plug.printer({TSC:data}, (ret) => {
+		const tip = JSON.stringify(ret);
 	})
 	// #endif