Browse Source

fix: 标签打印

master
taqi be 1 month ago
parent
commit
d4d1e262fc
  1. 4
      .env.production
  2. 7
      src/api/module/eam/device/index.ts
  3. 36
      src/pages/deviceInfo/index.vue
  4. 58
      src/router/index.ts
  5. 2
      vite.config.ts

4
.env.production

@ -1,2 +1,2 @@ @@ -1,2 +1,2 @@
VITE_BASE_URL = 'http://192.168.1.3:48081'
VITE_SOCKET_SERVER = 'http://192.168.1.3:48081'
VITE_BASE_URL = 'http://62.234.18.176:48081'
VITE_SOCKET_SERVER = 'http://62.234.18.176:48081'

7
src/api/module/eam/device/index.ts

@ -93,6 +93,13 @@ export const getSimpleDeviceList = (params: { categoryId: string }) => @@ -93,6 +93,13 @@ export const getSimpleDeviceList = (params: { categoryId: string }) =>
params,
})
export const getDeviceLabelBase64 = (id: number) =>
eamServer({
url: `/device/generate-label`,
method: 'get',
params: { id },
})
// ============== 测试工单相关 ==============
export const operantDeviceTestSheet = (type: OperantAction, params: any) => {

36
src/pages/deviceInfo/index.vue

@ -10,11 +10,7 @@ @@ -10,11 +10,7 @@
</div>
<EdfsWrap title="设备信息列表" class="device-info-table">
<template #title-right>
<EdfsButton
type="primary"
inner-text="新增设备"
@click="addDevice"
/>
<EdfsButton type="primary" inner-text="新增设备" @click="addDevice" />
</template>
<EdfsTable
class="table"
@ -56,7 +52,7 @@ @@ -56,7 +52,7 @@
/>
</template>
<el-table-column label="操作" width="190" align="center">
<el-table-column label="操作" width="210" align="center">
<template #default="scope">
<EdfsButton
link
@ -64,6 +60,12 @@ @@ -64,6 +60,12 @@
inner-text="查看"
@click="onView(scope.row)"
/><el-divider direction="vertical" />
<EdfsButton
link
type="primary"
inner-text="打印标签"
@click="onPrint(scope.row)"
/><el-divider direction="vertical" />
<el-dropdown @command="command => handleCommand(command, scope.row)">
<el-button type="primary" link
@ -104,12 +106,14 @@ import type { TableColumnCtx } from 'element-plus' @@ -104,12 +106,14 @@ import type { TableColumnCtx } from 'element-plus'
import { useRouter } from 'vue-router'
import PieChart from './components/pie-chart.vue'
import {
getDeviceLabelBase64,
getDevicePage,
getDeviceSummaryByStatus,
type IDevice,
} from '@/api/module/eam/device'
import { deviceTableCol, DeviceStatus } from './utils'
import { getCategoryTree, type ICategoryTree } from '@/api/module/eam/device/category'
import jsPDF from 'jspdf'
const loading = ref(true)
const total = ref(0)
@ -191,6 +195,26 @@ function onView(row: any) { @@ -191,6 +195,26 @@ function onView(row: any) {
router.push({ path: '/device/deviceOperation', query: { action: 'view', id: row.id } })
}
async function onPrint(row: any) {
const res = await getDeviceLabelBase64(row.id)
debugger
if (isResError(res)) return
const pdf = new jsPDF('l', 'mm', [60, 40])
const pdfWidth = pdf.internal.pageSize.getWidth() //
const imgData = res.data
const imgWidth = pdfWidth
const imgHeight = (pdfWidth * 3) / 4
// PDF
pdf.addImage(imgData, 'JPEG', 0, 0, imgWidth, imgHeight)
// PDF
pdf.autoPrint()
window.open(pdf.output('bloburl'), '_blank')
}
function handleCommand(command: string, row: any) {
editDevice(row, command)
}

58
src/router/index.ts

@ -48,30 +48,40 @@ export const defaultRoute = [ @@ -48,30 +48,40 @@ export const defaultRoute = [
],
},
{
path: '/test',
component: () => import('@/pages/layout.vue'),
name: 'Test',
meta: {
canTo: true,
hidden: false,
noTagsView: false,
icon: 'ep:user',
title: 'Test',
},
children: [
{
path: 'PDF',
component: () => import('@/pages/deviceInfo/testPDF.vue'),
name: 'PDF',
meta: {
icon: 'ep:user',
hidden: false,
title: '测试PDF',
},
},
],
},
// {
// path: '/test',
// component: () => import('@/pages/layout.vue'),
// name: 'Test',
// meta: {
// canTo: true,
// hidden: false,
// noTagsView: false,
// icon: 'ep:user',
// title: 'Test',
// },
// children: [
// {
// path: 'PDF',
// component: () => import('@/pages/deviceInfo/testPDF.vue'),
// name: 'PDF',
// meta: {
// icon: 'ep:user',
// hidden: false,
// title: '测试PDF',
// },
// },
// {
// path: 'template',
// component: () => import('@/pages/printTemp/index.vue'),
// name: 'Template',
// meta: {
// icon: 'ep:user',
// hidden: false,
// title: '打印模板',
// },
// },
// ],
// },
// {
// path: '/user',
// component: () => import('@/pages/layout.vue'),

2
vite.config.ts

@ -49,7 +49,7 @@ export default defineConfig(({ mode }) => { @@ -49,7 +49,7 @@ export default defineConfig(({ mode }) => {
scss: {
additionalData: `@use "./src/styles/variables.scss" as *;`,
javascriptEnabled: true,
silenceDeprecations: ["legacy-js-api"],
silenceDeprecations: ['legacy-js-api'],
},
},
},

Loading…
Cancel
Save