Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
梁建民
/
wmsMin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f2b558bd
authored
Apr 13, 2022
by
liangjianmin
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
bug
parent
6513638c
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
167 additions
and
264 deletions
pages/goods/tallyDetail.vue
pages/tag/deviceList.vue
pages/tag/print.vue
pages/tag/repairPrint.vue
pages/goods/tallyDetail.vue
View file @
f2b558bd
...
@@ -137,7 +137,7 @@
...
@@ -137,7 +137,7 @@
<textarea
@
input=
"inputChange()"
maxlength=
"200"
placeholder=
"请输入理货备注"
placeholder-style=
"color:#6E767A;"
v-model=
"form.sort_goods_remark"
></textarea>
<textarea
@
input=
"inputChange()"
maxlength=
"200"
placeholder=
"请输入理货备注"
placeholder-style=
"color:#6E767A;"
v-model=
"form.sort_goods_remark"
></textarea>
<text
class=
"text"
>
{{ limitword }}/200
</text>
<text
class=
"text"
>
{{ limitword }}/200
</text>
</view>
</view>
<view
class=
"box row verCenter"
style=
"border-bottom: none;"
>
<
!-- <
view class="box row verCenter" style="border-bottom: none;">
<text class="label">放置托盘</text>
<text class="label">放置托盘</text>
<view class="uni-list-cell-db">
<view class="uni-list-cell-db">
<text class="iconfont icon-sanjiaoxing1"></text>
<text class="iconfont icon-sanjiaoxing1"></text>
...
@@ -145,7 +145,7 @@
...
@@ -145,7 +145,7 @@
<view class="uni-input">{{ traySelectOption[index].tray_sn || '请选择' }}</view>
<view class="uni-input">{{ traySelectOption[index].tray_sn || '请选择' }}</view>
</picker>
</picker>
</view>
</view>
</view>
</view>
-->
</view>
</view>
</view>
</view>
<view
class=
"btn row rowCenter verCenter"
@
click=
"submit()"
>
确认收货
</view>
<view
class=
"btn row rowCenter verCenter"
@
click=
"submit()"
>
确认收货
</view>
...
@@ -203,12 +203,26 @@ export default {
...
@@ -203,12 +203,26 @@ export default {
},
},
onLoad
(
options
)
{
onLoad
(
options
)
{
this
.
form
.
number
=
options
.
number
||
''
;
//获取参数入仓号
this
.
form
.
number
=
options
.
number
||
''
;
//获取参数入仓号
this
.
getTraySelectOption
();
//获取托盘数据
//停止搜索,节省系统资源
uni
.
stopBluetoothDevicesDiscovery
({
success
:
res
=>
{
console
.
log
(
'停止搜索'
,
JSON
.
stringify
(
res
.
errMsg
));
}
});
try
{
uni
.
removeStorageSync
(
'device'
);
}
catch
(
e
)
{
// error
}
},
},
onShow
()
{
onShow
()
{
const
deviceData
=
uni
.
getStorageSync
(
'device'
)
||
''
;
//获取已连接蓝牙设备信息
//获取已连接蓝牙设备信息
const
deviceData
=
uni
.
getStorageSync
(
'device'
)
||
''
;
if
(
deviceData
)
{
if
(
deviceData
)
{
this
.
deviceId
=
deviceData
.
deviceId
;
this
.
deviceId
=
deviceData
.
deviceId
;
this
.
serviceId
=
deviceData
.
serviceId
;
this
.
characteristics
=
deviceData
.
characteristics
;
this
.
device_name
=
deviceData
.
name
;
this
.
device_name
=
deviceData
.
name
;
}
else
{
}
else
{
this
.
deviceId
=
''
;
this
.
deviceId
=
''
;
...
@@ -370,15 +384,6 @@ export default {
...
@@ -370,15 +384,6 @@ export default {
return
false
;
return
false
;
}
}
if
(
!
this
.
form
.
wstylt_id
)
{
uni
.
showModal
({
title
:
'提示'
,
content
:
'请选择放置托盘'
,
showCancel
:
false
});
return
false
;
}
//截取入仓号
//截取入仓号
if
(
this
.
form
.
number
)
{
if
(
this
.
form
.
number
)
{
this
.
printForm
.
erp_order_sn_pre
=
this
.
form
.
number
.
substr
(
0
,
1
);
this
.
printForm
.
erp_order_sn_pre
=
this
.
form
.
number
.
substr
(
0
,
1
);
...
@@ -430,16 +435,28 @@ export default {
...
@@ -430,16 +435,28 @@ export default {
*/
*/
print
()
{
print
()
{
if
(
!
this
.
device_name
)
{
if
(
!
this
.
device_name
)
{
uni
.
showToast
({
uni
.
showModal
({
icon
:
'error'
,
title
:
'提示'
,
title
:
'请连接蓝牙'
content
:
'请连接蓝牙设备'
,
showCancel
:
false
,
confirmText
:
'关闭'
,
success
:
function
(
res
)
{
if
(
res
.
confirm
)
{
uni
.
navigateTo
({
url
:
'/pages/tag/deviceList'
});
}
else
if
(
res
.
cancel
)
{
console
.
log
(
'用户点击取消'
);
}
}
});
});
return
false
;
return
false
;
}
}
this
.
request
(
API
.
printLabel
,
'POST'
,
this
.
printForm
,
true
).
then
(
res
=>
{
this
.
request
(
API
.
printLabel
,
'POST'
,
this
.
printForm
,
true
).
then
(
res
=>
{
if
(
res
.
err_code
===
0
)
{
if
(
res
.
err_code
===
0
)
{
this
.
printLabelData
=
res
.
data
;
this
.
printLabelData
=
res
.
data
;
this
.
getBLEDeviceServices
();
//根据获取的设备信息,连接设备
this
.
sendDataChange
();
//发送数据
}
else
{
}
else
{
uni
.
showToast
({
uni
.
showToast
({
title
:
res
.
err_msg
,
title
:
res
.
err_msg
,
...
@@ -449,66 +466,10 @@ export default {
...
@@ -449,66 +466,10 @@ export default {
});
});
},
},
/**
/**
* 来获取蓝牙设备所有服务
*/
getBLEDeviceServices
()
{
let
that
=
this
;
uni
.
showLoading
({
title
:
'设备打印中'
});
uni
.
createBLEConnection
({
deviceId
:
this
.
deviceId
,
success
:
res
=>
{
console
.
log
(
'连接成功'
,
JSON
.
stringify
(
res
.
errMsg
));
//需延时连接,不然会报错
setTimeout
(()
=>
{
uni
.
getBLEDeviceServices
({
deviceId
:
that
.
deviceId
,
success
:
res
=>
{
console
.
log
(
'获取蓝牙设备所有服务'
,
JSON
.
stringify
(
res
.
errMsg
));
that
.
serviceId
=
res
.
services
[
0
].
uuid
;
that
.
getBLEDeviceCharacteristics
();
}
});
},
1000
);
},
fail
:
res
=>
{
uni
.
hideLoading
();
uni
.
showToast
({
icon
:
'error'
,
title
:
'连接设备失败!'
,
duration
:
3000
});
}
});
},
/**
* 获取蓝牙设备某个服务中所有特征值
*/
getBLEDeviceCharacteristics
()
{
let
that
=
this
;
uni
.
getBLEDeviceCharacteristics
({
deviceId
:
that
.
deviceId
,
serviceId
:
that
.
serviceId
,
success
:
res
=>
{
that
.
characteristics
=
res
.
characteristics
[
0
].
uuid
;
that
.
sendDataChange
();
console
.
log
(
'服务功能特征值'
,
JSON
.
stringify
(
res
.
errMsg
));
},
fail
:
res
=>
{
uni
.
hideLoading
();
uni
.
showToast
({
icon
:
'error'
,
title
:
'连接设备失败!'
,
duration
:
3000
});
}
});
},
/**
* 向蓝牙发送数据
* 向蓝牙发送数据
*/
*/
sendDataChange
()
{
sendDataChange
()
{
try
{
console
.
log
(
'第'
+
this
.
print_number
+
'次打印'
);
console
.
log
(
'第'
+
this
.
print_number
+
'次打印'
);
let
data
=
[];
let
data
=
[];
if
(
this
.
printLabelData
.
length
>
0
)
{
if
(
this
.
printLabelData
.
length
>
0
)
{
...
@@ -532,6 +493,15 @@ export default {
...
@@ -532,6 +493,15 @@ export default {
this
.
sendData64
=
arrayBuffer
;
this
.
sendData64
=
arrayBuffer
;
this
.
writeBLECharacteristicValue
();
this
.
writeBLECharacteristicValue
();
console
.
log
(
data
.
join
(
''
));
console
.
log
(
data
.
join
(
''
));
}
catch
(
e
)
{
uni
.
hideLoading
();
uni
.
showModal
({
title
:
'提示'
,
content
:
'数据异常,请重试'
,
showCancel
:
false
,
confirmText
:
'关闭'
});
}
},
},
/**
/**
* 写入二进制数据
* 写入二进制数据
...
@@ -539,22 +509,17 @@ export default {
...
@@ -539,22 +509,17 @@ export default {
writeBLECharacteristicValue
()
{
writeBLECharacteristicValue
()
{
let
that
=
this
;
let
that
=
this
;
uni
.
writeBLECharacteristicValue
({
uni
.
writeBLECharacteristicValue
({
deviceId
:
that
.
deviceId
,
deviceId
:
this
.
deviceId
,
serviceId
:
that
.
serviceId
,
serviceId
:
this
.
serviceId
,
characteristicId
:
that
.
characteristics
,
characteristicId
:
this
.
characteristics
,
value
:
that
.
sendData64
,
value
:
this
.
sendData64
,
success
(
res
)
{
success
:
res
=>
{
that
.
print_number
++
;
this
.
print_number
++
;
console
.
log
(
'蓝牙写入成功:'
,
JSON
.
stringify
(
res
.
errMsg
));
console
.
log
(
'打印张数:'
+
this
.
print_number
);
console
.
log
(
'打印计数:'
+
that
.
print_number
);
if
(
this
.
print_number
<
this
.
printLabelData
.
length
)
{
if
(
that
.
print_number
<
that
.
printLabelData
.
length
)
{
this
.
sendDataChange
();
that
.
sendDataChange
();
}
else
{
}
else
{
uni
.
hideLoading
();
uni
.
hideLoading
();
uni
.
closeBLEConnection
({
deviceId
:
that
.
deviceId
,
success
(
res
)
{
console
.
log
(
'关闭蓝牙连接:'
,
JSON
.
stringify
(
res
.
errMsg
));
//清空数据
//清空数据
that
.
print_number
=
0
;
that
.
print_number
=
0
;
that
.
printLabelData
=
[];
that
.
printLabelData
=
[];
...
@@ -573,14 +538,12 @@ export default {
...
@@ -573,14 +538,12 @@ export default {
}
}
});
});
}
}
});
}
},
},
fail
()
{
fail
()
{
uni
.
hideLoading
();
uni
.
hideLoading
();
uni
.
showModal
({
uni
.
showModal
({
title
:
'提示'
,
title
:
'提示'
,
content
:
'
无法打印,请查看标签打印机连接状态
'
,
content
:
'
打印失败,请检查打印机
'
,
showCancel
:
false
,
showCancel
:
false
,
confirmText
:
'关闭'
,
confirmText
:
'关闭'
,
success
:
function
(
res
)
{
success
:
function
(
res
)
{
...
...
pages/tag/deviceList.vue
View file @
f2b558bd
This diff is collapsed.
Click to expand it.
pages/tag/print.vue
View file @
f2b558bd
...
@@ -36,14 +36,14 @@
...
@@ -36,14 +36,14 @@
<view
class=
"label"
>
{{ text }}
</view>
<view
class=
"label"
>
{{ text }}
</view>
<input
type=
"number"
v-model=
"form.label_num"
placeholder-style=
"font-size:24rpx;color:#404547;"
class=
"uni-input"
placeholder=
"请输入"
/>
<input
type=
"number"
v-model=
"form.label_num"
placeholder-style=
"font-size:24rpx;color:#404547;"
class=
"uni-input"
placeholder=
"请输入"
/>
</view>
</view>
<view
class=
"box row verCenter"
>
<!--
<view class="box row verCenter">
<view class="label">放置托盘</view>
<view class="label">放置托盘</view>
<view class="el-select row verCenter">
<view class="el-select row verCenter">
<picker @change="bindPickerChange" :value="index" :range="traySelectOption" range-key="tray_sn">
<picker @change="bindPickerChange" :value="index" :range="traySelectOption" range-key="tray_sn">
<view class="uni-input">{{ traySelectOption[index].tray_sn || '请选择' }}</view>
<view class="uni-input">{{ traySelectOption[index].tray_sn || '请选择' }}</view>
</picker>
</picker>
</view>
</view>
</view>
</view>
-->
</view>
</view>
<view
class=
"btn row rowCenter verCenter"
@
click=
"submit()"
>
提交打印
</view>
<view
class=
"btn row rowCenter verCenter"
@
click=
"submit()"
>
提交打印
</view>
</view>
</view>
...
@@ -81,7 +81,13 @@ export default {
...
@@ -81,7 +81,13 @@ export default {
};
};
},
},
onLoad
(
option
)
{
onLoad
(
option
)
{
this
.
getTraySelectOption
();
//停止搜索,节省系统资源
uni
.
stopBluetoothDevicesDiscovery
({
success
:
res
=>
{
console
.
log
(
'停止搜索'
,
JSON
.
stringify
(
res
.
errMsg
));
}
});
try
{
try
{
uni
.
removeStorageSync
(
'device'
);
uni
.
removeStorageSync
(
'device'
);
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -89,9 +95,12 @@ export default {
...
@@ -89,9 +95,12 @@ export default {
}
}
},
},
onShow
()
{
onShow
()
{
const
deviceData
=
uni
.
getStorageSync
(
'device'
)
||
''
;
//获取已连接蓝牙设备信息
//获取已连接蓝牙设备信息
const
deviceData
=
uni
.
getStorageSync
(
'device'
)
||
''
;
if
(
deviceData
)
{
if
(
deviceData
)
{
this
.
deviceId
=
deviceData
.
deviceId
;
this
.
deviceId
=
deviceData
.
deviceId
;
this
.
serviceId
=
deviceData
.
serviceId
;
this
.
characteristics
=
deviceData
.
characteristics
;
this
.
device_name
=
deviceData
.
name
;
this
.
device_name
=
deviceData
.
name
;
}
else
{
}
else
{
this
.
deviceId
=
''
;
this
.
deviceId
=
''
;
...
@@ -121,12 +130,24 @@ export default {
...
@@ -121,12 +130,24 @@ export default {
},
},
submit
()
{
submit
()
{
if
(
!
this
.
device_name
)
{
if
(
!
this
.
device_name
)
{
uni
.
showToast
({
uni
.
showModal
({
icon
:
'error'
,
title
:
'提示'
,
title
:
'请连接蓝牙设备'
content
:
'请连接蓝牙设备'
,
showCancel
:
false
,
confirmText
:
'关闭'
,
success
:
function
(
res
)
{
if
(
res
.
confirm
)
{
uni
.
navigateTo
({
url
:
'/pages/tag/deviceList'
});
}
else
if
(
res
.
cancel
)
{
console
.
log
(
'用户点击取消'
);
}
}
});
});
return
false
;
return
false
;
}
}
if
(
!
this
.
form
.
erp_order_sn_pre
)
{
if
(
!
this
.
form
.
erp_order_sn_pre
)
{
uni
.
showToast
({
uni
.
showToast
({
icon
:
'error'
,
icon
:
'error'
,
...
@@ -165,78 +186,16 @@ export default {
...
@@ -165,78 +186,16 @@ export default {
return
false
;
return
false
;
}
}
if
(
!
this
.
form
.
tray_remark
)
{
uni
.
showToast
({
icon
:
'error'
,
title
:
'请选择放置托盘'
});
return
false
;
}
this
.
request
(
API
.
printLabel
,
'POST'
,
this
.
form
,
false
).
then
(
res
=>
{
this
.
request
(
API
.
printLabel
,
'POST'
,
this
.
form
,
false
).
then
(
res
=>
{
if
(
res
.
err_code
===
0
)
{
if
(
res
.
err_code
===
0
)
{
this
.
printLabelData
=
res
.
data
;
this
.
printLabelData
=
res
.
data
;
this
.
getBLEDeviceServices
();
//根据获取的设备信息,连接设备
this
.
sendDataChange
();
//发送数据
}
else
{
}
else
{
uni
.
showToast
({
uni
.
showModal
({
title
:
res
.
err_msg
,
title
:
'提示'
,
icon
:
'error'
content
:
res
.
err_msg
,
});
showCancel
:
false
,
}
confirmText
:
'关闭'
});
},
/**
* 来获取蓝牙设备所有服务
*/
getBLEDeviceServices
()
{
let
that
=
this
;
uni
.
showLoading
({
title
:
'设备打印中'
});
uni
.
createBLEConnection
({
deviceId
:
this
.
deviceId
,
success
:
res
=>
{
console
.
log
(
'连接成功'
,
JSON
.
stringify
(
res
.
errMsg
));
//需延时连接,不然会报错
setTimeout
(()
=>
{
uni
.
getBLEDeviceServices
({
deviceId
:
that
.
deviceId
,
success
:
res
=>
{
console
.
log
(
'获取蓝牙设备所有服务'
,
JSON
.
stringify
(
res
.
errMsg
));
that
.
serviceId
=
res
.
services
[
0
].
uuid
;
that
.
getBLEDeviceCharacteristics
();
}
});
},
1000
);
},
fail
:
res
=>
{
uni
.
hideLoading
();
uni
.
showToast
({
icon
:
'error'
,
title
:
'连接设备失败!'
,
duration
:
3000
});
}
});
},
/**
* 获取蓝牙设备某个服务中所有特征值
*/
getBLEDeviceCharacteristics
()
{
let
that
=
this
;
uni
.
getBLEDeviceCharacteristics
({
deviceId
:
that
.
deviceId
,
serviceId
:
that
.
serviceId
,
success
:
res
=>
{
that
.
characteristics
=
res
.
characteristics
[
0
].
uuid
;
that
.
sendDataChange
();
console
.
log
(
'服务功能特征值'
,
JSON
.
stringify
(
res
.
errMsg
));
},
fail
:
res
=>
{
uni
.
hideLoading
();
uni
.
showToast
({
icon
:
'error'
,
title
:
'连接设备失败!'
,
duration
:
3000
});
});
}
}
});
});
...
@@ -245,6 +204,10 @@ export default {
...
@@ -245,6 +204,10 @@ export default {
* 向蓝牙发送数据
* 向蓝牙发送数据
*/
*/
sendDataChange
()
{
sendDataChange
()
{
try
{
uni
.
showLoading
({
title
:
'打印中...'
});
console
.
log
(
'第'
+
this
.
print_number
+
'次打印'
);
console
.
log
(
'第'
+
this
.
print_number
+
'次打印'
);
let
data
=
[];
let
data
=
[];
if
(
this
.
printLabelData
.
length
>
0
)
{
if
(
this
.
printLabelData
.
length
>
0
)
{
...
@@ -268,6 +231,15 @@ export default {
...
@@ -268,6 +231,15 @@ export default {
this
.
sendData64
=
arrayBuffer
;
this
.
sendData64
=
arrayBuffer
;
this
.
writeBLECharacteristicValue
();
this
.
writeBLECharacteristicValue
();
console
.
log
(
data
.
join
(
''
));
console
.
log
(
data
.
join
(
''
));
}
catch
(
e
)
{
uni
.
hideLoading
();
uni
.
showModal
({
title
:
'提示'
,
content
:
'数据异常,请重试'
,
showCancel
:
false
,
confirmText
:
'关闭'
});
}
},
},
/**
/**
* 写入二进制数据
* 写入二进制数据
...
@@ -275,22 +247,17 @@ export default {
...
@@ -275,22 +247,17 @@ export default {
writeBLECharacteristicValue
()
{
writeBLECharacteristicValue
()
{
let
that
=
this
;
let
that
=
this
;
uni
.
writeBLECharacteristicValue
({
uni
.
writeBLECharacteristicValue
({
deviceId
:
that
.
deviceId
,
deviceId
:
this
.
deviceId
,
serviceId
:
that
.
serviceId
,
serviceId
:
this
.
serviceId
,
characteristicId
:
that
.
characteristics
,
characteristicId
:
this
.
characteristics
,
value
:
that
.
sendData64
,
value
:
this
.
sendData64
,
success
(
res
)
{
success
:
res
=>
{
that
.
print_number
++
;
this
.
print_number
++
;
console
.
log
(
'蓝牙写入成功:'
,
JSON
.
stringify
(
res
.
errMsg
));
console
.
log
(
'打印张数:'
+
this
.
print_number
);
console
.
log
(
'打印计数:'
+
that
.
print_number
);
if
(
this
.
print_number
<
this
.
printLabelData
.
length
)
{
if
(
that
.
print_number
<
that
.
printLabelData
.
length
)
{
this
.
sendDataChange
();
that
.
sendDataChange
();
}
else
{
}
else
{
uni
.
hideLoading
();
uni
.
hideLoading
();
uni
.
closeBLEConnection
({
deviceId
:
that
.
deviceId
,
success
(
res
)
{
console
.
log
(
'关闭蓝牙连接:'
,
JSON
.
stringify
(
res
.
errMsg
));
//清空数据
//清空数据
that
.
print_number
=
0
;
that
.
print_number
=
0
;
that
.
printLabelData
=
[];
that
.
printLabelData
=
[];
...
@@ -309,14 +276,12 @@ export default {
...
@@ -309,14 +276,12 @@ export default {
}
}
});
});
}
}
});
}
},
},
fail
()
{
fail
()
{
uni
.
hideLoading
();
uni
.
hideLoading
();
uni
.
showModal
({
uni
.
showModal
({
title
:
'提示'
,
title
:
'提示'
,
content
:
'
无法打印,请查看标签打印机连接状态
'
,
content
:
'
打印失败,请检查打印机
'
,
showCancel
:
false
,
showCancel
:
false
,
confirmText
:
'关闭'
,
confirmText
:
'关闭'
,
success
:
function
(
res
)
{
success
:
function
(
res
)
{
...
...
pages/tag/repairPrint.vue
View file @
f2b558bd
...
@@ -63,10 +63,27 @@ export default {
...
@@ -63,10 +63,27 @@ export default {
}
}
};
};
},
},
onLoad
(
option
)
{
//停止搜索,节省系统资源
uni
.
stopBluetoothDevicesDiscovery
({
success
:
res
=>
{
console
.
log
(
'停止搜索'
,
JSON
.
stringify
(
res
.
errMsg
));
}
});
try
{
uni
.
removeStorageSync
(
'device'
);
}
catch
(
e
)
{
// error
}
},
onShow
()
{
onShow
()
{
const
deviceData
=
uni
.
getStorageSync
(
'device'
)
||
''
;
//获取已连接蓝牙设备信息
//获取已连接蓝牙设备信息
const
deviceData
=
uni
.
getStorageSync
(
'device'
)
||
''
;
if
(
deviceData
)
{
if
(
deviceData
)
{
this
.
deviceId
=
deviceData
.
deviceId
;
this
.
deviceId
=
deviceData
.
deviceId
;
this
.
serviceId
=
deviceData
.
serviceId
;
this
.
characteristics
=
deviceData
.
characteristics
;
this
.
device_name
=
deviceData
.
name
;
this
.
device_name
=
deviceData
.
name
;
}
else
{
}
else
{
this
.
deviceId
=
''
;
this
.
deviceId
=
''
;
...
@@ -94,9 +111,20 @@ export default {
...
@@ -94,9 +111,20 @@ export default {
},
},
submit
()
{
submit
()
{
if
(
!
this
.
device_name
)
{
if
(
!
this
.
device_name
)
{
uni
.
showToast
({
uni
.
showModal
({
icon
:
'error'
,
title
:
'提示'
,
title
:
'请连接蓝牙设备'
content
:
'请连接蓝牙设备'
,
showCancel
:
false
,
confirmText
:
'关闭'
,
success
:
function
(
res
)
{
if
(
res
.
confirm
)
{
uni
.
navigateTo
({
url
:
'/pages/tag/deviceList'
});
}
else
if
(
res
.
cancel
)
{
console
.
log
(
'用户点击取消'
);
}
}
});
});
return
false
;
return
false
;
}
}
...
@@ -142,7 +170,7 @@ export default {
...
@@ -142,7 +170,7 @@ export default {
this
.
request
(
API
.
getPrintLabel
,
'POST'
,
{
erp_order_sn
:
this
.
form
.
erp_order_sn_pre
+
this
.
form
.
erp_order_sn_number
,
label_sort
:
this
.
form
.
label_sort
},
true
).
then
(
res
=>
{
this
.
request
(
API
.
getPrintLabel
,
'POST'
,
{
erp_order_sn
:
this
.
form
.
erp_order_sn_pre
+
this
.
form
.
erp_order_sn_number
,
label_sort
:
this
.
form
.
label_sort
},
true
).
then
(
res
=>
{
if
(
res
.
err_code
===
0
)
{
if
(
res
.
err_code
===
0
)
{
this
.
printLabelData
=
res
.
data
;
this
.
printLabelData
=
res
.
data
;
this
.
getBLEDeviceServices
();
//根据获取的设备信息,连接设备
this
.
sendDataChange
();
//发送数据
}
else
{
}
else
{
uni
.
showToast
({
uni
.
showToast
({
title
:
res
.
err_msg
,
title
:
res
.
err_msg
,
...
@@ -152,66 +180,13 @@ export default {
...
@@ -152,66 +180,13 @@ export default {
});
});
},
},
/**
/**
* 来获取蓝牙设备所有服务
*/
getBLEDeviceServices
()
{
let
that
=
this
;
uni
.
showLoading
({
title
:
'设备打印中'
});
uni
.
createBLEConnection
({
deviceId
:
this
.
deviceId
,
success
:
res
=>
{
console
.
log
(
'连接成功'
,
JSON
.
stringify
(
res
));
//需延时连接,不然会报错
setTimeout
(
function
()
{
uni
.
getBLEDeviceServices
({
deviceId
:
that
.
deviceId
,
success
:
res
=>
{
console
.
log
(
'获取蓝牙设备所有服务'
,
res
);
that
.
serviceId
=
res
.
services
[
0
].
uuid
;
that
.
getBLEDeviceCharacteristics
();
}
});
},
1000
);
},
fail
:
res
=>
{
uni
.
hideLoading
();
uni
.
showToast
({
icon
:
'error'
,
title
:
'连接设备失败!'
,
duration
:
3000
});
}
});
},
/**
* 获取蓝牙设备某个服务中所有特征值
*/
getBLEDeviceCharacteristics
()
{
let
that
=
this
;
uni
.
getBLEDeviceCharacteristics
({
deviceId
:
that
.
deviceId
,
serviceId
:
that
.
serviceId
,
success
:
res
=>
{
that
.
characteristics
=
res
.
characteristics
[
0
].
uuid
;
that
.
sendDataChange
();
console
.
log
(
'服务功能特征值'
,
res
);
},
fail
:
res
=>
{
uni
.
hideLoading
();
uni
.
showToast
({
icon
:
'error'
,
title
:
'连接设备失败!'
,
duration
:
3000
});
}
});
},
/**
* 向蓝牙发送数据
* 向蓝牙发送数据
*/
*/
sendDataChange
()
{
sendDataChange
()
{
try
{
uni
.
showLoading
({
title
:
'打印中...'
});
console
.
log
(
'第'
+
this
.
print_number
+
'次打印'
);
console
.
log
(
'第'
+
this
.
print_number
+
'次打印'
);
let
data
=
[];
let
data
=
[];
if
(
this
.
printLabelData
.
length
>
0
)
{
if
(
this
.
printLabelData
.
length
>
0
)
{
...
@@ -234,6 +209,15 @@ export default {
...
@@ -234,6 +209,15 @@ export default {
this
.
sendData64
=
arrayBuffer
;
this
.
sendData64
=
arrayBuffer
;
this
.
writeBLECharacteristicValue
();
this
.
writeBLECharacteristicValue
();
console
.
log
(
data
.
join
(
''
));
console
.
log
(
data
.
join
(
''
));
}
catch
(
e
)
{
uni
.
hideLoading
();
uni
.
showModal
({
title
:
'提示'
,
content
:
'数据异常,请重试'
,
showCancel
:
false
,
confirmText
:
'关闭'
});
}
},
},
/**
/**
* 写入二进制数据
* 写入二进制数据
...
@@ -241,24 +225,17 @@ export default {
...
@@ -241,24 +225,17 @@ export default {
writeBLECharacteristicValue
()
{
writeBLECharacteristicValue
()
{
let
that
=
this
;
let
that
=
this
;
uni
.
writeBLECharacteristicValue
({
uni
.
writeBLECharacteristicValue
({
deviceId
:
that
.
deviceId
,
deviceId
:
this
.
deviceId
,
serviceId
:
that
.
serviceId
,
serviceId
:
this
.
serviceId
,
characteristicId
:
that
.
characteristics
,
characteristicId
:
this
.
characteristics
,
value
:
that
.
sendData64
,
value
:
this
.
sendData64
,
success
(
res
)
{
success
:
res
=>
{
that
.
print_number
++
;
this
.
print_number
++
;
console
.
log
(
'蓝牙写入成功:'
,
JSON
.
stringify
(
res
.
errMsg
));
console
.
log
(
'打印张数:'
+
this
.
print_number
);
console
.
log
(
'打印计数:'
+
that
.
print_number
);
if
(
this
.
print_number
<
this
.
printLabelData
.
length
)
{
if
(
that
.
print_number
<
that
.
printLabelData
.
length
)
{
this
.
sendDataChange
();
setTimeout
(
function
()
{
that
.
sendDataChange
();
},
0
);
}
else
{
}
else
{
uni
.
hideLoading
();
uni
.
hideLoading
();
uni
.
closeBLEConnection
({
deviceId
:
that
.
deviceId
,
success
(
res
)
{
console
.
log
(
'关闭蓝牙连接:'
,
JSON
.
stringify
(
res
.
errMsg
));
//清空数据
//清空数据
that
.
print_number
=
0
;
that
.
print_number
=
0
;
that
.
printLabelData
=
[];
that
.
printLabelData
=
[];
...
@@ -277,14 +254,12 @@ export default {
...
@@ -277,14 +254,12 @@ export default {
}
}
});
});
}
}
});
}
},
},
fail
()
{
fail
()
{
uni
.
hideLoading
();
uni
.
hideLoading
();
uni
.
showModal
({
uni
.
showModal
({
title
:
'提示'
,
title
:
'提示'
,
content
:
'
无法打印,请查看标签打印机连接状态
'
,
content
:
'
打印失败,请检查打印机
'
,
showCancel
:
false
,
showCancel
:
false
,
confirmText
:
'关闭'
,
confirmText
:
'关闭'
,
success
:
function
(
res
)
{
success
:
function
(
res
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment