Browse Source

feat: 前端打印

master
taqi be 1 month ago
parent
commit
435a760fe5
  1. 217
      package-lock.json
  2. 3
      package.json
  3. 437
      src/pages/deviceInfo/testPDF.vue
  4. 48
      src/router/index.ts

217
package-lock.json generated

@ -29,6 +29,8 @@
"cropperjs": "^1.6.2", "cropperjs": "^1.6.2",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"dayjs": "^1.11.11", "dayjs": "^1.11.11",
"jspdf": "^2.5.2",
"jspdf-html2canvas": "^1.5.2",
"jszmq": "^0.1.2", "jszmq": "^0.1.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mitt": "^3.0.1", "mitt": "^3.0.1",
@ -76,6 +78,7 @@
"uuid": "^9.0.0", "uuid": "^9.0.0",
"vite": "^5.2.12", "vite": "^5.2.12",
"vite-plugin-purge-icons": "^0.10.0", "vite-plugin-purge-icons": "^0.10.0",
"vue-printjs": "^1.0.0",
"vue-tsc": "^2.0.19" "vue-tsc": "^2.0.19"
} }
}, },
@ -2863,6 +2866,13 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/raf": {
"version": "3.4.3",
"resolved": "https://registry.npmjs.org/@types/raf/-/raf-3.4.3.tgz",
"integrity": "sha512-c4YAvMedbPZ5tEyxzQdMoOhhJ4RD3rngZIdwC2/qDN3d7JpEhB6fiBRKVY1lg5B7Wk+uPBjn5f39j1/2MY1oOw==",
"license": "MIT",
"optional": true
},
"node_modules/@types/semver": { "node_modules/@types/semver": {
"version": "7.5.8", "version": "7.5.8",
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz",
@ -3993,6 +4003,18 @@
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/atob": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
"license": "(MIT OR Apache-2.0)",
"bin": {
"atob": "bin/atob.js"
},
"engines": {
"node": ">= 4.5.0"
}
},
"node_modules/available-typed-arrays": { "node_modules/available-typed-arrays": {
"version": "1.0.7", "version": "1.0.7",
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz",
@ -4121,6 +4143,15 @@
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/base64-arraybuffer": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
"integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6.0"
}
},
"node_modules/base64-js": { "node_modules/base64-js": {
"version": "1.5.1", "version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
@ -4243,6 +4274,18 @@
"node-int64": "^0.4.0" "node-int64": "^0.4.0"
} }
}, },
"node_modules/btoa": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz",
"integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==",
"license": "(MIT OR Apache-2.0)",
"bin": {
"btoa": "bin/btoa.js"
},
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/buffer": { "node_modules/buffer": {
"version": "5.7.1", "version": "5.7.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
@ -4358,6 +4401,33 @@
], ],
"license": "CC-BY-4.0" "license": "CC-BY-4.0"
}, },
"node_modules/canvg": {
"version": "3.0.10",
"resolved": "https://registry.npmjs.org/canvg/-/canvg-3.0.10.tgz",
"integrity": "sha512-qwR2FRNO9NlzTeKIPIKpnTY6fqwuYSequ8Ru8c0YkYU7U0oW+hLUvWadLvAu1Rl72OMNiFhoLu4f8eUjQ7l/+Q==",
"license": "MIT",
"optional": true,
"dependencies": {
"@babel/runtime": "^7.12.5",
"@types/raf": "^3.4.0",
"core-js": "^3.8.3",
"raf": "^3.4.1",
"regenerator-runtime": "^0.13.7",
"rgbcolor": "^1.0.1",
"stackblur-canvas": "^2.0.0",
"svg-pathdata": "^6.0.3"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/canvg/node_modules/regenerator-runtime": {
"version": "0.13.11",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==",
"license": "MIT",
"optional": true
},
"node_modules/cfb": { "node_modules/cfb": {
"version": "1.2.2", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz", "resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz",
@ -4524,6 +4594,18 @@
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/core-js": {
"version": "3.40.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.40.0.tgz",
"integrity": "sha512-7vsMc/Lty6AGnn7uFpYT56QesI5D2Y/UkgKounk87OP9Z2H9Z8kj6jzcSGAxFmUtDOS0ntK6lbQz+Nsa0Jj6mQ==",
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
},
"node_modules/crc-32": { "node_modules/crc-32": {
"version": "1.2.2", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz", "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
@ -4572,6 +4654,15 @@
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==", "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/css-line-break": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
"integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
"license": "MIT",
"dependencies": {
"utrie": "^1.0.2"
}
},
"node_modules/cssesc": { "node_modules/cssesc": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",
@ -4896,6 +4987,13 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/dompurify": {
"version": "2.5.8",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.5.8.tgz",
"integrity": "sha512-o1vSNgrmYMQObbSSvF/1brBYEQPHhV1+gsmrusO7/GXtp1T9rCS8cXFqVxK/9crT1jA6Ccv+5MTSjBNqr7Sovw==",
"license": "(MPL-2.0 OR Apache-2.0)",
"optional": true
},
"node_modules/dotenv": { "node_modules/dotenv": {
"version": "16.4.7", "version": "16.4.7",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
@ -6392,6 +6490,19 @@
"url": "https://github.com/sponsors/wooorm" "url": "https://github.com/sponsors/wooorm"
} }
}, },
"node_modules/html2canvas": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
"integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
"license": "MIT",
"dependencies": {
"css-line-break": "^2.1.0",
"text-segmentation": "^1.0.3"
},
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/http-proxy-agent": { "node_modules/http-proxy-agent": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz",
@ -7947,6 +8058,40 @@
"node": ">= 10.0.0" "node": ">= 10.0.0"
} }
}, },
"node_modules/jspdf": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jspdf/-/jspdf-2.5.2.tgz",
"integrity": "sha512-myeX9c+p7znDWPk0eTrujCzNjT+CXdXyk7YmJq5nD5V7uLLKmSXnlQ/Jn/kuo3X09Op70Apm0rQSnFWyGK8uEQ==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.23.2",
"atob": "^2.1.2",
"btoa": "^1.2.1",
"fflate": "^0.8.1"
},
"optionalDependencies": {
"canvg": "^3.0.6",
"core-js": "^3.6.0",
"dompurify": "^2.5.4",
"html2canvas": "^1.0.0-rc.5"
}
},
"node_modules/jspdf-html2canvas": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/jspdf-html2canvas/-/jspdf-html2canvas-1.5.2.tgz",
"integrity": "sha512-jA/QvZWPiBJFR7Ut4XCwKsOcml1L75lvO7+mmw5qgTfmi8qbfHNr2DPXeQ8J6mNKJfB4Fn8QBBiYcr2NR3ssdQ==",
"license": "ISC",
"dependencies": {
"html2canvas": "^1.4.1",
"jspdf": "^2.5.1"
}
},
"node_modules/jspdf/node_modules/fflate": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz",
"integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==",
"license": "MIT"
},
"node_modules/jszmq": { "node_modules/jszmq": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/jszmq/-/jszmq-0.1.2.tgz", "resolved": "https://registry.npmjs.org/jszmq/-/jszmq-0.1.2.tgz",
@ -8995,6 +9140,13 @@
"integrity": "sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==", "integrity": "sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/performance-now": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==",
"license": "MIT",
"optional": true
},
"node_modules/picocolors": { "node_modules/picocolors": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
@ -9361,6 +9513,16 @@
], ],
"license": "MIT" "license": "MIT"
}, },
"node_modules/raf": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz",
"integrity": "sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==",
"license": "MIT",
"optional": true,
"dependencies": {
"performance-now": "^2.1.0"
}
},
"node_modules/react-is": { "node_modules/react-is": {
"version": "17.0.2", "version": "17.0.2",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
@ -9551,6 +9713,16 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/rgbcolor": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/rgbcolor/-/rgbcolor-1.0.1.tgz",
"integrity": "sha512-9aZLIrhRaD97sgVhtJOW6ckOEh6/GnvQtdVNfdZ6s67+3/XwLS9lBcQYzEEhYVeUowN7pRzMLsyGhK2i/xvWbw==",
"license": "MIT OR SEE LICENSE IN FEEL-FREE.md",
"optional": true,
"engines": {
"node": ">= 0.8.15"
}
},
"node_modules/rimraf": { "node_modules/rimraf": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
@ -10084,6 +10256,16 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/stackblur-canvas": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/stackblur-canvas/-/stackblur-canvas-2.7.0.tgz",
"integrity": "sha512-yf7OENo23AGJhBriGx0QivY5JP6Y1HbrrDI6WLt6C5auYZXlQrheoY8hD4ibekFKz1HOfE48Ww8kMWMnJD/zcQ==",
"license": "MIT",
"optional": true,
"engines": {
"node": ">=0.1.14"
}
},
"node_modules/string-length": { "node_modules/string-length": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz",
@ -10288,6 +10470,16 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/svg-pathdata": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/svg-pathdata/-/svg-pathdata-6.0.3.tgz",
"integrity": "sha512-qsjeeq5YjBZ5eMdFuUa4ZosMLxgr5RZ+F+Y1OrDhuOCEInRMA3x74XdBtggJcj9kOeInz0WE+LgCPDkZFlBYJw==",
"license": "MIT",
"optional": true,
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/svg-tags": { "node_modules/svg-tags": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/svg-tags/-/svg-tags-1.0.0.tgz", "resolved": "https://registry.npmjs.org/svg-tags/-/svg-tags-1.0.0.tgz",
@ -10330,6 +10522,15 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/text-segmentation": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
"integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
"license": "MIT",
"dependencies": {
"utrie": "^1.0.2"
}
},
"node_modules/text-table": { "node_modules/text-table": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
@ -11016,6 +11217,15 @@
"node": ">= 4" "node": ">= 4"
} }
}, },
"node_modules/utrie": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
"integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
"license": "MIT",
"dependencies": {
"base64-arraybuffer": "^1.0.2"
}
},
"node_modules/uuid": { "node_modules/uuid": {
"version": "9.0.1", "version": "9.0.1",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
@ -11338,6 +11548,13 @@
"vue": "^3.0.0" "vue": "^3.0.0"
} }
}, },
"node_modules/vue-printjs": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/vue-printjs/-/vue-printjs-1.0.0.tgz",
"integrity": "sha512-4WKTreQH6DuBY1chTcCzH//RpqEhVesGBB0XoK2cD8pXGInoPzcjWTtceI0VPNuPXAsiX/uIBqvNUX8MNNhY8Q==",
"dev": true,
"license": "ISC"
},
"node_modules/vue-router": { "node_modules/vue-router": {
"version": "4.5.0", "version": "4.5.0",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.5.0.tgz", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.5.0.tgz",

3
package.json

@ -35,6 +35,8 @@
"cropperjs": "^1.6.2", "cropperjs": "^1.6.2",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"dayjs": "^1.11.11", "dayjs": "^1.11.11",
"jspdf": "^2.5.2",
"jspdf-html2canvas": "^1.5.2",
"jszmq": "^0.1.2", "jszmq": "^0.1.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mitt": "^3.0.1", "mitt": "^3.0.1",
@ -82,6 +84,7 @@
"uuid": "^9.0.0", "uuid": "^9.0.0",
"vite": "^5.2.12", "vite": "^5.2.12",
"vite-plugin-purge-icons": "^0.10.0", "vite-plugin-purge-icons": "^0.10.0",
"vue-printjs": "^1.0.0",
"vue-tsc": "^2.0.19" "vue-tsc": "^2.0.19"
} }
} }

