lilei 3 vuotta sitten
vanhempi
commit
f0c4f7fb43

+ 21 - 5
components/kk-printer/index.vue

@@ -1,7 +1,7 @@
 <template>
 	<view class="kk-printer">
 		<view class="kk-printer-btn">
-			<u-button @tap="handlePrintTap" shape="circle" :custom-style="{background:$config('primaryColor')}" type="primary">{{isPrinting?printingText:defaultText}}</u-button>
+			<u-button @tap="handlePrintTap" :loading="isPrinting" shape="circle" :custom-style="{background:$config('primaryColor')}" type="primary">{{isPrinting?printingText:defaultText}}</u-button>
 		</view>
 		<view class="kk-shadow" :class="isShowSearch?'show':''" @tap="handleSearchClose">
 			<view class="kk-modal" @tap.stop="doNothing">
@@ -10,9 +10,14 @@
 						<view class="filter-title">根据SRRI过滤设备</view>
 						<slider @change="handleSRRIChange" max='-20' min='-100' value="-95" show-value/>
 					</view> -->
-					<view class="kk-filter-wrap">
+					<!-- <view class="kk-filter-wrap">
 						<view class="filter-title">根据蓝牙名过滤</view>
 						<input type="text"  placeholder-class="kk-placeholder-class" placeholder="请输入蓝牙名字或设备ID搜索" v-model="filterName" />
+					</view> -->
+					<view>
+						<view>注意事项:</view>
+						<view>1、连接打印机之前,先打开手机蓝牙开关</view>
+						<view>2、请检查打印机是否已被其它手机连接,如果是请关闭其它手机蓝牙,然后再用您的手机连接</view>
 					</view>
 					<view class="kk-btn-wrap">
 						<view class="kk-btn-item confirm-btn" @tap="searchBtnTap" v-if="!isSearching">
@@ -47,13 +52,14 @@
 									</view>
 								</view>
 								<view>
-									<u-icon :size="60" color="#55aaff" name="plus-circle"></u-icon>
+									<!-- <u-icon :size="60" color="#55aaff" name="plus-circle"></u-icon> -->
+									<u-button @tap="handleConnectDevice(item)" :loading="isConnecting" shape="circle" size="mini" :custom-style="{background:$config('primaryColor')}" type="primary">{{isConnecting?'连接中':'连接'}}</u-button>
 								</view>
 							</view>
 						</view>
 					</view>
 					<view style="margin-top: 20upx;">
-						<view style="text-align: center;padding: 20upx;border:2upx solid #eee;border-radius: 15upx;" @tap="handleSearchClose">取消打印</view>
+						<view v-if="!isConnecting" style="text-align: center;padding: 20upx;border:2upx solid #eee;border-radius: 15upx;" @tap="handleSearchClose">取消打印</view>
 					</view>
 				</view>
 			</view>
@@ -73,6 +79,8 @@
 				isPrinting:false,
 				//是否正在搜索设备
 				isSearching:false,
+				// 是否正在连接
+				isConnecting: false,
 				//是否显示蓝牙列表
 				isShowSearch:false,
 				//按蓝牙名过滤
