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 @@
VITE_BASE_URL = 'http://192.168.1.3:48081' VITE_BASE_URL = 'http://62.234.18.176:48081'
VITE_SOCKET_SERVER = 'http://192.168.1.3: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 }) =>
params, params,
}) })
export const getDeviceLabelBase64 = (id: number) =>
eamServer({
url: `/device/generate-label`,
method: 'get',
params: { id },
})
// ============== 测试工单相关 ============== // ============== 测试工单相关 ==============
export const operantDeviceTestSheet = (type: OperantAction, params: any) => { export const operantDeviceTestSheet = (type: OperantAction, params: any) => {

36
src/pages/deviceInfo/index.vue

@ -10,11 +10,7 @@
</div> </div>
<EdfsWrap title="设备信息列表" class="device-info-table"> <EdfsWrap title="设备信息列表" class="device-info-table">
<template #title-right> <template #title-right>
<EdfsButton <EdfsButton type="primary" inner-text="新增设备" @click="addDevice" />
type="primary"
inner-text="新增设备"
@click="addDevice"
/>
</template> </template>
<EdfsTable <EdfsTable
class="table" class="table"
@ -56,7 +52,7 @@
/> />
</template> </template>
<el-table-column label="操作" width="190" align="center"> <el-table-column label="操作" width="210" align="center">
<template #default="scope"> <template #default="scope">
<EdfsButton <EdfsButton
link link
@ -64,6 +60,12 @@
inner-text="查看" inner-text="查看"
@click="onView(scope.row)" @click="onView(scope.row)"
/><el-divider direction="vertical" /> /><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-dropdown @command="command => handleCommand(command, scope.row)">
<el-button type="primary" link <el-button type="primary" link
@ -104,12 +106,14 @@ import type { TableColumnCtx } from 'element-plus'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import PieChart from './components/pie-chart.vue' import PieChart from './components/pie-chart.vue'
import { import {
getDeviceLabelBase64,
getDevicePage, getDevicePage,
getDeviceSummaryByStatus, getDeviceSummaryByStatus,
type IDevice, type IDevice,
} from '@/api/module/eam/device' } from '@/api/module/eam/device'
import { deviceTableCol, DeviceStatus } from './utils' import { deviceTableCol, DeviceStatus } from './utils'
import { getCategoryTree, type ICategoryTree } from '@/api/module/eam/device/category' import { getCategoryTree, type ICategoryTree } from '@/api/module/eam/device/category'
import jsPDF from 'jspdf'
const loading = ref(true) const loading = ref(true)
const total = ref(0) const total = ref(0)
@ -191,6 +195,26 @@ function onView(row: any) {
router.push({ path: '/device/deviceOperation', query: { action: 'view', id: row.id } }) 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) { function handleCommand(command: string, row: any) {
editDevice(row, command) editDevice(row, command)
} }

58
src/router/index.ts

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

2
vite.config.ts

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

Loading…
Cancel
Save