437
src/pages/deviceInfo/testPDF.vue

@ -0,0 +1,437 @@
<template>
<div>
<el-button @click="generateAndPrintPDF">打印</el-button>
<div id="printArea" class="report">
<h2 class="title">北京比塔技术服务有限公司</h2>
<h3 class="subtitle">出厂检验报告</h3>
<table class="table">
<tr>
<td>产品名称</td>
<td>边缘控制器</td>
<td>报告编号</td>
<td>20240311-M001</td>
</tr>
<tr>
<td>规格型号</td>
<td>BICON-CCU-M</td>
<td>日期</td>
<td>2024.3.11</td>
</tr>
<tr>
<td>本批检验数量</td>
<td>1</td>
<td>设备编号</td>
<td>CCU-M-01-2403-020026</td>
</tr>
</table>
<h4 class="result">检查结果</h4>
<table class="table result-table">
<thead>
<tr>
<th class="index">项次</th>
<th class="project">检验项目</th>
<th class="content">检验内容</th>
<th class="consequence">检验结果</th>
<th class="decide">判定</th>
<th class="remark">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>外观</td>
<td>表面光滑无划伤无明显凹凸不平无污渍腐蚀点及一致均匀无色差</td>
<td></td>
<td>合格</td>
<td></td>
</tr>
<tr>
<!-- rowspan="3" 动态生成 -->
<td rowspan="3">2</td>
<td rowspan="3">电气性能</td>
<td>尺寸与图纸要求一致</td>
<td>103*147*41mm</td>
<td>合格</td>
<td></td>
</tr>
<tr>
<td>通信测试电源电压正常指示灯指示</td>
<td></td>
<td>合格</td>
<td></td>
</tr>
<tr>
<td>通信测试电源电压正常指示灯指示</td>
<td></td>
<td>合格</td>
<td></td>
</tr>
</tbody>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<table class="table res-table">
<tr>
<td class="conclusion" rowspan="2">建议结论</td>
<td colspan="4">边缘控制器</td>
</tr>
<tr>
<td class="inspector">检验员</td>
<td class="value">xs</td>
<td class="data">检验日期</td>
<td class="value">2024.12.2</td>
</tr>
</table>
<div class="footer">
<span>电话: 010 - 82736682</span>
<span>地址: 北京市海淀区信息路28号上地信息大厦B座901</span>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import html2canvas from 'html2canvas'
import jsPDF from 'jspdf'
async function generateAndPrintPDF() {
const printArea = document.getElementById('printArea')
if (!printArea) {
console.error('打印区域未找到')
return
}
try {
// HTML Canvas
const canvas = await html2canvas(printArea, {
scale: window.devicePixelRatio * 2,
})
// Canvas
const canvasWidth = canvas.width
const canvasHeight = canvas.height
// Canvas
const imgData = canvas.toDataURL('image/jpeg', 1.0)
// jsPDF
const pdf = new jsPDF('p', 'mm', 'a4')
const pdfWidth = pdf.internal.pageSize.getWidth() // PDF
const pdfHeight = pdf.internal.pageSize.getHeight() // PDF
const headerHeight = 20 // Header
const footerHeight = 20 // Footer
const contentHeight = pdfHeight - headerHeight - footerHeight //
// PDF
const imgHeight = (canvasHeight * pdfWidth) / canvasWidth
// PDF
if (imgHeight <= contentHeight) {
pdf.text('Header Title', pdfWidth / 2, headerHeight / 2, { align: 'center' }) // Header
pdf.addImage(imgData, 'JPEG', 0, headerHeight, pdfWidth, imgHeight)
pdf.text('Footer Text', pdfWidth / 2, pdfHeight - footerHeight / 2, {
align: 'center',
}) // Footer
} else {
//
let position = 0 //
while (position < canvasHeight) {
const pageCanvas = document.createElement('canvas')
pageCanvas.width = canvasWidth
pageCanvas.height = (contentHeight * canvasWidth) / pdfWidth
const pageCtx = pageCanvas.getContext('2d')
pageCtx?.drawImage(
canvas,
0,
position, // Canvas
canvasWidth,
pageCanvas.height,
0,
0,
canvasWidth,
pageCanvas.height
)
const pageImgData = pageCanvas.toDataURL('image/jpeg', 1.0)
// Header
pdf.text(' ', pdfWidth / 2, headerHeight / 2, { align: 'center' })
// PDF
pdf.addImage(pageImgData, 'JPEG', 0, headerHeight, pdfWidth, contentHeight)
// Footer
pdf.text(' ', pdfWidth / 2, pdfHeight - footerHeight / 2, {
align: 'center',
})
position += pageCanvas.height //
//
if (position < canvasHeight) {
pdf.addPage()
}
}
}
// PDF
pdf.autoPrint()
window.open(pdf.output('bloburl'), '_blank')
} catch (error) {
console.error('生成 PDF 时出错:', error)
}
}
</script>
<style scoped lang="scss">
.report {
width: 940px;
margin: 0 auto;
padding: 40px 20px;
box-sizing: border-box;
background-color: #fff;
.title {
text-align: center;
font-size: 24px;
margin-bottom: 20px;
}
h1,
h2,
h3,
h4 {
margin: 0;
}
.subtitle {
font-size: 20px;
height: 60px;
line-height: 60px;
text-align: center;
border: 1px solid #000;
border-bottom: none;
}
.table {
width: 100%;
border-collapse: collapse;
thead,
tbody {
th,
td {
border: 1px solid #000;
padding: 12px 18px;
text-align: center;
box-sizing: border-box;
}
}
}
.result {
text-align: center;
border: 1px solid #000;
border-top: none;
border-bottom: none;
height: 50px;
line-height: 50px;
font-weight: bold;
}
.result-table {
width: 100%;
border-collapse: collapse;
thead,
tbody {
th,
td {
border: 1px solid #000;
padding: 12px 18px;
text-align: center;
box-sizing: border-box;
}
}
tr {
.index {
min-width: 40px;
}
.project {
min-width: 80px;
}
.content {
width: auto;
}
.consequence {
min-width: 40px;
}
.decide {
min-width: 40px;
}
.remark {
min-width: 120px;
}
}
}
.res-table {
width: 100%;
border-collapse: collapse;
thead,
tbody {
td {
border: 1px solid #000;
padding: 12px 18px;
text-align: center;
}
}
.conclusion {
width: 63px;
font-weight: bold;
}
.value {
width: 32%;
}
}
.footer {
width: 100%;
text-align: center;
margin-top: 20px;
font-size: 14px;
line-height: 1.5;
border-top: none;
span {
display: block;
}
:last-child {
margin-left: auto;
margin-right: auto;
}
}
}
</style>

48
src/router/index.ts

@ -48,30 +48,30 @@ export const defaultRoute = [
], ],
}, },
// { {
// path: '/device', path: '/test',
// component: () => import('@/pages/layout.vue'), component: () => import('@/pages/layout.vue'),
// name: 'UserInfo', name: 'Test',
// meta: { meta: {
// canTo: true, canTo: true,
// hidden: true, hidden: false,
// noTagsView: false, noTagsView: false,
// icon: 'ep:user', icon: 'ep:user',
// title: '系统管理', title: 'Test',
// }, },
// children: [ children: [
// { {
// path: 'deviceOperation', path: 'PDF',
// component: () => import('@/pages/deviceInfo/info.vue'), component: () => import('@/pages/deviceInfo/testPDF.vue'),
// name: 'deviceOperation', name: 'PDF',
// meta: { meta: {
// icon: 'ep:user', icon: 'ep:user',
// hidden: true, hidden: false,
// title: '设备xx', title: '测试PDF',
// }, },
// }, },
// ], ],
// }, },
// { // {
// path: '/user', // path: '/user',
// component: () => import('@/pages/layout.vue'), // component: () => import('@/pages/layout.vue'),

Loading…
Cancel
Save