@@ -199,7 +207,9 @@
 				this.devicesList = res;
 			},
 			handleSearchClose(){
-				this.isShowSearch = false
+				if(!this.isConnecting){
+					this.isShowSearch = false
+				}
 			},
 			handleSRRIChange(e){
 				this.filterRSSI = e.detail.value
@@ -222,6 +232,8 @@
 				let name = device.name;
 				this.deviceId = deviceId;
 				console.log('deviceId',this.deviceId)
+				this.isConnecting = true
+				this.stopSearchBtnTap()
 				uni.onBLEConnectionStateChange(function(res){
 					console.log('连接',res)
 					if(res.connected){
@@ -234,15 +246,19 @@
 							verticalAlign:'center'
 						})
 					}
+					_this.isConnecting = false
 			    })
 				blesdk.createBLEConnection(deviceId, this.onConnectSuccess, this.onConnectFail);
 			},
 			onConnectSuccess(res){
 				this.stopSearchBtnTap()
+				this.isConnecting = false
 				blesdk.getBLEDeviceServices(this.deviceId, this.onGetServicesSuccess, this.onGetServicesFail);
 			},
 			onConnectFail(err){
 				console.log('链接失败',err)
+				this.isConnecting = false
+				blesdk.catchToast(err.res)
 			},
 			onGetServicesSuccess(res){
 				console.log('获取服务',res)

+ 6 - 3
components/kk-printer/utils/bluetoolth.js

@@ -82,7 +82,8 @@ export function createBLEConnection(deviceId, sucess, fail) {
 	//连接蓝牙设备
 	console.log('连接蓝牙设备', deviceId);
 	uniAsyncPromise("createBLEConnection", {
-			deviceId
+			deviceId,
+			timeout: 10000
 		})
 		.then(res => {
 			//连接成功可选择停止搜索蓝牙
@@ -312,12 +313,14 @@ export function catchToast(err) {
 		10006: '当前连接已断开',
 		10007: '当前特征值不支持此操作',
 		10008: '系统上报异常',
-		10009: '系统版本低于 4.3 不支持BLE'
+		10009: '系统版本低于 4.3 不支持BLE',
+		10012: '连接超时,请检查打印机是否被其它手机连接中'
 	};
 	let coode = err.errCode ? err.errCode.toString() : '';
 	let msg = errMsg[coode];
 	plus.nativeUI.toast(msg || coode, {
 		align: 'center',
-		verticalAlign: 'center'
+		verticalAlign: 'center',
+		duration:'long'
 	});
 }

+ 39 - 0
package-lock.json

@@ -0,0 +1,39 @@
+{
+  "name": "qpls-md-app",
+  "version": "1.0.0",
+  "lockfileVersion": 2,
+  "requires": true,
+  "packages": {
+    "": {
+      "name": "qpls-md-app",
+      "version": "1.0.0",
+      "license": "ISC",
+      "dependencies": {
+        "moment": "^2.29.1",
+        "uview-ui": "^1.8.4"
+      }
+    },
+    "node_modules/moment": {
+      "version": "2.29.1",
+      "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
+      "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==",
+      "engines": {
+        "node": "*"
+      }
+    },
+    "node_modules/uview-ui": {
+      "version": "1.8.4",
+      "license": "MIT"
+    }
+  },
+  "dependencies": {
+    "moment": {
+      "version": "2.29.1",
+      "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
+      "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
+    },
+    "uview-ui": {
+      "version": "1.8.4"
+    }
+  }
+}

+ 1 - 0
package.json

@@ -14,6 +14,7 @@
   "author": "",
   "license": "ISC",
   "dependencies": {
+    "moment": "^2.29.1",
     "uview-ui": "^1.8.4"
   }
 }

+ 16 - 6
pages/common/printTag/printTag.vue

@@ -29,6 +29,7 @@
 	import { shelfDetail } from '@/api/shelf'
 	import kkPrinter from '@/components/kk-printer/index.vue';
 	import {textFormat} from '@/libs/printTools.js'
+	import moment from 'moment'
 	export default {
 		components:{
 			kkPrinter
@@ -38,7 +39,8 @@
 				infoData: null,
 				fromPage: '',
 				printInfo: null,
-				printNum: 0
+				printNum: 0,
+				isParinting: false
 			}
 		},
 		onLoad(options) {
@@ -64,7 +66,7 @@
 			// 获取打印内容
 			getPrintContent(){
 				const _this = this
-				const myDate = new Date()
+				const nowDate = moment().format('YYYY-MM-DD HH:mm')
 				if(_this.fromPage == 'bdtq'){
 					_this.printInfo = {
 						dealerName: _this.$store.state.vuex_userData.orgName,
@@ -73,7 +75,7 @@
 						productName: _this.infoData.productEntity&&_this.infoData.productEntity.productName || '',
 						shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
 						currentInven: _this.printNum,
-						printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
+						printDate: nowDate,
 						printUser: _this.$store.state.vuex_userData.username,
 						barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productEntity&&_this.infoData.productEntity.productSn}&productCode=${_this.infoData.productEntity&&_this.infoData.productEntity.code}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
 					}
@@ -85,7 +87,7 @@
 						productName: _this.infoData.productName || '',
 						shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
 						currentInven: _this.printNum,
-						printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
+						printDate: nowDate,
 						printUser: _this.$store.state.vuex_userData.username,
 						barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productSn}&productCode=${_this.infoData.productCode}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
 					}
@@ -104,6 +106,10 @@
 					this.$refs.kkprinter.onPrintFail()
 					return
 				}
+				if(this.isParinting){
+					return
+				}
+				this.isParinting = true
 				let top = 10 // 距离顶部10点像素
 				const left = 8 // 距离左边
 				const lightHeight = 24 // 行高3mm,1mm = 8点
@@ -111,7 +117,7 @@
 				const pageH = 30 // 页签高度mm
 				const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
 				let rightTop = 0
-				let rightLeft = Math.floor(maxFontNums*0.6)*lightHeight
+				let rightLeft = (Math.floor(maxFontNums*0.6)+1)*lightHeight
 				// 初始化打印机
 				const command = tsc.jpPrinter.createNew()
 				command.init()
@@ -129,8 +135,11 @@
 				top = top+10
 				top = textFormat(command,this.printInfo.productCode,lwidth,left,top,lightHeight,"left",1)
 				// 产品名称
-				top = top+5
+				top = top+10
 				top = textFormat(command,this.printInfo.productName,lwidth,left,top,lightHeight,"left",1)
+				// 打印人打印时间
+				top = top+10
+				top = textFormat(command,this.printInfo.printDate+' '+this.printInfo.printUser,lwidth,left,top,lightHeight,"left",1)
 				// 货位号
 				textFormat(command,this.printInfo.shelfPlaceCode,maxFontNums-lwidth,rightLeft,rightTop,lightHeight,"center",1)
 				// 二维码
@@ -144,6 +153,7 @@
 			onPrintSuccess(){
 				// uni.navigateBack()
 				this.$refs.kkprinter.onPrintSuccess()
+				this.isParinting = false
 			}
 		}
 	}