支持打印和搜索

This commit is contained in:
2026-04-27 22:01:45 +08:00
parent 09e806c969
commit 7bcd159605
8 changed files with 1121 additions and 15 deletions
+88 -5
View File
@@ -3,6 +3,9 @@
<view class="header">
<text class="back-btn" @click="goBack"> 返回</text>
<text class="title">物品详情</text>
<view class="header-right">
<text class="print-btn" @click="printItem">打印</text>
</view>
</view>
<scroll-view scroll-y class="content" refresher-enabled @refresherrefresh="onRefresh" :refresher-triggered="refreshing">
@@ -159,6 +162,16 @@ import { ref, onMounted } from 'vue'
import { warehouseApi } from '@/api/warehouse.js'
import { useConfigStore } from '@/stores/config.js'
// 仅在 App 环境下加载原生插件
let printer = null
try {
if (uni.requireNativePlugin) {
printer = uni.requireNativePlugin('LcPrinter')
}
} catch (e) {
console.error('打印机插件加载失败:', e.message)
}
const configStore = useConfigStore()
const itemId = ref(0)
const loading = ref(false)
@@ -318,6 +331,73 @@ function goBack() {
uni.navigateBack({ delta: 1 })
}
// 打印物品标签
function printItem() {
if (!printer) {
uni.showToast({ title: '打印机插件未加载(仅在 App 环境可用)', icon: 'none' })
return
}
if (!item.value) {
uni.showToast({ title: '物品信息未加载', icon: 'none' })
return
}
// 标签打印,使用黑标
printer.printEnableMark({
enable: true
})
// 第一行:标题(名称)
printer.setFontSize({ fontSize: 0 })
printer.setTextBold({ bold: true })
printer.printText({
content: (item.value.Name || '物品')+'\n'
})
printer.setTextBold({ bold: false })
//printer.printLine({ line_length: 1 })
// 第二行:编号
if (item.value.SerialNumber) {
printer.setFontSize({ fontSize: 1 })
printer.printText({
content: '序列号:' + item.value.SerialNumber +'\n'
})
//printer.printLine({ line_length: 1 })
}
// 第三行:备注
if (item.value.Remark) {
printer.setFontSize({ fontSize: 1 })
printer.printText({
content: '备注:' + item.value.Remark+'\n'
})
//printer.printLine({ line_length: 1 })
}
// 第四行:创建日期
if (item.value.CreatedAt) {
printer.setFontSize({ fontSize: 1 })
printer.printText({
content: '创建日期:' + formatDate(item.value.CreatedAt)
})
//printer.printLine({ line_length: 1 })
}
// 条形码(高度4
printer.printBarcode({
text: 'item:' + itemId.value,
height: 40,
barcodeType: 73
})
printer.printLine({ line_length: 2 })
// 提交打印
printer.start()
uni.showToast({ title: '打印成功', icon: 'success' })
}
async function onRefresh() {
refreshing.value = true
await fetchDetail()
@@ -372,13 +452,16 @@ onShow(() => {
color: #333;
flex: 1;
text-align: center;
padding-right: 60rpx;
}
.title {
font-size: 36rpx;
font-weight: bold;
color: #333;
.header-right {
display: flex;
align-items: center;
}
.print-btn {
font-size: 28rpx;
color: #007AFF;
}
.content {